Page 1 of 1

PHP HTTP Request to LiveCode

Posted: Sun Apr 01, 2018 9:17 am
by ebenezereshun
Can someone help me convert this PHP http post request to Livecode either with or without cURL. I am new to Livecode and I have tried couple of things but not working.

Code: Select all

$receive_momo_request = array(
         'CustomerName' => 'Customer Name',
	  'CustomerMsisdn'=> '054XXXX',
	  'CustomerEmail'=> 'customer Email',
	  'Channel'=> 'mtn-gh',
	  'Amount'=> 0.8,
	  'PrimaryCallbackUrl'=> 'Primary Call back Url ',
	  'Description'=> 'T Shirt',
);

//API Keys

$clientId = 'xxxxxxx';
$clientSecret = 'xxxxxxx';
$basic_auth_key =  'Basic ' . base64_encode($clientId . ':' . $clientSecret);
$request_url = 'Server Post URL';
$receive_momo_request = json_encode($receive_momo_request);

$ch =  curl_init($request_url);  
		curl_setopt( $ch, CURLOPT_POST, true );  
		curl_setopt( $ch, CURLOPT_POSTFIELDS, $receive_momo_request);  
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );  
		curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
		    'Authorization: '.$basic_auth_key,
		    'Cache-Control: no-cache',
		    'Content-Type: application/json',
		  ));

$result = curl_exec($ch); 
$err = curl_error($ch);
curl_close($ch);

if($err){
	echo $err;
}else{
	echo $result;
}
This is what I have done so far. Thanks in advance for your support.

Code: Select all


on mouseUp
   global gFirstName, gLastName
   put gFirstName & " " & gLastName into lFullName
   put lFullName into tArray[ "CustomerName"]
   put "gPhoneNumber" into tArray["CustomerMsisdn"]
   put "gEmail"  into tArray["CustomerEmail"]
   put "airtel-gh" into tArray["Channel"]
   put "0.01" into tArray["Amount"]
   put "Primary Call back Url" into tArray["PrimaryCallbackUrl"]
   put "FBMC Mobile" into tArray["Description"]
   put true into tArray ["FeesOnCustomer"]

   put ArrayToJSON(tArray) into receive_momo_request

   put "ABCD" into clientId
   put "1234" into clientSecret
   set the httpHeaders to "Content-type: application/json" && "Authorization: Basic " && base64Encode("clientId:clientSecret") && "Cache-Control: no-cache"
   post receive_momo_request to url "https://Server Post UR/v1/merchantaccount/merchants/HMXXXXXXX/receive/mobilemoney"

end mouseUp

Re: PHP HTTP Request to LiveCode

Posted: Sun Apr 01, 2018 1:53 pm
by FourthWorld
What does the data look like in LiveCode?

Re: PHP HTTP Request to LiveCode

Posted: Mon Apr 02, 2018 3:30 am
by ebenezereshun
FourthWorld wrote:
Sun Apr 01, 2018 1:53 pm
What does the data look like in LiveCode?
See what I have done so far in the updated code