微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Google Pay 反应按钮中调用 ProcessPayment 功能?

如何解决如何在 Google Pay 反应按钮中调用 ProcessPayment 功能?

我正在将 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','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}                                  
                />

解决方法

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

您的 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 */}
    })
  });
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。