I am trying to implement MPGS payment gateway in php. The details I am using are same that are used and are working when using 3rd party plugin in woocommerce woo mpgs and in open cart using mpgs gateway
But I tried doing the same with core php following the official mastercard integration guide and also converted the source codes from the above plugins, but both give the same error as below in both LIVE and TEST mode
Here is the code I am using:
<?php
$orderid='223';
$merchant ='TestMYID';
$apipassword = 'xxx2b27cf8e45fffc6532f50xxxxxxxx';
$returnUrl = 'http://localhost/mpgs.php';
$currency = 'KWD';
$amount = 1;
$ch =curl_init();
curl_setopt($ch, CURLOPT_URL,'https://ap-gateway.mastercard.com/api/nvp/version/55');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "apiOperation=CREATE_CHECKOUT_SESSION&apiPassword=$apipassword&apiUsername=merchant.$merchant&merchant=$merchant&interaction.operation=PURCHASE&interaction.returnUrl=$returnUrl&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);
if(curl_errno($ch)){
echo curl_error($ch);
}
curl_close($ch);
$a = explode('&', $result);
foreach ($a as $result) {
$b = explode('=', $result);
$array[$b[0]] = $b[1];
}
$sessionid = ($array['session.id']);
//exit;
?>
<script src="https://ap-gateway.mastercard.com/checkout/version/55/checkout.js"
data-error="errorCallback"
data-cancel="http://localhost/mpgs.php">
</script>
<script>
function errorCallback(error)
{
alert("Error: "+JSON.stringify(error));
}
Checkout.configure({
merchant: '<?=$merchant?>',
order:{
amount:function(){
return <?=$amount?>;
},
currency:'<?=$currency?>',
description:'Order Goods',
id:'<?=$orderid?>'
},
interaction:{
merchant:{
name:'Anesthesia Lenses',
address:{
line1:'Kuwait',
line2:'Kuwait'
}
}
},
session:{
id:'<?=$sessionid?>'
}
});
Checkout.showPaymentPage();
//Checkout.showLightbox()
</script>
I have also tried the following:
- Running it on live domain to rule out any domain based blocking condition
- Ran with test and live credentials for same error
- Tried multiple test cards from official guide and other sources
- Tried with asia-pacific and europe endpoints
This is ran for a website with bank account located in Kuwait if that helps to for the url being wrong or something.
2
Answers
Thank you for all other answers and inputs. But I solved this with help from MPGS support team through our bank. Basically we did 3 things that helped us with this:
Updated API version to 63 (latest at time of implementation)
Included the following 2 fields which are mandatory
Order.Reference
andTransaction.Reference
(Both must be unique for each order) in theCREATE CHECKOUT SESSION
operation (The docs although at that time did not tag them as mandatory)Used 3Dsecure enabled cards for testing/sandbox:
Hope this helps!
3DS2.0 authentication is supported in MPGS API version 57 or above. Upgrade the version 57 or above.
If you are using API version 63 or above you will be required to change the Hosted Checkout Integration.