Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ShamiCanCode's avatar

stripe cashier laravel

Stripe\ Exception\ InvalidRequestException PHP 8.1.6 9.35.1 No such customer: 'cus_N8wFxoP3f0Z3MX'

0 likes
11 replies
vincent15000's avatar

What's your question ? Where is the code that generates this error ?

jaseofspades88's avatar

The exception couldn't be much clearer really. cus_N8wFxoP3f0Z3MX doesn't exist in Stripe. Check that you're not confusing the development mode customer id and a production mode customer id.

1 like
ShamiCanCode's avatar

@vincent15000

public function index($id)
{
    /** @var User $user */
    $user = Auth::user();
    $plan = Plan::find($id);
    if (!is_null($plan)) {
        if ($user->subscribed('gold')) {
            return redirect('/home')->with('status', 'You already subscribed to this plan');
        } else {
            return view('checkout', [
                'user' => $user,
                'intent' => $user->createSetupIntent(),
                'plan' => $plan
            ]);
        }
    } else
        return redirect('/');
}

public function checkout(Request $request)
{
    /** @var User $user */
    $user = Auth::user();
    $plan = $request->input('plan');
    $planType = Plan::where('plan_id', $plan)->pluck('plan_type')->first();
    $paymentMethod = $request->input('payment_method');
    $user->createOrGetStripeCustomer();
    $user->addPaymentMethod($paymentMethod);

    $user->newSubscription($planType, $plan)->trialDays($plan->trail_days)
        ->create($paymentMethod, [
            'email' => $user->email
        ]);
    return redirect('/home')->with('status', 'Subscribed successfully! enjoy 😊');
}

index function is when the user clicks a plan checkout function when user fill his debit card information

1 like
vincent15000's avatar

@ShamiCanCode As the customer doesn't exist, for me there are two possibilities :

  • the user has an existing account on Stripe but you don't retrieve its id correctly

  • the user doesn't have any account on Stripe and $user->createOrGetStripeCustomer(); don't create it on Stripe

Have you checked the datas in the database ?

vincent15000's avatar

@ShamiCanCode You need to find why you are getting a customer id which doesn't exist in Stripe. Have you tried to create a totally new user ?

jaseofspades88's avatar

$user->createOrGetStripeCustomer(); this assumes the customer id you have stored in the user model is correct. In your case it's either been deleted or the reference has been changed but either way, the customer doesn't exist in stripe. That's the problem here... if you choose to do nothing with that information then it doesn't matter how many times people tell you the same information!

1 like

Please or to participate in this conversation.