MPGS(万事达卡网关)返回错误,但在 woocommerce 或 opencart 中使用插件时有效

发布于 2025-01-15 21:44:21 字数 2738 浏览 3 评论 0原文

我正在尝试在 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>

我还尝试了以下操作:

  1. 在实时域上运行它以排除任何基于域的阻止条件
  2. 使用测试和实时凭据来解决相同的错误
  3. 尝试了官方指南中的多个测试卡和其他来源
  4. 尝试过亚太和欧洲端点

这是为银行帐户位于科威特的网站运行的,如果这有助于解决网址错误或其他问题。

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

enter image description here

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:

  1. Running it on live domain to rule out any domain based blocking condition
  2. Ran with test and live credentials for same error
  3. Tried multiple test cards from official guide and other sources
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凝望流年 2025-01-22 21:44:21

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.

嘿哥们儿 2025-01-22 21:44:21

感谢您提供的所有其他答案和意见。但我在 MPGS 支持团队通过我们银行的帮助下解决了这个问题。基本上,我们做了 3 件事来帮助我们实现这一目标:

  1. 将 API 版本更新为 63(实施时的最新版本)

  2. 包含以下 2 个必填字段:Order.ReferenceTransaction.Reference(两者都必须是唯一的)每个订单)在CREATE CHECKOUT SESSION操作中(docs 尽管当时没有将它们标记为强制)

  3. 使用支持 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:

  1. Updated API version to 63 (latest at time of implementation)

  2. Included the following 2 fields which are mandatory Order.Reference and Transaction.Reference (Both must be unique for each order) in the CREATE CHECKOUT SESSION operation (The docs although at that time did not tag them as mandatory)

  3. Used 3Dsecure enabled cards for testing/sandbox:
    enter image description here

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文