PHP HTTP Request to LiveCode

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller

Post Reply
ebenezereshun
Posts: 3
Joined: Sun Apr 01, 2018 8:51 am

PHP HTTP Request to LiveCode

Post by ebenezereshun » Sun Apr 01, 2018 9:17 am

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
Last edited by ebenezereshun on Mon Apr 02, 2018 12:25 am, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5814
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: PHP HTTP Request to LiveCode

Post by FourthWorld » Sun Apr 01, 2018 1:53 pm

What does the data look like in LiveCode?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

ebenezereshun
Posts: 3
Joined: Sun Apr 01, 2018 8:51 am

Re: PHP HTTP Request to LiveCode

Post by ebenezereshun » Mon Apr 02, 2018 3:30 am

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

Post Reply

Return to “Converting to LiveCode”