MPGS(万事达卡网关)返回错误,但在 woocommerce 或 opencart 中使用插件时有效
我正在尝试在 php 中实现 MPGS 支付网关。我使用的详细信息与在 woocommerce woo mpgs< 中使用第 3 方插件时使用和工作的详细信息相同/a> 并在打开购物车中使用 mpgs gateway
但我尝试这样做与 core php 相同,遵循官方万事达卡集成指南,并且还转换了上述插件的源代码,但在 LIVE 和 TEST 模式下都给出了与下面相同的错误
这是我正在使用的代码:
<?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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MPGS API 版本 57 或更高版本支持 3DS2.0 身份验证。升级57以上版本。
如果您使用的是 API 版本 63 或更高版本,您将需要更改托管结账集成。
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.
感谢您提供的所有其他答案和意见。但我在 MPGS 支持团队通过我们银行的帮助下解决了这个问题。基本上,我们做了 3 件事来帮助我们实现这一目标:
将 API 版本更新为 63(实施时的最新版本)
包含以下 2 个必填字段:
Order.Reference
和Transaction.Reference
(两者都必须是唯一的)每个订单)在CREATE CHECKOUT SESSION
操作中(docs 尽管当时没有将它们标记为强制)使用支持 3Dsecure 的卡进行测试/沙箱:

希望这有帮助!
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!