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

alex32's avatar

laravel-cashier | Route not defined

In my Stripe dashboard I've created a product with 2 prices: 1mo, and 6mo plans. Then in my app I select one plan and I try to subscribe by passing a single price_string.

Laravel returns 'Route not defined" error , though apparently the route is defined. Any idea what could be wrong ? Many thanks

laravel: 10, cashier: latest

MainController.php

public function checkout_gold(Request $request) {   
      ....
      $pagedata= compact(["app_url" ]);  
      $price= $request->input('price');
  
      return $request->user()
            ->newSubscription('default', $price )  
            ->allowPromotionCodes()
            ->checkout([
                'success_url' => route('/retCheckout').'?plan=gold&status=success&pagedata='.$pagedata,
                'cancel_url' => route('/retCheckout').'?plan=gold&status=cancel&pagedata='.$pagedata
            ]); 
 
     }

pricetable.js

function subscribe (plan, price) {   

		var data = {price:price};
		var link = pagedata.app_url+"/checkout-"+plan;   
    
		$.ajax({ 
			headers: {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			}, 
			data: data,
			url: link,
			method: "POST",  
    ....
} 

web.php:

Route::get('/retCheckout', function (Request $request) {  
    return view('ret-checkout', ['plan' => $request->get('plan'), 'status' => $request->get('status'), 
     'pagedata' => $request->get('pagedata') ]); 
});

Route::controller(MainController::class)->group(function () {
        Route::post('/checkout-gold', 'checkout_gold'); 
       ...													

 });  

Screenshot

0 likes
7 replies
alex32's avatar

Thanks Martin, the 'price' error is gone but I still get an error on the callback route. I've updated the ticket with the new sr-shot.

gych's avatar

You're passing route path instead of route name to route() function

Update your route like this:

Route::get('/retCheckout', function (Request $request) {  
    return view('ret-checkout', ['plan' => $request->get('plan'), 'status' => $request->get('status'), 
     'pagedata' => $request->get('pagedata') ]); 
})->name('retCheckout');

Update checkout_gold return like this:

return $request->user()
            ->newSubscription('default', $price )  
            ->allowPromotionCodes()
            ->checkout([
                'success_url' => route('retCheckout').'?plan=gold&status=success&pagedata='.$pagedata,
                'cancel_url' => route('retCheckout').'?plan=gold&status=cancel&pagedata='.$pagedata
            ]); 
alex32's avatar

Thank you Gych, it worked!

But now I'm getting a CORS error from Stripe. Not sure why, though the csrf in my webhook is disabled:

web.php

Route::post('stripe/webhook', 'StripeWebhookController@handleWebhook')->name('cashier.webhook')->withoutMiddleware(\App\Http\Middleware\VerifyCsrfToken::class); 

sr-shot

martinbean's avatar

@alex32 Because you’re trying to call your back-end route via AJAX. You shouldn’t be. Submit the form to your controller, and then let your controller redirect the user to Stripe.

1 like
gych's avatar

@alex32 No problem, to fix the cors issue follow the advise from @martinbean

This is also metioned in the best answer from the stackoverflow link you've added in your last reply

Or, you can use a form submit from your HTML code to call your server instead of a JS HTTP POST request

Please or to participate in this conversation.