Un-canceling a Stripe subscription

Brent Royal-Gordon picture Brent Royal-Gordon · Feb 14, 2015 · Viewed 7k times · Source

Suppose a user wants to cancel their subscription, so I issue a command like this:

stripe_subscription.delete(at_period_end: true)

Later, though—before the period ends—the user changes their mind. Is there a call I can issue to undo the scheduled cancellation?

If not, what's the best way to implement this? My best guess looks like this:

new_subscription = stripe_customer.subscriptions.create(plan: stripe_subscription.plan.id, trial_end: stripe_subscription.current_period_end)
stripe_subscription.delete()   # if permitted
self.stripe_subscription = new_subscription
save!

Is there something better I can do?

Answer

koopajah picture koopajah · Feb 14, 2015

If the subscription is still active, you just have to update the current subscription and pass the plan id once again and it would resume the subscription.

In PHP you would do:

$customer = Stripe_Customer::retrieve("cus_XXX");
$subscription = $customer->subscriptions->retrieve("sub_YYY");
$subscription->plan = "myPlanId";
$subscription->save();

This is covered in one of Stripe's support article in more details here.