laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 671 forks source link

Multiple Plans #922

Closed Nuranto closed 4 years ago

Nuranto commented 4 years ago

Description:

I just upgraded from 10 to 11 on my dev environment. I started using multiple plans, but I think there may be is a bug :

I added a plan to an existing subscription. However, when I try to check the subscription via subscribedToPlan method, it does not work. After a bit digging, the issue seems to be : I still have stripe_plan filled with my intial subscription in my subscriptions table, and I have only one row for that user in my subscription_items table. So the hasMultiplePlans method returns false, and so hasPlan returns false also.

The issue would be probably solved if I migrate all my current subscriptions to subscription_items table, and then set stripe_plan and qty to null in subscriptions table. But, I don't see any of this on the migration guide, so I guess it should not behave like this ? When adding the second plan, both subscriptions should have been migrated to subscription_items, am I right ?

I'm not sure I'm clear, so here is the situation before/after upgrading :

Before

subscriptions table :

user_id = 1
stripe_plan = monthly

->subscribedToPlan('monthly') => returned true

After upgrading, and after ->addPlan('option1')

subscriptions table :

id = 1
user_id = 1
stripe_plan = monthly

subscription_items table :

subscription_id = 1
stripe_plan = option1

->subscribedToPlan('monthly') => return true ->subscribedToPlan('option1') => return false ->hasMultiplePlans() => return false

driesvints commented 4 years ago

I think I see what the problem is. Because you indeed don't have the initial subscription items there's a check somewhere that doesn't makes sense. I'll fix this.

driesvints commented 4 years ago

PR: https://github.com/laravel/cashier/pull/926