0

i try to integration Hosted Checkout of mastercard by PHP

my code

<?php
$orderid = "45";
$merchant = "xxxxx_xxx";
$apipassword = "xxxxxxxxxxxxx";
$amount = "1.00";
$returnUrl = "http://www.google.com";
$currency = "USD";


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "ttps://banquemisr.gateway.mastercard.com/api/nvp/version/61");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "
apiOperation=CREATE_CHECKOUT_SESSION &
apiPassword=$apipassword  &
apiUsername=$merchant  &
merchant=$merchant  &
interaction.operation=PURCHASE  &
order.id=$orderid  &
order.amount=$amount  &
order.currency=$currency
");


$headers = array();
$headers[] = 'content-type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);

curl_close($ch);
print_r(explode("&", $result));

?>

It does not show any errors But there is no data

result:

Array ( [0] => ) 

What is wrong with this code?

Omar Dealo
  • 11
  • 2
  • Looks like you're not getting a result. You'll want to check the headers to see if you're getting a good response or not. (See [here](https://stackoverflow.com/questions/9183178/can-php-curl-retrieve-response-headers-and-body-in-a-single-request) for info on how to get that). I'm guessing that your post field string is not properly built. Try creating an array then use [http_build_query](https://www.php.net/manual/en/function.http-build-query.php) to make sure it's done properly. – aynber Mar 04 '22 at 19:16

0 Answers0