万事达卡托管结帐集成问题

时间:2019-03-05 16:12:46

标签: payment-gateway mastercard

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

                      

    <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>

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

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

我正确使用了商人ID,可能是我错过了一些东西。我有用户名和密码,不确定在哪里添加这些参数。请帮助我

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

3 个答案:

答案 0 :(得分:1)

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

创建会话变量

$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>,
            ];

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

/**
     * @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());
            }
        }*/
    }

答案 1 :(得分:0)

有两种情况 1.收到商户ID时。他们应该共享一个文档链接,以供参考。通常,checkout.js文件路径错误。 2.您必须在进行API调用时进行基本的用户身份验证,并传递用户名和密码。您可以从管理面板生成密码

答案 2 :(得分:0)

static public function initPaymentSession($amount,$orderID,$description,$currency = 'EGP')
{
    // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://banquemisr.gateway.mastercard.com/api/nvp/version/60');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "apiOperation=CREATE_CHECKOUT_SESSION&apiPassword=xxxxxxxxxxxxxxx&apiUsername=merchant.xxxxxxxxx&merchant=xxxxxxxxx&interaction.operation=PURCHASE&order.id=$orderID&order.amount=$amount&order.currency=EGP");

    $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 'Error:' . curl_error($ch);
    }
    if (curl_errno($ch)) {
        return 'Error:' . curl_error($ch);
    }
    curl_close($ch);

    if ($result){
        $res1 = explode('&session.id=', $result);
        $res2 = explode('&', $res1[1]);
        return $res2[0];
    }

}