1

I am new to Livecode and I have tried couple of things to convert this php http post request code to Livecode but not working. Will need it either with cURL or without cURL.

    $receive_momo_request = array(
         'CustomerName' => 'Customer Name',
      'CustomerMsisdn'=> '054XXXX',
      'CustomerEmail'=> 'customer@gmail.com',
      'Channel'=> 'mtn-gh',
      'Amount'=> 0.8,
      'PrimaryCallbackUrl'=> 'http://requestb.in/1minotz1',
      'Description'=> 'T Shirt',

);

//API Keys

$clientId = 'xxxxxxx';
$clientSecret = 'xxxxxxx';
$basic_auth_key =  'Basic ' . base64_encode($clientId . ':' . $clientSecret);
$request_url = 'https://api.hubtel.com/v1/merchantaccount/merchants/HMXXXXXXX/receive/mobilemoney';
$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 may be am missing something.

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 "http://requestb.in/1minotz1" 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://api.hubtel.com/v1/merchantaccount/merchants/HMXXXXXXX/receive/mobilemoney"

end mouseUp

1 Answers1

0

Your LiveCode code looks good on first glance. I would try two things:

First, URLencode the data you are posting before you post it.

put ArrayToJSON(tArray) into receive_momo_request
put urlEncode(receive_momo_request) into receive_momo_request

Second, after the post command, check the itvariable to see what data was returned by the web server. You can also check the result to see if an error occurred.

post receive_momo_request to url "https://api.hubtel.com/v1/merchantaccount/merchants/HMXXXXXXX/receive/mobilemoney"
put it into tServerFeedback
answer the result

This should at least tell you what is happening after you issue the post command.

Devin
  • 593
  • 1
  • 3
  • 8
  • The responds from the server : `{"ResponseCode":"4101","Message":"Permission denied"}` `put "Accept: application/json" &&"Authorization: Basic" && base64Encode("clientId:clientSecret") && "Cache-Control: no-cache" &&"Content-type: application/json" into tHeader set the httpHeaders to tHeader` I believe the issue might by the header but not sure what is wrong but the authentication keys are all correct not sure why the server is denying access. – Ebenezer Eshun Apr 04 '18 at 00:53