Reputation: 1763
I am trying to implement cancelled stripe subscription resuming. I am following the following guide: https://stripe.com/docs/billing/subscriptions/canceling-pausing
My cancel code looks like this:
// 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)
Then I resume with the following:
// 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 }],
});
But the error I get is:
StripeInvalidRequestError: No such subscription: sub_GFmbrVQihHoD6P
I am running these in an integration test one after the other immediately.. I dont know if this has something to do with it or not.
Any ideas?
Upvotes: 4
Views: 3724
Reputation: 119
I want to tell you on the below two lines you are using. I think you are using these one after the another immediately at the same time
// 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)
You have to use below line only if you want to cancel the subscription after the end of current billing cycle.
await stripe.subscriptions.update(subscription.id, { cancel_at_period_end: true });
In above statement only, if you want to reactivate before the end of current billing cycle then you can reactivate the subscription by updating the value of cancel_at_period_end to false. Keep in mind that subscription has not yet reached the end of the billing period. Only then it can be reactivated otherwise you need to create a new subscription for the user.
You have to use the below line only, if you want to cancel the subscription immediately. You can not reactivate the subscription. You need to create a new subscription for the user.
await stripe.subscriptions.del(subscription.id)
For more information you can read on this.
https://stripe.com/docs/billing/subscriptions/canceling-pausing#reactivating-canceled-subscriptions
Upvotes: 6