#T.C.

1 messages · Page 1 of 1 (latest)

daring groveBOT
rugged plinth
#

What specific issue are you having?

little hare
#

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.

rugged plinth
#

Do you have a screenshot of the error you're seeing?

little hare
#

Are you seeing those images? Not positive I uploaded them correctly

rugged plinth
#

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?

little hare
#

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

rugged plinth
#

Yeah, try Route::post() instead of Route::get()

little hare
#

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

rugged plinth
#

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

little hare
#

Gotcha, any tips on doing that in Laravel? I thought that's what I was trying to do.

rugged plinth
#

What's the new error you're getting?

little hare
rugged plinth
#

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

little hare
#

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?

rugged plinth
#

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

little hare
#

Gotcha. No, same 419 Time Expired error.

#

Page* Expired error

rugged plinth
#

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?

little hare
#

<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

upbeat warren
#

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.

little hare
#

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?

upbeat warren
#

What do you mean by that exactly? It looks like you're setting ad-hoc pricing already with price_data

little hare
#

OK that's what I was hoping that did, just haven't been able to see it in action yet.

#

Thanks!