Stripe:订阅更新时没有网络钩子事件

时间:2021-02-18 04:34:27

标签: stripe-payments

我的目标

当客户想降级到更便宜的订阅时,让他/她使用当前订阅直到当前计费周期结束,然后自动切换到更便宜的订阅。此外,我需要收到有关更改的通知,以便我可以运行一些内部逻辑。

我尝试了什么

我已使用订阅时间表来安排订阅在当前期间结束时的价格变化。使用 Stripe 仪表板,我可以看到价格已在正确的时间成功更改,但是:

  • 没有网络钩子事件。我期待 customer.subscription.updated 事件,并且还尝试收听 subscription_schedule.updated 事件但没有成功。
  • 即使等了几个小时,客户也没有按新价格收费。

以下是详细步骤:

  • 客户对每日价格下标。
  • 客户希望将订阅更改为更便宜的价格。
  • 我从订阅中创建了一个订阅计划:
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 帐户被列入黑名单。解决信用卡问题,一切恢复正常。

1 个答案:

答案 0 :(得分:0)

进入新阶段时您不会收到 updated 事件,因为订阅在技术上没有更新。

相反,您应该聆听 invoice.created event。当订阅计划进入一个新阶段时,意味着它进入了一个新的计费周期,意味着创建了一张发票。