#T.C.
1 messages · Page 1 of 1 (latest)
What specific issue are you having?
So I've got all my products listed on the 'Welcome' page, and each has a button. I'm trying to route each button to trigger 'create-checkout-session.php' like the docs say, but I'm getting a 'Call to a member function checkout() on null' message in the browser. Obviously this is still local dev and I'm kind of new to all of this, I'm just wondering if there are any steps I'm missing.
Do you have a screenshot of the error you're seeing?
Are you seeing those images? Not positive I uploaded them correctly
Yeah, taking a look now
There might be a couple of things wrong with this. Did you mean to have your route for creating a Checkout Session have the POST method instead of the GET method? Where is the HTML for the page that is calling that route? What line is throwing the error?
So it's a react frontend, and the route's being called on resources/js/Components/ProductDisplay.jsx
I believe I tried POST before but it said it wasn't supported. Happy to try again though
Yeah, try Route::post() instead of Route::get()
This is what I got (changed it in the form it's being called from as well
OK, so I think I had localhost:4242 in my form instead of 8000, changed that and now I'm getting a 419 error
I don't think your routes are set up correctly. I believe you need to create the Checkout Session inside of the /create-checkout-session route
Gotcha, any tips on doing that in Laravel? I thought that's what I was trying to do.
What's the new error you're getting?
Can you copy/paste the code that creates the Checkout Session and put it inside of the POST route you made for create-checkout-session? Once you've done that, try and redirect to the Checkout Session's URL from the Checkout Session object
I've tried that a bunch of ways now and not really sure syntactically how to do it
this is my create-checkout-session.php file. Does it look wrong?
I meant take all of the code from line 11 to line 26 and put it in the route you created in the web.php file
Can you copy/paste all the relevant code to this thread so we can take a look at what you're doing now more specifically?
<form
className="text-white font-bold border py-2 px-3 text-grey-darkest text-center m-3 rounded-lg bg-gradient-to-br from-blue-400 to-emerald-400 hover:opacity-80"
action="http://localhost:8000/create-checkout-session"
method="POST"
>
<button
className="max-w-full"
id="submit"
role="link"
>
Buy
</button>
</form>
Route::post('/create-checkout-session', function (Request $request) {
return $stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
//this is where specificity for the Product-specific Price Id (default_price) should be handled
'line_items' => [
[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => $name,
],'unit_amount' => $amount,
'quantity' => 2,
],
],
'mode' => 'payment',
]]);
I sent the repo too if that's easier
Unfortunately I'm not super familiar with how Laravel routes work -- the Stripe code itself looks fine to me, but the issue you seem to be having is getting there in the first place
Broadly though I'd suggest breaking down the problem into figuring out your Stripe code and figuring out the routing issue. For that you might need to reach out to the Laravel expert community. I can help with the Stripe PHP code if there are issues there.
That makes sense. Everything I've been Googling does make this seem mostly like a Laravel issue.
Once I do get it routed correctly though, how do I dynamically set the default_price parameters of each item to the checkout session?
What do you mean by that exactly? It looks like you're setting ad-hoc pricing already with price_data