gpt4 book ai didi

stripe-payments - Stripe订阅在支付成功后更新计费周期 anchor

转载 作者:行者123 更新时间:2023-12-05 05:53:53 24 4
gpt4 key购买 nike

假设我有一个 stripe 订阅(从 2021-10-01 开始),并在 2021-11-01 的第一个计费周期结束时

  1. stripe 尝试对文件中的卡收费
  2. 假设交易因 insufficient_funds 而失败
  3. stripe 在 2 天后(2021-11-03)再次重试,这次交易成功。

现在订阅将在 2021-12-01 再次向用户收费,即使上一次付款是在 2021-11-03 完成的

用户付款未完成时(2021-11-01 至 2021-11-03)我不提供服务

这里的最佳做法是什么以便下一次收费发生在 2021-12-03(而不是 2021-12-01)?

最佳答案

使用 stripe webhooks 和 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;
}

更多信息:

https://stripe.com/docs/webhooks

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

关于stripe-payments - Stripe订阅在支付成功后更新计费周期 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69802556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com