【问题标题】:Cannot resume a cancelled stripe subscription?无法恢复已取消的条带订阅?
【发布时间】:2020-03-22 14:37:55
【问题描述】:

我正在尝试实现已取消的条带订阅恢复。我遵循以下指南: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

我立即在集成测试中一个接一个地运行这些。我不知道这是否与它有关。

有什么想法吗?

【问题讨论】:

    标签: node.js typescript stripe-payments


    【解决方案1】:

    我想在以下两行中告诉您您正在使用的内容。我认为您正在同时使用这些一个又一个

     // 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 1970-01-01
      • 2013-11-24
      相关资源
      最近更新 更多