Search code examples
laravellaravel-cashier

Laravel cashier `$user->subscribed()` returning true when no subscription exists


My code is simple:

if($user->subscribed('main')){
    $user->subscription('main')->cancel();
}

I get this response:

Stripe \ Error \ InvalidRequest
No such subscription: sub_EQTvxKjit2Ak6i

The subscription was in fact previously cancelled, so it shouldn't be giving a true response.

I tried returning $user->subscribed('main') and it came back as true.

This user has other subscriptions, but 'main' is not active.

Am I missing something?


Solution

  • $user->subscribed() only checks the database for subscription status--it doesn't query the Stripe API at all. But when you try to cancel that subscription, then it queries the API.

    So that could produce an error like this if your database is out of sync with your data in Stripe. Maybe your database has subscription from Stripe test mode, but you're querying the Stripe production API? Or vice versa?