【问题标题】:How to call ProcessPayment function in Google Pay react button?如何在 Google Pay 反应按钮中调用 ProcessPayment 功能?
【发布时间】:2021-04-19 04:29:40
【问题描述】:

我正在将 google pay 集成到 react 应用程序中。根据文档,生成令牌时,它将被传递到网关以进行支付。我正在使用@google-pay/button-react。如何将令牌传递给网关。我在文档中没有找到任何东西。这个库是自己向网关发送令牌的吗?

从谷歌教程发送令牌到网关

 processPayment(paymentDetail) {
  const paymentToken = paymentDetail.paymentMethodData.tokenizationData.token;
  let paymentData = {
    orderId : '12331231232311',
    amount : '50.00'
  }
  axios.post("https://esqa.moneris.com/googlepay/googlepay-api.js", {
    body: JSON.stringify({
      paymentToken,
      paymentData
    })
  }).then(response => {
    if ( response && response.receipt && response.receipt.ResponseCode &&
    !isNaN(response.receipt.ResponseCode) )
    {
    if ( parseInt(response.receipt.ResponseCode) < 50 )
    {
    alert("Looks like the transaction is approved.");
    }
    else
    {
    alert("Looks like the transaction is declined.");
    }
    }
    else
    {
    throw ("Error processing receipt.");
    }
  })
  
}

<GooglePayButton
                environment="TEST"
                paymentRequest={{
                    apiVersion: 2,
                    apiVersionMinor: 0,
                    allowedPaymentMethods: [
                    {
                        type: 'CARD',
                        parameters: {
                        allowedAuthMethods: ['PAN_ONLY'],
                        allowedCardNetworks: ['MASTERCARD', 'VISA', 'DISCOVER', 'AMEX','DISCOVER','JCB','INTERAC'],
                        },
                        tokenizationSpecification: {
                        type: 'PAYMENT_GATEWAY',
                        parameters: {
                            gateway: "moneris",
                            gatewayMerchantId: "monca05217"
                        },
                        },
                    },
                    ],
                    merchantInfo: {
                    merchantId: '12345678901234567890',
                    merchantName: 'Demo Merchant',
                    },
                    transactionInfo: {
                    totalPriceStatus: 'FINAL',
                    totalPriceLabel: 'Total',
                    totalPrice: '50.00',
                    currencyCode: 'USD',
                    countryCode: 'CA',
                    },
                    callbackIntents: ['PAYMENT_AUTHORIZATION'],
                    emailRequired: true,
                }}
                onLoadPaymentData={paymentRequest => {
                    console.log('load payment data', paymentRequest);
                    this.processPayment(paymentRequest)

                }} 
                onPaymentAuthorized={(paymentData) => ({ 
                    transactionState: 'SUCCESS'                                       
                  })} 
                onReadyToPayChange={result => {
                  console.log('ready to pay change', result);
                  this.setState({isReadyToPay : result.isReadyToPay});
                }}                                     
                onCancel={() => alert('Cancelled')}
                existingPaymentMethodRequired = {true}                                  
                />

【问题讨论】:

    标签: reactjs google-pay


    【解决方案1】:

    您需要从onLoadPaymentData 调用您的processPayment 方法。

    您的processPayment 负责调用您的后端并将支付令牌传递到您的支付网关。

    例子:

    onLoadPaymentData={paymentRequest => {
      processPayment();
    }}
    
    async function processPayment(paymentData) {
      const paymentToken = paymentData.paymentMethodData.tokenizationData.token;
      const response = await fetch("/backend/api", {
        method: "POST",
        body: JSON.stringify({
          paymentToken,
          orderDetails: {/* details about your order */}
        })
      });
    }
    

    【讨论】:

    • 我收到此错误“从源 'esqa.moneris.com/googlepay/googlepay-api.js' 访问 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否请求的资源上存在“Access-Control-Allow-Origin”标头。”再次查看代码我修改了它
    • 您似乎正试图从前端调用您的 PSP。你不应该。流程应该类似于 Browser > 您的后端服务器 > 您的 PSP
    • 我使用了 Nodejs 并将响应作为一个函数。 “MonerisGooglePay() { this.error = false; this.session = null; this.channel = null; this.container = null; this.validateCallback = null; this.receiptCallback = null; this.host = "esqa.moneris. com"; this.debug = false; this._credentials = null; }; --------------------"
    • 我认为问题在于您实际上是从 Nodejs 请求他们的 JS 库。我不熟悉 Moneris,但您需要找到一种使用 Nodejs 进行 API 调用的方法。看起来他们没有 Nodejs 库:community.moneris.com/product-forums/f/5/t/36
    • 你能看看这个链接developer.moneris.com/en/Documentation/NA/…,让我知道如何实现processPayment功能吗?
    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    相关资源
    最近更新 更多