I am having an issue with Laravel Cashier. I am trying to use their checkout functionality that should redirect to a Stripe checkout page, however it does not. It returns a blank page as if it were a get request.
Note, this is a subscription checkout, not a product checkout
Notes: I recently upgraded this application to Laravel 6 from 5.8 and Cashier to 12.17.2 from 10.2 so I could get the checkout functionality which was introduced in Cashier 12.7
The blade page just has a form and a submit button that posts to the subscription.create route.
That route has the following code, but when it executes it does not load a Stripe checkout page, it loads a blank page at the /subscription endpoint. This is set up as a POST route in web.php pointing to the correct function
Note, the variables being passed to the newSubscription function have been changed, they are correct in the actual code
Route::get('/subscription-checkout', function (Request $request) {
return $request->user()
->newSubscription('default', 'plan')
->allowPromotionCodes()
->checkout([
'success_url' => route('thankyou'),
'cancel_url' => route('home'),
]);
})->name('subscription.create');
Update – So it is returning a JSON object to the page, but it is never redirecting to the payment page as it is supposed to. The JSON object contains the payment page URL….
This is very confusing.
2
Answers
Okay, so it turns out Cashier 12.7 works on Laravel 6 But Checkout only works on 8 and above.
not sure why you are calling the
checkout
on acreate
method. and its showing blank because you are not returning anything.you have to define a route which returns that checkout process (which then redirects to stripe checkout page).
Something like
the
checkout
method of cashier is just a wrapper of stripe checkout which you have to pass in the data of what you trying to checkout, you can see here full example from StripeEDIT:
if the object you getting from the response is actual stripe
checkout
object, you could simply grab the checkout url and redirect to it. if not then you might be able to do your own checkout session assuming your cashier version supports checkout session.Something like