#Max4637-checkout
1 messages · Page 1 of 1 (latest)
looks like your backend server is returning a 404!
i.e, the 'server' tab at https://docs.ngx-stripe.dev/core-concepts/checkout , you need a backend for this.
I have a server.JS class which looks like this ``` // This example sets up an endpoint using the Express framework.
// Watch this video to get started: https://youtu.be/rPR2aJ6XnAc.
const express = require('express');
const app = express();
const stripe = require('stripe')('your secret key');
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'T-shirt',
},
unit_amount: 2000,
},
quantity: 1,
},
],
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
res.json({ id: session.id });
});
app.listen(4242, () => console.log(Listening on port ${4242}!)); ```
Sorry. I replaced the 4242 with 4200, because I had it to make it match my localhost:4200/
I will also modify line items soon, but I want to make sure this works first
I replaced the 4242 with 4200, because I had it to make it match my localhost:4200/
you mean you changed that on the frontend?
No, the server.JS class
because the backend still uses port 4242 (app.listen(4242) so naturally you'd get an error like that if you don't also change the backend to match
ok. And your server is running?
How do I check if the server is running again?
When I do “node server.JS” it says it listens to the port
if you open a terminal window and do curl -d '{}' http://localhost:4200/create-checkout-session what happens
what changed between when you got "connection refused" and then got the HTML response?
i.e. what did you do differently or other command did you run somewhere else
Ignore connection refused because I forgot to run the localhost on the first command
yep that is what I want to dig into really. So in some other window, you have the server running right now?
The second command I opened a different terminal and ran “ng serve”
Doesn't that only run the frontend server?
I don't know anything about Angular(that plugin you use is not something we officially support)
what you said earlier about node server.js would make more sense
Yes, but I use a 2nd terminal window to run the command you told me
so maybe try changing that server.js file , and the frontend part that makes the request, back to port 4242 like in our example, then go and run node server.js now and then try again
Ok. I’ll do that
like it sounds to me like you're not running the backend Node server that actually hosts that server file, ng serve is just about serving the static Angular files, it's all frontend
AFAIK you'd have two servers, one is the dev server for serving the angular assets, the other is the backend server hosting the backend code to talk to Stripe's API