简体   繁体   English

Stripe 将 paymentMethod 添加到试用订阅并稍后验证信用卡

[英]Stripe adding paymentMethod to trial subscription and later validate credit card

I'm working on stripe integration with react node.js我正在与 react node.js 进行条带集成

While creating a subscription without trial, I have no issues, and all use-cases are much simple.在没有试用的情况下创建订阅时,我没有遇到任何问题,而且所有用例都非常简单。

But, I'm trying to create free trial without collecting credit card details, later when trial expired, I would like to collect credit card details但是,我试图在不收集信用卡详细信息的情况下创建免费试用,稍后当试用期结束时,我想收集信用卡详细信息

Server side: Creating Trial Subscription without payment method:服务器端:创建没有付款方式的试用订阅:

  const subscription = await stripe.subscriptions.create({
    customer: customer.id,
    items: [{ price: priceId }],
    trial_end: expiredAt.unix(),
    expand: ['latest_invoice.payment_intent'], 
  });

ClientSide: Later when trial expired, I would like to collect credit card details(paymentMethod), check if user action is required due to failures or 3ds and update the subscription by updating the customer's default payment_method: ClientSide:试用期结束后,我想收集信用卡详细信息(paymentMethod),检查是否由于故障或 3ds 需要用户操作,并通过更新客户的默认 payment_method 来更新订阅:

  const updateCustomerDefaultPaymentMethod = await stripe.customers.update(
    customerId,
    {
      invoice_settings: {
        default_payment_method: req.body.paymentMethodId,
      },
    }
  );

How can I update the subscription to perform paymentIntent or charge the user, and return to client same subscription object with status 'in_complete' same as when creating subscription without trial_period?如何更新订阅以执行 paymentIntent 或向用户收费,并返回给客户端相同的订阅 object,状态为“in_complete”,与在没有试用期的情况下创建订阅时相同? Currently when running my code, I keep getting status='active' because the first invoice is in status='paid' with price of '0$'.目前,在运行我的代码时,我不断收到 status='active',因为第一张发票处于 status='paid',价格为 '0$'。

In the case of a free trial, creating a subscription won't result in an initial payment, and Stripe will instead create a SetupIntent under the hood for you automatically.在免费试用的情况下,创建订阅不会产生初始付款,Stripe 会自动在后台为您创建一个SetupIntent This SetupIntent is meant to be used when collecting the customer's payment method.此 SetupIntent 用于收集客户的付款方式。 So at any point during the trial , the customer would need to return to your app to enter their credit card details, which you would then save using the SetupIntent:因此, 在试用期间的任何时候,客户都需要返回到您的应用程序以输入他们的信用卡详细信息,然后您将使用 SetupIntent 保存这些详细信息:

Once the payment method is setup and saved to the customer (as the default payment method for invoices ) it will be used to pay for the subscription's first invoice when the trial ends.一旦付款方式设置并保存给客户(作为发票的默认付款方式),它将用于在试用结束时支付订阅的第一张发票。 The first payment after a trial is considered an off-session payment (last FAQ), so if that payment fails Stripe will attempt to recollect the payment using the usual smart retries and dunning functionality. 试用后的第一笔付款被视为会话外付款(最后一个常见问题解答),因此如果付款失败,Stripe 将尝试使用通常的智能重试和催款功能重新收取付款。

In a nutshell, you need to use the SetupIntent that's created (and attached to the subscription) to save the user's payment information.简而言之,您需要使用创建(并附加到订阅)的 SetupIntent 来保存用户的付款信息。

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

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