Back
Blog

Cancelling a Stripe Subscription On 'Period End'

Jan 17, 2021

By Katy G

Share:
  • linkedin
  • facebook
  • instagram
  • twitter
<p>Stripe's documentation on cancelling a subscription at the end of a period isn't entirely up to date.</p><p><a target="_blank" rel="noopener noreferrer" href="https://stripe.com/docs/billing/subscriptions/cancel"><span style="color:hsl(270,75%,60%);">https://stripe.com/docs/billing/subscriptions/cancel</span></a></p><p>For cancelling at end of period, the docs say to do the following:</p><!-- codeBlock --> <div class="code-block mx-auto" x-data="hljs()"> <pre> <code class="language-ruby">Stripe::Subscription.update( &#039;sub_&#039;, { cancel_at_period_end: true, } )</code> </pre> </div> <p>Easy enough, right?</p><p>WRONG.</p><p>When actually doing this we were getting the following error:</p><!-- codeBlock --> <div class="code-block mx-auto" x-data="hljs()"> <pre> <code class="language-json">{ &quot;error&quot;: { &quot;message&quot;: &quot;The subscription is managed by the subscription schedule `sub_sched_`, and updating any cancelation behavior directly is not allowed. Please update the schedule instead.&quot;, &quot;type&quot;: &quot;invalid_request_error&quot; } }</code> </pre> </div> <p>After contacting stripe support, if you wish to cancel at the period end you need to do the following:</p><ol><li>Update phases on subscription schedule object to pass only current phase.</li><li>Set end_behavior to 'cancel'</li></ol><!-- codeBlock --> <div class="code-block mx-auto" x-data="hljs()"> <pre> <code class="language-ruby">Stripe::SubscriptionSchedule.update( &#039;sub_sched_&#039;, {end_behavior: &#039;cancel&#039;}, )</code> </pre> </div> <p>Links:</p><p><a target="_blank" rel="noopener noreferrer" href="https://stripe.com/docs/billing/subscriptions/subscription-schedules#updating"><span style="color:hsl(270,75%,60%);">https://stripe.com/docs/billing/subscriptions/subscription-schedules#updating</span></a></p><p><a target="_blank" rel="noopener noreferrer" href="https://stripe.com/docs/api/subscription_schedules/update?lang=ruby"><span style="color:hsl(270,75%,60%);">https://stripe.com/docs/api/subscription_schedules/update?lang=ruby</span></a></p>
Back to Explore Focused Lab
/Contact us

Let’s build better software together