【问题标题】:MasterCard payment gateway checkout.js method not triggering complete Callback function万事达支付网关 checkout.js 方法未触发完整的回调函数
【发布时间】:2020-12-27 12:58:16
【问题描述】:

我用的是万事达卡checkout.js方法57版。
checkout.js 下有两种类型

  1. showLightbox -> 显示灯箱完成付款。
  2. showPaymentPage -> 重定向到托管支付页面以完成支付。

当使用第一种方法时灯箱如果支付过程成功completeCallback()函数得到触发。这个 showlightbox 方法没有问题。

但是在支付过程之后使用showPaymentPage方法时,会重定向到启动的域但不会触发completeCallback()函数。

如果我取消付款流程,我会如何重定向到启动的域并触发 取消回调函数。

<script src="https://nbo.gateway.mastercard.com/checkout/version/57/checkout.js" data-error="errorCallback" 
data-cancel="cancelCallback" 
data-complete="completeCallback"></script>

Checkout.configure({
    merchant: pay_det['merchant'],
    order: {
        amount: function() {                        
            return pay_det['amount'];
        },
        currency: pay_det['currebcy'],
        description: 'Payments',
        id: invID,
        reference : $('#id_invoice').val()
    },
    session : {
        id : pay_det['session_id']
    },
    transaction :{
        reference : 'TR'+pay_det['invID']
    },
    interaction: {                        
        operation : 'PURCHASE',                    
        displayControl: {
            billingAddress : 'HIDE',
            customerEmail  : 'HIDE',
            orderSummary   : 'SHOW',
            shipping       : 'HIDE'
        },
        merchant: {
            name: pay_det['amount'],
            address: {
                line1: pay_det['companyPrintAddress'],
            },                            
        }
    },                                
});

Checkout.showPaymentPage();

function cancelCallback() {
    alert('cancelled');
}

function completeCallback(resultIndicator, sessionVersion) {
    //var invoiceID = $('#id_invoice').val();
    alert('success');
    console.log(resultIndicator);
}

如果我将 data-complete 属性值更改为不从支付网关重定向到我的域的 url,还有一件事。 表格

data-complete="completeCallback"

data-complete="https://subscription-int.com/567"

当提到 complete Callback 函数参考时,文档说

仅在 Return To Merchant 集成中支持完整回调。

什么是返回商家集成

【问题讨论】:

标签: javascript payment-gateway mastercard


【解决方案1】:

您需要在 Create Checkout SessionNOT IN Configure 操作中提供interaction.returnUrl

另一种方法是在引用checkout.js 脚本时,您可以定义complete 回调。提及您的returnUrl 作为回调值(而不是函数),用户将在付款完成后被重定向到此 URL。

您将在重定向时将resultIndicator 附加到您的returnUrl。将此与您在Create Checkout Session 响应期间收到的successIndicator 值进行比较。

MPGS Hosted Checkout Documentation

【讨论】:

【解决方案2】:

你可以像这样使用取消和完成回调。

<script src="https://nbo.gateway.mastercard.com/checkout/version/57/checkout.js" data-cancel="https://website.com/payment-rejected.php" data-complete="https://website.com/payment-success.php"> </script>

参考这个:

https://nbo.gateway.mastercard.com/api/documentation/integrationGuidelines/hostedCheckout/integrationModelHostedCheckout.html

【讨论】:

    【解决方案3】:

    我在我的 wordpress 小部件中使用了下面的代码 sn-p,只需确保在交互参数中添加 returnUrl。

    $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 .'",
        
        },
        "order": {
            "currency": "NGN",
             "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);
    

    【讨论】:

      猜你喜欢
      • 2019-08-21
      • 2021-09-03
      • 2016-02-16
      • 2017-12-21
      • 1970-01-01
      • 2021-06-13
      • 2012-06-05
      • 2017-02-22
      • 2018-03-17
      相关资源
      最近更新 更多