gpt4 book ai didi

node.js - Stripe 将支付方式添加到试用订阅,然后验证信用卡

转载 作者:行者123 更新时间:2023-12-04 14:10:42 28 4
gpt4 key购买 nike

我正在研究与 react node.js 的 strip 集成
在无需试用的情况下创建订阅时,我没有任何问题,并且所有用例都非常简单。
但是,我正在尝试创建不收集信用卡详细信息的免费试用版,稍后试用期到期后,我想收集信用卡详细信息
服务器端:创建没有付款方式的试用订阅:

  const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: priceId }],
trial_end: expiredAt.unix(),
expand: ['latest_invoice.payment_intent'],
});
客户端:试用期结束后,我想收集信用卡详细信息(paymentMethod),检查是否由于失败或3ds而需要用户操作,并通过更新客户的默认payment_method来更新订阅:
  const updateCustomerDefaultPaymentMethod = await stripe.customers.update(
customerId,
{
invoice_settings: {
default_payment_method: req.body.paymentMethodId,
},
}
);
如何更新订阅以执行 paymentIntent 或向用户收费,并将状态“in_complete”的相同订阅对象返回给客户端,与在没有 trial_period 的情况下创建订阅时相同?
目前,在运行我的代码时,我不断收到 status='active',因为第一张发票的状态为 status='paid',价格为'0$'。

最佳答案

在免费试用的情况下,创建订阅不会导致初始付款,而 Stripe 将创建 SetupIntent在引擎盖下自动为您服务。此 SetupIntent 旨在用于收集客户的付款方式。所以在 any point during the trial ,客户需要返回到您的应用程序以输入他们的信用卡详细信息,然后您将使用 SetupIntent 保存这些信息:

  • subscription.pending_setup_intent
  • Confirm the SetupIntent with the collected card details

  • 一旦付款方式被设置并保存给客户(如 default payment method for invoices),它将用于在试用期结束时支付订阅的第一张发票。 first payment after a trial is considered an off-session payment (最后一个常见问题解答),因此如果付款失败,Stripe 将尝试使用通常的 smart retries and dunning 收回付款。功能。
    简而言之,您需要使用已创建(并附加到订阅)的 SetupIntent 来保存用户的付款信息。

    关于node.js - Stripe 将支付方式添加到试用订阅,然后验证信用卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64540630/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com