简体   繁体   English

stripe:在保存的卡上创建 30 天的试用订阅费用,但允许用户升级并立即开始收费?

[英]stripe: Create a 30-day trial subscription charge on a saved card but allow user to upgrade and start charging immediately?

So before a user can create an account I want to save their credit card to charge a subscription with 30 day trial AND the ability to immediately charge the card for a subscription if the user demands it.因此,在用户创建帐户之前,我想保存他们的信用卡以收取 30 天试用期的订阅费用,并且能够在用户需要时立即向卡收取订阅费用。

so my logic is to所以我的逻辑是

1) create a customer 1)创建客户

2) add payment details for customer 2)为客户添加付款明细

3) create subscription with 30 day trial 3) 创建订阅 30 天试用

4) activate subscription upon user upgrade action 4) 在用户升级操作时激活订阅

I'm not clear on how 4) is possible.我不清楚 4) 是如何可能的。 I get that on 3), after 30 days, they are on a subscription.我在 3) 上得到了,30 天后,他们订阅了。 but what if the customer wants to start using the full version immediately before the trial is over, how would I create a charge for the subscription?但是,如果客户想在试用期结束前立即开始使用完整版,我将如何为订阅收费?

const stripe = require('stripe')('sk_test_asdfasdf');
(async () => {
  // Create a Customer:
stripe.customers.create({
  email: 'jenny.rosen@example.com',
  payment_method: 'pm_1FWS6ZClCIKljWvsVCvkdyWg',
  invoice_settings: {
    default_payment_method: 'pm_1FWS6ZClCIKljWvsVCvkdyWg',
  },
}, function(err, customer) {
  // asynchronously called
});

//create subscription
stripe.subscriptions.create({
  customer: 'cus_4fdAW5ftNQow1a',
  items: [
    {
      plan: 'plan_CBXbz9i7AIOTzr',
    },
  ],
  expand: ['latest_invoice.payment_intent'],
}, function(err, subscription) {
    // asynchronously called
  }
);

})();

I'll chime in on this really quick, to hopefully get you in the right direction;我会非常快地加入这个话题,希望能让你朝着正确的方向前进; This sounds like a case for Setup Intents.这听起来像是 Setup Intents 的一个例子。 You can collect payment details, with the intent to charge at a later time.你可以收集付款细节,意图在稍后的时间来充电。 Since the trial won't incur any charges at first, all is good.由于审判一开始不会产生任何费用,所以一切都很好。 However you work out the logic to switch from trial to active status on the subscription, you'd update the subscription end-date to end the trial.无论您如何制定从订阅的试用状态切换到活动状态的逻辑,您都需要更新订阅结束日期以结束试用。

This is nicely summarized here, for the most part, save for updating the Subscription and setting the trial_end argument:在这里很好地总结了这一点,大部分情况下,除了更新订阅和设置trial_end参数:

https://stripe.com/docs/payments/save-and-reuse https://stripe.com/docs/payments/save-and-reuse

API docs entry on updating the Subscription:有关更新订阅的 API 文档条目:

https://stripe.com/docs/api/subscriptions/update#update_subscription-trial_end https://stripe.com/docs/api/subscriptions/update#update_subscription-trial_end

Once the trial is over, whether "naturally" or by explicitly setting the end timestamp, an invoice should be sent out or default payment method charged, depending on your settings.试用结束后,无论是“自然地”还是通过明确设置结束时间戳,都应发送发票或收取默认付款方式,具体取决于您的设置。 It wouldn't hurt to work in some good flow here, concerning user-experience;关于用户体验,在这里以某种良好的流程工作不会有什么坏处; For example, having a confirmation step to let the customer know they are about to be charged X amount, before actually firing off that off.例如,在实际取消之前,有一个确认步骤让客户知道他们将被收取 X 金额。

Here are other helpful docs:以下是其他有用的文档:

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

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