DEV Community

Cover image for Cancelling a stripe subscription on 'period end'
katydidknot for Focused

Posted on • Edited on • Originally published at focusedlabs.io

4 1

Cancelling a stripe subscription on 'period end'

Stripe's documentation on cancelling a subscription at the end of a period isn't entirely up to date.

https://stripe.com/docs/billing/subscriptions/cancel

For cancelling at end of period, the docs say to do the following:

Stripe::Subscription.update(
  'sub_',
  {
    cancel_at_period_end: true,
  }
)
Enter fullscreen mode Exit fullscreen mode

Easy enough, right?

WRONG.

When actually doing this we were getting the following error:

{
  "error": {
    "message": "The subscription is managed by the subscription schedule `sub_sched_`, and updating any cancelation behavior directly is not allowed. Please update the schedule instead.",
    "type": "invalid_request_error"
  }
}
Enter fullscreen mode Exit fullscreen mode

After contacting stripe support, if you wish to cancel at the period end you need to do the following:

  1. Update phases on subscription schedule object to pass only current phase.
  2. Set end_behavior to 'cancel'
Stripe::SubscriptionSchedule.update(
  'sub_sched_',
  {end_behavior: 'cancel'},
)
Enter fullscreen mode Exit fullscreen mode

Links:

https://stripe.com/docs/billing/subscriptions/subscription-schedules#updating

https://stripe.com/docs/api/subscription_schedules/update?lang=ruby

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
austinbv profile image
Austin Vance

Nice!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay