#joseph-react-checkout
1 messages · Page 1 of 1 (latest)
joseph-react-checkout
seems like the same problem someone asked about earlier. You mention port 3000 in parts of your code but the server seems started on 4242
I searched about the problem here if somebody had the same issue. Couldn't find so
Can you help me out with this
I have no idea what you mean, I just explained above what the issue is
you're hitting localhost:3000 but your server is on localhost:4242
Okay let me check
Please give me 5mins before closing the thread
Hey, same error shows after changing to 4242
I mean I ned more than this to help you sorry
What you need ?
I have changed the
successUrl: 'http://localhost:4242/success',
cancelUrl: 'http://localhost:4242/cancel',
As the official docs suggested
const YOUR_DOMAIN = 'http://localhost:4242';
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: 'price_1MKEdySJaJ2t0SuD5HMcFQ3n',
quantity: 1,
},
],
mode: 'payment',
success_url: ${YOUR_DOMAIN}?success=true,
cancel_url: ${YOUR_DOMAIN}?canceled=true,
});
res.redirect(303, session.url);
});
app.listen(4242, () => console.log('Running on port 4242'));
did you restart the whole server? Do you see other logs? How are you debugging this yourself as the developer of the app?
I have restarted the server multiple times and getting still the same axios error
Yes same 404 is saying
I have only that request going on the 4242 server and the the app is running on 3000 server
After clicking on the checkout it's giving
AxiosError {message: 'Request failed with status code 404', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
So if the app is still running on 3000, that would mean the create-checkout-session endpoint is also at localhost:3000, correct?
yes sir
It's making the request but with a 404 error
xhr.js:247 POST http://localhost:3000/create-checkout-session (404)
stripe sample code which I download to check the code is running fine with 4242 and local 3000
But when I integrated with the above code it's showing error
Your client side code should use whatever port you are actually running the server on
And I am still a bit unclear, can you reach other endpoints or anything else on that local server? Like if you do a curl command to the server does it respond or also give a 404?
curl -X POST https://localhost:3000/create-checkout-session
I am really unable to understand about the client side code you are saying. If you don't mind please give a example.
As far the docs the server side code is this and I too have contructed my code in a similar way if you look a little up
const YOUR_DOMAIN = 'http://localhost:4242';
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: 'price_1MKEdySJaJ2t0SuD5HMcFQ3n',
quantity: 1,
},
],
mode: 'payment',
success_url: ${YOUR_DOMAIN}?success=true,
cancel_url: ${YOUR_DOMAIN}?canceled=true,
});
res.redirect(303, session.url);
});
app.listen(4242, () => console.log('Running on port 4242'));
So basically, the code in your browser is running in to an issue when it runs this code, correct?
products,
successUrl: 'http://localhost:4242/success',
cancelUrl: 'http://localhost:4242/cancel',
total
});```
Absolutely sir that's the issue
So a 404 means that the webpage cannot resolve that http://localhost:4242/create-checkout-session URL. So it sounds like either your local server is not running or there is some connectivity issue with it
If you restart the server that is at 4242 and then try to reach out to it with a cURL command, does it also get a 404?
curl -X POST https://localhost:3000/create-checkout-session
Okay thank you so much at least for explaining. I will try this and get back to you.
It's showing this
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number
Oh whoops I meant to paste that for the 4242 server. Do you get the same thing there?
curl -X POST https://localhost:4242/create-checkout-session
Yes same error 😫
I checked out, It's probably for SSL/TLS connection between the client and the server. Any idea how to solve this?
Checking in to how to debug this. It sounds like it may be your curl or the command more than the server. Will get back with another way to look at this
Okay. Thank you so much!
If you just try going to http://localhost:4242/create-checkout-session in a browser does it show anything?
If the server is running it will error with "Cannot GET /create-checkout-session" but that error at least confirms it is running and findable
This is what is shows
Even I added cors also in the server code
var cors = require('cors');
app.use(cors());
But nothing new 🙃
Gotcha. Thanks for trying that. So at least it is up and running, trying to think of how to debug the disconnect between your client and server here
Same trying to debug.
const express = require('express');
var cors = require('cors');
const stripe = require('stripe')('SECRET_KEY');
const app = express();
app.use(cors());
app.use(express.static('public'));
app.post('/create-checkout-session', async (req, res) => {
const { products, total } = req.body;
// Create the Checkout Session on the server
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: products,
success_url: "http://localhost:3000/success",
cancel_url: "http://localhost:3000/cancel",
amount_total: total * 100 // Convert total price to cents
});
res.send({ sessionId: session.id });
});
app.listen(4242, () => console.log("Node server listening on port 4242!"));
Can you check if any parameters are missing or not ?
products I am fetching from handleCheckout function from frontend
Hello 👋
Taking over and catching up on the context..
can you add following to your server-side code make sure that the server isn't buggy
res.send('hello world')
})```
Hey, Sure
and try loading http://localhost:4200 in your browser
Sure, let me try
also can you try adding following to your package.json ?
"proxy": "http://localhost:4242",
This came
Gotcha so the server is working..
on the server folder package.json right ?
yup
Okay sure
ah sorry, it needs to go to your react app's package.json I think
Ohh, Okay will do so.
Added
Now giving error 500
in react it's giving this while compiling
ah its the wrong port
It should be
"proxy": "http://localhost:4200"
4200 and not 4242
I changed to 4242 for everything
Hey, now I saw in server this error is coming
app.post('/create-checkout-session', async (req, res) => {
const { products, total } = req.body;
// Create the Checkout Session on the server
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: products,
success_url: "http://localhost:3000/success",
cancel_url: "http://localhost:3000/cancel",
amount_total: total * 100 // Convert total price to cents
});
res.send({ sessionId: session.id });
});
It's from this code
AH nice, that's the 500
Yes atlast we know what is the issue.
Can you try setting a static array instead of sending products to see if the code works?
also it looks like you're trying to set amount_total which isn't really a parameter you can set on creation
did that work? @gentle girder
for inline pricing, you'd want to use price_data parameter
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Okay let's try with that
No, it should be as following
line_items: [
{
price_data: {
currency: 'usd',
unit_amount: 1000
}
},
],```
{
price_data: {
currency: 'usd',
unit_amount: 1000,
product_data: {
name: 'Product name'
}
}
},
quantity: 2
],```
There's an example here
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#redirect-customers
Glad we could help 🙂 🎉
Now just help me with the products to get here
It was showing couldn't destructure or atleast tell where I am going wrong I will check that. Anyway thankyou so much!
NP! 🙂 You would want to make sure that the products array match the structure that line_items expect
Good luck
Okay thank you. Really glad of this support! ❤️
😄 👍
One last question. What to keep this while deploying the app.