3
votes

I'm using Stripe (PHP Client, Laravel) to handle our subscriptions. We both have subscription and addons which Stripe doesn't seem to support nativly - however I've found a workaround but I encounter a problem.

Set up
We have some different subscriptions available to our users.

Monthly:

  • 1 Entity ($10/month)
  • 5 Entities ($40/month)
  • 10 Entities ($80/month)

Yearly:

  • 1 Entity ($100/year)
  • 5 Entities ($400/year)
  • 10 Entities ($800/year)

Addons:

  • 1 Entity ($10/month)
  • 1 Entity ($100/year)

Imagine a user is subscribed to a monthly 5 entities plan ($40/month) with 2 extra addons a month ($20/month). Total of $60/month.

The addons are added as SubscriptionItem using Stripe's PHP Client Library.

How would I go about upgrading the user to a yearly subscription like this:

  • 1x 5 Entities ($400/year) subscription
  • 2x 1 Entity ($200/year) addons

As you can see, the only difference is the billing interval and the price but the same access to our system.

I've tried to just upgrade the subscription plan (not the addon) but I got an error which seems logical due to the different billing intervals.

Would I have to remove all of the subscription addons (SubscriptionItems), then make the upgrade and when add the subscription addons again with their new billing interval? I don't like this approach since I would have to delete the initial subscription and then no where to return the user incase the charge fails...

Another way would be to create a entirely new subscription with the addons seperat from the initial. Then I could assign the new subscription to the customer and remove the old subscription.

All of this seems a bit weird since Stripe is so easy and flexible. I might me missing something? Am I?

What is the best way for me to switch between monthly and yearly plans when I have other subscription items in the subscription?

Hope you understand my question. Thanks!

1

1 Answers

2
votes

All Subscription Items under a Subscription object must use the same billing interval.

If you'd like to move the user from a monthly to an annual subscription, you'd need to update all items to an annual plan at the same time. From Stripe's side you'd do something like:

// create a customer
$customer = \Stripe\Customer::create([
    "source" => "tok_visa",
    "description" => "change my subscription customer"
]);

// create a sub with two monthly items
$sub = \Stripe\Subscription::create([
    "customer" => $customer->id,
    "items" => [
        [
            "plan" => "gold-monthly"
        ],
        [
            "plan" => "silver-monthly"
        ],
    ]
]);

// let's pretend we later retrieved that subscription
$subscription = \Stripe\Subscription::retrieve($sub->id);

// grab the items attached, change both to annual
echo \Stripe\Subscription::update($subscription->id, [
    'items' => [
        [
            'id' => $subscription->items->data[0]->id,
            'plan' => 'gold-annual',
        ],
        [
            'id' => $subscription->items->data[1]->id,
            'plan' => 'silver-annual',
        ],
    ],
]);