natral
natral

Reputation: 1098

How can I cancel a subscription item in Stripe at end of billing period

I'm using Stripe API and Laravel 5.4

My business logic requires that a user have 1 subscription and if the user needs to add more functionality they will be added as subscription items to that main subscription.

Now if a user were to cancel one of the services(functionality) he requested he needs to be able to use that functionality for the remainder of the current billing period and should only be billed for the time used.

In the API documentation I see that I can achieve this with a subscription by setting cancel_at_period_end = true but can't seem to find the equivalent when dealing with just a subscription item within a subscription.

Would appreciate any suggestions. Thanks

Upvotes: 12

Views: 8876

Answers (2)

Marco
Marco

Reputation: 473

You can update the subscription to expire at the end of the billing period, as explained in the documentation.

const subscription = await stripe.subscriptions.update(
  'sub_IlS7kzn3wPGV9D',
  {cancel_at_period_end: true}
);

Upvotes: 3

taintedzodiac
taintedzodiac

Reputation: 2908

A subscription_item (as well as a plan) doesn't currently support deleting it automatically at the end of the billing period.

A workaround for this:

  1. For the current subscription, set the subscription to cancel_at_period_end = true.
  2. Create a new subscription with all the same subscription_items as the original subscription (except for the item that they're cancelling), but set it to be a free trial until the same time as the current subscription.

Using that method, the customer can keep using all of their functionality until the end of the billing period. The "new" subscription won't be charged at all during the overlap time. At the end of the current billing period, the old subscription will end and the new subscription will begin.

Upvotes: 6

Related Questions