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

Check all subscriptions when running `$user->subscribed('name')` #1575

Closed maxheckel closed 11 months ago

maxheckel commented 11 months ago

Currently, if a user has multiple subscriptions with the same name where one is canceled and another is active and the canceled subscription was created after the active subscription cashier will return that the user is not subscribed. This is due to the subscription pulling just the first() model out of the database. Instead we should check every subscription with the same name and return if any of them are active.

As an example, cashier was returning false for subscribed('unlimited') with the following database state:

image
driesvints commented 11 months ago

The current behavior is the correct behavior. The latest created subscription is always the one you should check. All the ones before need to be canceled/handled before starting a new one. These records are purely held for historic purposes. Please check the docs: https://laravel.com/docs/10.x/billing#checking-subscription-status

Screenshot 2023-09-26 at 14 04 37