立即对订阅更改收费 [英] Immediately charge for subscription changes

查看:27
本文介绍了立即对订阅更改收费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为客户的订阅使用 Stripe 付款处理.当用户更改计划时,我们希望立即向他们收取按比例分配的差额.当计划具有不同的计费间隔时,Stripe 会自动执行此操作,但在具有相同间隔的计划之间更改时,Stripe 将付款推迟到下一个计费周期.

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?

推荐答案

您可以在更新订阅时使用设置为 nowbilling_cycle_anchor 强制其更改计费周期因此总是立即向客户收费.我个人认为这更有意义.这也适用于按比例分配.

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-循环#变化

这篇关于立即对订阅更改收费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆