无法恢复已取消的Stripe订阅?

4

我正在尝试实现取消的Stripe订阅恢复。我正在按照以下指南:https://stripe.com/docs/billing/subscriptions/canceling-pausing

我的取消代码如下:

// Update to cancel at the end of the period
await stripe.subscriptions.update(subscription.id, { cancel_at_period_end: true });

// Cancel the subscription
await stripe.subscriptions.del(subscription.id)

接下来,我继续如下:

// Grab the subscription
const subscription = await stripe.subscriptions.retrieve(subId);

// Resume
await stripe.subscriptions.update(subscription .id, {
      cancel_at_period_end: false,
      items: [{ id: subscription.items.data[0].id, plan: subscription.plan.id }],
    });

但我得到的错误信息是:

StripeInvalidRequestError:无此订阅:sub_GFmbrVQihHoD6P

我立即在集成测试中依次运行这些代码。我不知道这是否与此有关。

有什么想法吗?

1个回答

5

我想告诉你,你正在使用下面的两行代码。我认为你是在同一时间立即使用它们。

 // Update to cancel at the end of the period
await stripe.subscriptions.update(subscription.id, { cancel_at_period_end: true });

// Cancel the subscription
await stripe.subscriptions.del(subscription.id)

如果您想在当前计费周期结束后取消订阅,只需使用以下行。

  await stripe.subscriptions.update(subscription.id, { cancel_at_period_end: true });

在上述语句中,如果您想在当前计费周期结束之前重新激活订阅,则可以通过将cancel_at_period_end的值更新为false来重新激活订阅。请记住,订阅尚未达到结算周期的结束,只有这样才能重新激活,否则您需要为用户创建一个新的订阅。
如果您希望立即取消订阅,则必须仅使用下面的行。您无法重新激活订阅。您需要为用户创建一个新的订阅。
await stripe.subscriptions.del(subscription.id)

想要了解更多信息,您可以阅读以下内容。

https://stripe.com/docs/billing/subscriptions/canceling-pausing#reactivating-canceled-subscriptions


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接