javascript 万事达卡支付网关服务(MPGS)与托管结账交互页面(Checkout.js)的问题

cld4siwp  于 2023-01-19  发布在  Java
关注(0)|答案(2)|浏览(601)

我是新的万事达卡支付网关服务(MPGS)集成和面临的问题与第二步互动的万事达卡安全支付页面。
第一步:我使用apiOperation生成了一个会话ID,如“CREATE_CHECKOUT_SESSION”,使用Postman和POST方法,主体是raw =〉Json,如下所示:

URL: https://test-gateway.mastercard.com/api/rest/version/57/merchant/1033/session

Body:
 { 
  "apiOperation": "CREATE_CHECKOUT_SESSION", 
  "interaction": {
      "operation": "PURCHASE"
  },
  "order": {
      "currency": "USD",
       "id": "22541" ,
      "amount": 50
    } 
}

通过在Authorization部分提供我的API凭据,成功生成了会话ID。现在,当我调用checkout.js文件与托管的结帐支付页面交互时,控件移动到支付网关页面,但显示错误

Refused to execute script from 'https://test-gateway.mastercard.com/form/version//merchant/1033/session.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Error Message

<script type="application/javascript" src="https://test-gateway.mastercard.com/checkout/version/57/checkout.js" data-error="errorCallback" data-cancel="cancelCallback" data-complete="completeCallback"  >
            </script>
            
        <script type="application/javascript">
            function errorCallback(error) {
                  console.log(JSON.stringify(error));
            }
            function cancelCallback() {
                  console.log('Payment cancelled');
            }
            function completeCallback(resultIndicator, sessionVersion) {
    
            alert('success');
    console.log(resultIndicator);
}
            
            Checkout.configure({
                merchant: '1033',
                order: {
                    amount: function() {
                        return 50;
                    },
                    currency: 'USD',
                    description: 'Ordered goods',
                    id: '22541'
                },
                interaction: {
                    operation: 'PURCHASE',
                    merchant: {
                        name: 'MOFA -TEST',
                        address: {
                            line1: '200 Sample St',
                            line2: '1234 Example Town'     
                        }    
                    }
                },
                session: {
                      id: 'SESSION0002089703583J7873949J89'
                }
                
            });
            
            Checkout.showPaymentPage();
            
        </script>

任何帮助都将不胜感激。谢谢

svdrlsy4

svdrlsy41#

万事达卡支付网关文档在描述请求的参数时并不清楚。我发现这个视频对使用PHP curl和JavaScript的万事达卡托管结账集成很有帮助:
下面是请求sessionId的代码片段:

$id = sanitize_text_field( $req['id'] );
    $amount  = sanitize_text_field( $req['amount'] );
    $merchantId = sanitize_text_field( $req['merchantId'] );
    $password = sanitize_text_field( $req['password'] );
    $redirectUrl = sanitize_text_field( $req['redirectUrl'] );

    $post_data = '{ 
        "apiOperation": "CREATE_CHECKOUT_SESSION", 
        "interaction": {
            "operation": "PURCHASE",
            "returnUrl": "' . $redirectUrl .'",
            "cancelUrl": "' . $redirectUrl . '",
        },
        "order": {
            "currency": "USD",
             "id": "' . $id . '",
            "amount": "' . $amount . '"
          } 
      }';

    $url = "https://fbn.gateway.mastercard.com/api/rest/version/61/merchant/" . $merchantId . "/session";
    
    $auth = 'merchant.'. $merchantId . ':' . $password;
    $credentials = base64_encode($auth);
    $authorization = 'Authorization: Basic ' . $credentials;

    // Prepare new cURL resource
    $crl = curl_init($url);
    curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($crl, CURLINFO_HEADER_OUT, true);
    curl_setopt($crl, CURLOPT_POST, true);
    curl_setopt($crl, CURLOPT_POSTFIELDS, $post_data);
     
    // Set HTTP Header for POST request 
    curl_setopt($crl, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Authorization: Basic ' . $credentials)
    );
     
    // Submit the POST request
    $result = curl_exec($crl);
     
    // handle curl error
    if ($result === false) {
        // throw new Exception('Curl error: ' . curl_error($crl));
        //print_r('Curl error: ' . curl_error($crl));
        $result_noti = 0; die();
    } else {
        return rest_ensure_response( $result );
    }
    // Close cURL session handle
    curl_close($crl);

https://www.youtube.com/watch?v=jRJkfszfla0

pgvzfuti

pgvzfuti2#

MPGS托管 checkout 集成已从API版本63及更高版本更新。但是,如果您仍在使用API版本57(最低3DS2.0支持的API版本),请查找以下示例代码。MPGS checkout.js HTML引用MPGS sample code version wise reference
检查站

  • HTML页面中的API版本与CREATE_CHECKOUT_SESSION API相同(对于版本〉= 63,无需在HTML页面中提供版本号)
  • 会话ID正确
  • 订单ID对于每个交易都是唯一的
<html>
    <head>
        <script src="https://test-gateway.mastercard.com/checkout/version/57/checkout.js"
                data-error="errorCallback"
                data-cancel="cancelCallback">
        </script>
    
        <script type="text/javascript">
            function errorCallback(error) {
                  console.log(JSON.stringify(error));
            }
            function cancelCallback() {
                  console.log('Payment cancelled');
            }
        
            Checkout.configure({
                session: {
                    id:  'SESSION0002892865938N27989233E3'
                 },
                order: {
                    description: 'Ordered goods',
                    id: 'bqtrb-xryt'
                },
                interaction: {
                    merchant: {
                        name: 'Merchant name',
                        address: {
                            line1: '200 Sample St',
                            line2: '1234 Example Town'
                        }
                    }
                }
            });
            
        </script>
    </head>
    <body>
    
        <div id="embed-target"> </div>
        <input type="button" value="Pay with Lightbox" onclick="Checkout.showLightbox();" />
        <input type="button" value="Pay with Payment Page" onclick="Checkout.showPaymentPage();" />
    
    </body>
</html>

相关问题