当客户想降级到更便宜的订阅时,让他/她使用当前订阅直到当前计费周期结束,然后自动切换到更便宜的订阅。此外,我需要收到有关更改的通知,以便我可以运行一些内部逻辑。
我已使用订阅时间表来安排订阅在当前期间结束时的价格变化。使用 Stripe 仪表板,我可以看到价格已在正确的时间成功更改,但是:
以下是详细步骤:
stripe.subscriptionSchedules.create({ from_subscription: subId }).
stripe.subscriptionSchedules.update(schedule.id, {
phases: [
{
start_date, // billing_cycle_anchor of current subscription
items: [
{ price: currentPriceId, quantity: 1 }, // current plan to be used until period end
],
iterations: 1, // 'iterations' is set to 1, this is important because we want current phase to end at the end of current period
},
{
proration_behavior: 'none', // no proration when transition to this phase
items: [
{ price: nextPriceId, quantity: 1 }, // new plan to be switched to after current period
],
iterations: 1, // 'iterations' is set to 1 and 'end_behavior' need to be set to 'release'
},
],
end_behavior: 'release', // release this schedule after last phase, so that subscription will continue as normal
});
编辑:这种奇怪的行为是因为我们使用的信用卡有问题,我们的 Stripe 帐户被列入黑名单。解决信用卡问题,一切恢复正常。
答案 0 :(得分:0)
进入新阶段时您不会收到 updated
事件,因为订阅在技术上没有更新。
相反,您应该聆听 invoice.created
event。当订阅计划进入一个新阶段时,意味着它进入了一个新的计费周期,意味着创建了一张发票。