Convert PHP code to Xojo Web?

I am working on a project that need to connect to a payment service, the example code for this payment service company is written in PHP, I have been studying this php code for hours but still can not figure out how to rewrite this in Xojo, please can any one give me a direction what control should I use to complete this?

[code]<?php
//???
function replaceChar($value)
{
$search_list = array(’%2d’, ‘%5f’, ‘%2e’, ‘%21’, ‘%2a’, ‘%28’, ‘%29’);
$replace_list = array(’-’, '
’, ‘.’, ‘!’, ‘*’, ‘(’, ‘)’);
$value = str_replace($search_list, $replace_list ,$value);

	return $value;
}
//?????
function _getMacValue($hash_key, $hash_iv, $form_array)
{
	$encode_str = "HashKey=" . $hash_key;
	foreach ($form_array as $key => $value)
	{
		$encode_str .= "&" . $key . "=" . $value;
	}
	$encode_str .= "&HashIV=" . $hash_iv;
	$encode_str = strtolower(urlencode($encode_str));
	$encode_str = _replaceChar($encode_str);

	return md5($encode_str);
}

//------------------------------------------???------------------------------------------------------
//???
$trade_no = “StageTest”.time();
//???
$total_amt = “100”;
//???
$trade_desc = “???(??)”;
//???(#)
$item_name = “???(??)”;
//???
$return_url = “http://www.allpay.com.tw/receive.php”;
//???
$client_back_url = “http://www.allpay.com.tw/receive.php”;
//???
$choose_payment = “ALL”;
//???
$needExtraPaidInfo = “Y”;
//Alipay ???
$alipay_item_name = $item_name;
$alipay_item_counts = 1;
$alipay_item_price = $total_amt;
$alipay_email = ‘stage_test@allpay.com.tw’;
$alipay_phone_no = ‘0911222333’;
$alipay_user_name = ‘Stage Test’;
/???(???,???)*******/
//???(???)
$gateway_url = “http://payment-stage.allpay.com.tw/Cashier/AioCheckOut”;
//???
$merchant_id = “2000132”;
//HashKey
$hash_key = “5294y06JbISpM5x9”;
//HashIV
$hash_iv = “v77hoKGq4kWxNNIS”;
/********************************************************************************************/

$form_array = array(
“MerchantID” => $merchant_id,
“MerchantTradeNo” => $trade_no,
“MerchantTradeDate” => date(“Y/m/d H:i:s”),
“PaymentType” => “aio”,
“TotalAmount” => $total_amt,
“TradeDesc” => $trade_desc,
“ItemName” => $item_name,
“ReturnURL” => $return_url,
“ChoosePayment” => $choose_payment,
“ClientBackURL” => $client_back_url,
“NeedExtraPaidInfo” => $needExtraPaidInfo,
# Alipay ???
“AlipayItemName” => $alipay_item_name,
“AlipayItemCounts” => $alipay_item_counts,
“AlipayItemPrice” => $alipay_item_price,
“Email” => $alipay_email,
“PhoneNo” => $alipay_phone_no,
“UserName” => $alipay_user_name
);

 # ??ksort????--??????(??????)
 ksort($form_array, SORT_NATURAL |SORT_FLAG_CASE);
 # ?? Mac Value
$form_array['CheckMacValue'] = _getMacValue($hash_key, $hash_iv, $form_array);

$html_code = ‘’;
foreach ($form_array as $key => $val) {
$html_code .= “
”;
}
$html_code .= “”;
$html_code .= “”;
echo $html_code;
?>[/code]

Hello,

I’m not sure I can convert all of the code for you. But in regards to the functions, check out this to help with _replaceChar()
http://documentation.xojo.com/index.php/ReplaceAll

And then these two functions to help replace _getMacValue():
http://documentation.xojo.com/index.php/Lowercase
http://documentation.xojo.com/index.php/MD5

I hope this helps.

[quote=191893:@Tunghua TAi]I am working on a project that need to connect to a payment service, the example code for this payment service company is written in PHP, I have been studying this php code for hours but still can not figure out how to rewrite this in Xojo, please can any one give me a direction what control should I use to complete this?
[/quote]

Apparently, this code is meant to create a payment page. I simply copied it into an HTML page, right after the tag, named it allpay.php and placed it on a site with Chmod 755. It creates a small payment page.

You could use that as a template to generate a page that you then display in an HTMLViewer.

Otherwise, all it does is to post the content of the form to http://payment-stage.allpay.com.tw/Cashier/AioCheckOut

You could replace the tiny php form by a Xojo program, then post the data to the same URL with httpsocket. See http://documentation.xojo.com/index.php/HTTPSocket.Post
You just need to use the name of the fields as values in the example, such as with a few of them :

[code]Dim d As New Dictionary

d.Value(“AlipayItemName”) = “TestValue”
d.Value(“alipay_item_name”) = “Widget”
d.Value(“AlipayItemCounts”) = “1”
d.Value(“AlipayItemPrice”) = “123”

Socket.SetFormData(d)

// This service simply returns the post data as the result
Dim result As String
result = Socket.Post(“http://httpbin.org/post”, 30) // Synchronous

result = DefineEncoding(result, Encodings.UTF8)

MsgBox(result)[/code]

That is just a beginning…

Follow-up. I tried to click on the sample php form, the response is “CheckMacValue Error.”. So apparently there is something missing in the original code. Before trying to translate, you want to make sure it works.

@Kevin Cully , @Michel Bujardet , Thanks for your help, I will keep trying today with your method.