简体   繁体   English

如何将 Stripe 3D 安全一次性付款 + 定期订阅放在一个弹出窗口中?

[英]How can put Stripe 3D secure one time payment + recurring subscription in a single pop up?

I am trying to integrate 3D secure Stripe payment for a "bundle" which has a one time payment AND a one year recurring payment.我正在尝试将 3D 安全条带支付集成为“捆绑”,该“捆绑”具有一次性付款和一年定期付款。

To achieve this the solution i found is using stripe.payment_intent for one time payment and stripe.subscription for recurring yearly payment.为了实现这一点,我找到的解决方案是使用 stripe.payment_intent 进行一次性付款,使用 stripe.subscription 进行年度付款。

Both payments work but the thing is that it shows 2 pop ups (one for each payment) which is confusing for the user.两种付款都有效,但问题是它显示了 2 个弹出窗口(每次付款一个),这让用户感到困惑。

My question is how can i group both payments with Total price in 1 3D secure popup?我的问题是如何在 1 个 3D 安全弹出窗口中将两次付款与总价分组?

Here's my backend:这是我的后端:

    const customer = await stripeService.createStripeCustomer(
      name,
      email,
      payment_method,
    )
    const subscription = await stripeService.createStripeSubscription(
      customer,
      stripePriceElement,
      discount,
      trialDays,
    )
      
    let status = subscription.status
    let client_secret =
      trialDays > 0
        ? null
        : subscription.latest_invoice.payment_intent.client_secret

    if (productIsBundle) {
      try {
        const amount = 4000

        const paymentIntent = await stripeService.createStripePaymentIntent(
          amount,
          payment_method,
          customer,
          model.name,
          model.email,
          product.productName,
        )
        let intent_secret = paymentIntent.client_secret
        let intent_status = paymentIntent.status
        res.status(200).json({
          product: 'bundle',
          client_secret,
          status,
          intent_secret,
          intent_status,
          subscription,
        })
      } catch (error) {
        res.status(200).json({ status: 'Payment Intent failed', error })
      }

and here's the front with 2 card confirmations:

try {
          if (intent_secret) {
            await stripe.confirmCardPayment(intent_secret);
          }
          await stripe
            .confirmCardPayment(client_secret)
            .then(async (result) => {
              if (result.error) {
                setStripeError(result.error.message);
              }
              if (result.paymentIntent?.status === 'succeeded') {
                await axios.post(
                  ${process.env.REACT_APP_BACKEND}/users/payment/success,
                  {
                    modelId: model.id,
                  },
                  token,
                );

Instead of using a separate Payment Intent for the one-time payment you can instead add the one-time payment as a line item on the first Invoice for the Subscription .您可以将一次性付款添加为订阅的第一张发票上的行项目,而不是使用单独的付款意图进行一次性付款。

This approach will allow your customer to pay for a single Invoice once when the Subscription starts.这种方法将允许您的客户在订阅开始时支付单张发票一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM