Search code examples
phplaravellaravel-5stripe-paymentslaravel-cashier

Laravel Cashier + Stripe: No Such Customer


I am working on developing a subscription for a web application using Laravel Cashier and Stripe.

I'm using Stripe v3 JavaScript API and using the card elements to generate the Stripe token. The Stripe token is being generated, and if you look in the Stripe dashboard a customer is created. Additionally, a stripe id is being saved in the user database. However, when I try and subscribe the user to a plan with the following code:

$user->newSubscription($planId, $planId)->create($stripeToken, [
            'email' => $user->email
]);

It fails with the error: "No such customer: cus_xxxxxx". The $planId variable is the ID of the plan in Stripe.

Like I said, the stripe token is being generated correctly, the customer is created in the Stripe dashboard, and the stripe id is being set in the database. I've done some digging into the Laravel Cashier code, and it seems to be getting the error when it tries to update the card info. More specifically, it fails at this function:

public function asStripeCustomer()

Which is found in the billable model.

I contacted Stripe support, and they said there are no further requests being made to their API after the initial customer is created.

My laravel version is 5.5.34, and I'm using the latest Cashier release. I've tried reinstalling Cashier and it still doesn't work. I've also refreshed my cache.

Any help is greatly appreciated.


Solution

  • Just in case anyone else faces this issue in the future, I managed to get it fixed.

    Essentially, the issue comes down to your database settings. For me, my database settings were saving everything lowercased. Stripe is case sensitive with its customer keys. After I changed my database to be case sensitive began to work again.