万事达卡托管结账集成问题 [英] MasterCard hosted checkout integration issue

查看:60
本文介绍了万事达卡托管结账集成问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是支付集成方面的新手.我需要在我的 php 页面中集成万事达卡支付网关服务.我有一个 PAY 按钮,点击后,我重定向到以下页面.我有以下代码:

I am newbie on payment integration. I need to integrate MasterCard payment gateway services in my php page. I have a button for PAY and once clicked,I redirect to the following page. I have following code:

    <script type="text/javascript">
        function errorCallback(error) {
              console.log(JSON.stringify(error));
        }
        function cancelCallback() {
              console.log('Payment cancelled');
        }

        Checkout.configure({
            merchant: 'test001000000052',
            order: {
                amount: 100,
                currency: 'AED',
                description: 'Ordered goods',
               id: '123'
            },
            interaction: {
                merchant: {
                    name: 'test',
                    address: {
                        line1: '200 Sample St',
                        line2: '1234 Example Town'            
                    },
                 cancelUrl:'10.0.1.100/?load=parents/online_payment'    
                }
              }
        });
    </script>
</head>
<body> 
    <input type="button" value="Pay with Lightbox" onclick="Checkout.showLightbox();" />
    <input type="button" value="Pay with Payment Page" onclick="Checkout.showPaymentPage();" /> 
</body>

当我单击任一按钮时,我在控制台中收到以下错误消息.

When I click either buttons, I am getting the following error message in console.

XHR failed loading: POST "https://eu-gateway.mastercard.com/api/page/version/51/pay". 
{"cause":"INVALID_REQUEST","explanation":"Invalid credentials."}

我已经正确使用了商家 ID,可能我遗漏了什么.我有用户名和密码,但不确定在哪里添加这些参数.请帮帮我

I have used the merchantID correctly,may be I missed something. I have username and password with me and not sure where to add these parameters. Please help me

我从 https 获取了代码://eu-gateway.mastercard.com/api/documentation/integrationGuidelines/hostedCheckout/integrationModelHostedCheckout.html?locale=en_US

推荐答案

您应该创建一个会话,然后打开结帐页面或灯箱

You Should create a session then open the checkout page or lightbox

创建会话变量

$session_request = [
                'apiOperation' => "CREATE_CHECKOUT_SESSION",
                'interaction'  => [
                    'operation' => "PURCHASE",
                    'returnUrl' => "<return url>",
                ],
                'order'        => [
                    'amount'      => <amount>,
                    'currency'    => '<Currency Code like USD>',
                    'description' => 'Full Payment',
                    'id'          => <transaction reference>,
                ],
                'userId'       => <customer ID>,
            ];

调用以下函数将会话数据发送到万事达卡服务器

Call the following function for sending the session data to Mastercard server

/**
     * @param        $inputs
     * @param        $link
     * @param        $username
     * @param        $password
     * @param string $type
     *
     * @return \Exception|\GuzzleHttp\Exception\ClientException|\GuzzleHttp\Exception\RequestException|mixed|string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function postJsonRequestWithToken( $inputs, $link, $username, $password, $type = "assoc" ) {
        try {
            $client     = new Client();
            $response   = $client->post( $link, [
                'body' => json_encode( $inputs ),
                'auth' => [
                    $username,
                    $password,
                ],
            ] );
            $statusCode = $response->getStatusCode();
            $body       = $response->getBody()->getContents();
            if ( $type == 'json' ) {
                return $body;
            }
            if ( $type == 'object' ) {
                return json_decode( $body );
            }
            if ( $type == 'assoc' ) {
                return json_decode( $body, true );
            }
            
            return json_decode( $body );
        } catch( ClientException $e ) {
            //return json_decode( $e->getResponse()->getBody(), true );
            return $e;
        } catch( RequestException $e ) {
            //return json_decode( $e->getResponse()->getBody(), true );
            return $e;
        }
        /*} catch( RequestException $e ) {
            echo Psr7\str($e->getRequest());
            if ($e->hasResponse()) {
                echo Psr7\str($e->getResponse());
            }
        }*/
    }

这篇关于万事达卡托管结账集成问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆