假设我有一个 stripe 订阅(从 2021 年 10 月 1 日开始),并在 2021 年 11 月 1 日第一个计费周期结束时
现在,即使之前的付款已于 2021 年 11 月 3 日完成,订阅仍将在 2021 年 12 月 1 日再次向用户收取费用
当用户付款未完成时,我不向用户提供服务(2021-11-01至2021-11-03)
此处的最佳做法是什么,以便下次收费发生在 2021 年 12 月 3 日(而不是 2021 年 12 月 1 日)?
使用 stripe webhook 和billing_cycle_anchor: "now":
// stripe webhooks: see example of how to implement here: https://stripe.com/docs/webhooks
const dataObject = event.data.object;
switch (event.type) {
//important to use the event invoice.updated to to avoid infinite loops
case "invoice.updated":
await stripe.subscriptions.update(dataObject.subscription, {
billing_cycle_anchor: "now",
proration_behavior: "create_prorations",
});
break;
}
Run Code Online (Sandbox Code Playgroud)
更多信息:
https://stripe.com/docs/webhooks
https://stripe.com/docs/billing/subscriptions/billing-cycle
| 归档时间: |
|
| 查看次数: |
759 次 |
| 最近记录: |