首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Google Pay react按钮中调用ProcessPayment函数?

如何在Google Pay react按钮中调用ProcessPayment函数?
EN

Stack Overflow用户
提问于 2021-04-19 12:29:40
回答 1查看 93关注 0票数 0

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

从google教程向网关发送令牌

代码语言:javascript
复制
 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}                                  
                />
EN

回答 1

Stack Overflow用户

发布于 2021-04-21 01:01:43

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

您的processPayment负责调用您的后台,并将支付token传递给您的支付网关。

示例:

代码语言:javascript
复制
onLoadPaymentData={paymentRequest => {
  processPayment();
}}
代码语言:javascript
复制
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 */}
    })
  });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67155980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档