Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

stripe payments - Immediately charge for subscription changes

We are using Stripe payment processing for our customer's subscriptions. When users change plans, we want them to be charged immediately for the prorated difference. Stripe does this automatically when plans have different billing intervals but when changing between plans with the same interval, Stripe defers payment till the next billing period.

The way we handle this now is to create an invoice after updating the subscription, but if the billing fails for it fails, we need to do a rollback.

stripe.subscriptions.update(/* change plan */);
if (plans_have_different_billing_intervals) {
  try {
    stripe.invoices.create(/* for all pending charges */);
  } catch (err) {
    /* rollback subscription to old plan */
  }
}

Overall, this feels wrong and convoluted. Is there an easier/cleaner way to implement this that we aren't seeing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use billing_cycle_anchor set to now when updating a subscription to force it to change the billing cycle and thus always charge the customer immediately. Personally I think this makes a lot more sense. Also this works well with prorating.

await stripe.subscriptions.update(subscription.id, {
  billing_cycle_anchor: 'now',
  items: [{ id: itemId, plan: planId }]
});

https://stripe.com/docs/billing/subscriptions/billing-cycle#changing


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...