Strip ExpressCheckoutElement 中 apple_pay 或 google_pay 的 paymentMethod 应该是什么

问题描述 投票:0回答:1

我正在使用 ExpressCheckoutElement

<ExpressCheckoutElement
          options={{
            wallets: {
              googlePay: 'never',
              applePay: 'always',
            },
            buttonType: {
              applePay:'donate',
            },
            paymentMethodOrder: ['googlePay', 'applePay'],
            layout: {
              maxRows: 1,
              maxColumns: 1,
              overflow: 'auto',
            },
          }}
          onConfirm={onConfirm}
        />

在我的 onConfirm 函数中,我正在创建并确认 paymentIntent 但要确认 paymentIntent,我需要一个 paymentMethodId(以“pm_”开头的)

const onConfirm = useCallback(
async (event) =\> {
if (!stripe) {
return
}
// console.log('🔥', event)
// return

      createPaymentIntent(paymentIntentInput, {
        onSuccess: async (data) => {
          const { client_secret: clientSecret } = data
    
          confirmPayment(
            {
              payment_method: //Payment method needed here!!!
            },
            {
              onSuccess: async ({ status, message, success }) => {
             
              },
              onError: (err) => {
                
              },
            }
          )
        },
        onError: (err) => {
        
          })
        },
      })
    },
    [
      stripe,
      elements,
      user,
      amount,
      applicationFeeAmount,
      currency,
      paymentMethod,
    ]

)

我尝试创建一个像我为卡支付所做的那样

const { paymentMethod } = await stripe.createPaymentMethod({
type: 'card',
card: cardElement,
billing_details: {
email: getValues('email'),
name: `${getValues('firstName')} ${getValues('lastName')}`,
},
})

像这个一样,但这适用于不用于Google Pay或Apple Pay的卡,我需要给它提供cardElement,而在使用我用于Apple和Google Pay的

ExpressCheckoutElement
时我没有该卡元素

我也尝试过不发送付款方式,但它带来了错误

"You cannot confirm this PaymentIntent because it's missing a payment method. You can either update the PaymentIntent with a payment method and then confirm it again, or confirm it again directly with a payment method."

即使在我的 Elements 组件中有

automatic_payment_methods: { enabled: true },

reactjs stripe-payments applepay google-pay
1个回答
0
投票

要在 Express Checkout Element 中创建付款方式,您可以按照此处的指南进行操作:https://stripe.com/docs/elements/express-checkout-element/accept-a- payment#create-pm

更具体地说:

expressCheckoutElement.on('confirm', async (event) => {
  ...

  const {error: submitError} = await elements.submit();
  if (submitError) {
    handleError(submitError);
    return;
  }

  // Create a PaymentMethod using the details collected by the Express Checkout Element
  const {error, paymentMethod} = await stripe.createPaymentMethod({
    elements,
    params: {
      billing_details: {
        name: 'Jenny Rosen',
      }
    }
  });

  ...
}

或者,我建议对所有支付方式(包括卡、Apple Pay、Google Pay 和其他本地支付方式)使用 Payment Element(单一集成),而不是单独集成钱包支付:https://stripe.com/文档/付款/接受付款?platform=web&ui=elements&client=react

© www.soinside.com 2019 - 2024. All rights reserved.