<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(
'sub_',
{
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">{
"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"
}
}</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(
'sub_sched_',
{end_behavior: 'cancel'},
)</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
Back
Blog