Created
August 15, 2018 12:22
-
-
Save linkyndy/62599a76dac8a9e3df3b58f0aa1c3315 to your computer and use it in GitHub Desktop.
Canceling (immediately/at period end) and reactivating Stripe subscriptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Canceling and reactivating Stripe subscriptions | |
# https://stripe.com/docs/billing/subscriptions/canceling-pausing#reactivating-canceled-subscriptions | |
subscription = Stripe::Subscription.create(customer: 'cus_XXX', items: [{ plan: 'XXX' }]) | |
# Cancel at period end | |
subscription.delete(at_period_end: true) | |
# Reactivate | |
subscription.cancel_at_period_end = false | |
subscription.save # everything okay | |
# Cancel immediately | |
subscription.delete | |
# Try to reactive | |
subscription.cancel_at_period_end = false | |
subscription.save | |
# => Stripe::InvalidRequestError: (Status 404) (Request req_NeLQGouEN7UWgK) No such subscription: sub_XXX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment