#King Rom II-checkout

1 messages · Page 1 of 1 (latest)

charred hollow
#

👋 Happy to help

#

Which line does the error throw?

snow chasm
#

Hey thanks,

const app = require("express")(); must be coming from here.
If I comment it out along with the post request the error disappears.
I have stripe/express dependencies installed

charred hollow
#

If you comment out this line, it's unlikely the app can even run since it's an initialisation of the express app

#

which line did you comment out?

snow chasm
#

Yes, but the problem lies in app = require(express), and the post request that's what I ment. If I run the script I get the error as stated above

snow chasm
# charred hollow which line did you comment out?

To find the error in the file, I uncommented the initialisation variable 'app' and the post request, for the error to appear. It's not the stripe import or any other function that's causing the issue.

#

I'm using the right syntax right? This would be an old way of doing it

charred hollow
#

Can you try?

const app = express();
snow chasm
#

I'll be home in an hour, I will

snow chasm
#

I've tried it without result. I'm a bit clueless at this point

spare pecan
#

you're running that code on the frontend in your browser

#

which is wrong, that is backend code for Node , you need to run an actual Node server, it's Javasccript but it's not frontend Javascript you run in a HTML page in a browser.

snow chasm
#

Oh I see

#

I do have a server running though

#

How would I get rid of this error in my console?

spare pecan
#

the chrome console?

snow chasm
#

Yes

spare pecan
#

why is chrome running server.js?

snow chasm
#

I have server.js linked to my html. What am I missing here?

spare pecan
#

I have server.js linked to my html
like you have <script src=/server.js">?

snow chasm
#

Exactly

spare pecan
#

I'm sorry but that really is completely wrong

snow chasm
#

oh typo

#

Yes?

#

I'm sorry, I'm new to backend. Trying my hardest to make it work

spare pecan
#

that's not how this works. You'd have a Node server running on the backend. Your frontend doesn't include those scripts. Your frontend makes HTTP requests(like fetch ) to contact the server running the backend scripts.

snow chasm
#

Oh right that makes alot of sence. So server.js should not be linked in the html but rather be a path that I configure?

spare pecan
snow chasm
#

Slightly confused over here hehe

spare pecan
#

You have a sever that runs somewhere. Doesn't have to be using Node, could be using PHP or anything. That's your backend. It exposes a HTTP route, so you have a URL like https://mywebsite/backendserver/get-payment-intent or http://localhost:4242/create-payment-intent.

You have a frontend webpage running Javascript. That page makes a HTTP request(that's what things like XMLHttpRequest or jQuery's $.post() or the fetch code in HTML5 are for) to that backend server's URL.

#

I'd suggest taking a step back and just looking into creating a simple web app using Express that lets you have a server running that just returns anything, and access that from a frontend page. Then you can look into integrating payments when you're comfortable with the concepts

snow chasm
#

Okay great thanks!

So my backend would be http://localhost:4242/ since I'm running a node server correct?
I do agree that I'm reaching out of my technical scope here, but that's the whole point.
I have a firebase backend where I want to store user credentials after payment.

The payment part is working, I can 'stripe listen' to output in my terminal, and orders appear in my dashboard. I'm new to the whole node part though.
Figured I run a server with node(mon) and that's that.
But I need to use the host it's providing me correct.
I'll take a crashcourse on node to try and understand the concept a bit better.

spare pecan
#

So my backend would be http://localhost:4242/ since I'm running a node server correct?
it would seem to be yes
I have a firebase backend where I want to store user credentials after payment.
Not to tempt fate, but then why isn't all your backend on Firebase? You'd generally have Firebase hosting your backend, like a function that creates a PaymentIntent or Stripe CheckoutSession, that your frontend calls, and then a different function that accepts webhooks after payments.

Like to actually use this in production on a real web page, you have to host the Node server on a public server somewhere, so I would have imagined you'd do it all on Firebase.

The payment part is working, I can 'stripe listen' to output in my terminal, and orders appear in my dashboard. I'm new to the whole node part though
how do you actually create the payments?

snow chasm
# spare pecan > So my backend would be http://localhost:4242/ since I'm running a node server...

Yeah I've looked into firebase functions, but in order to enable it I have to upgrade my plan. To do that I need a CC, which I do not have.

Okay so I can get rid of the whole node server, try to host my functionality through cloud functions and work from there?

you have to host the Node server on a public server
Snap okay I thought the node server was only for development.

I've only been building front end code so it's all foreign to me. I'm sorry that I'm having you teach me the fundamentals while we're in a stripe help server.

how do you actually create the payments?

I created a button on my page, with the code from img. Works all fine, processes payment etc. That's why I thought I had 80% of the work covered, the next part was to update my firebase database through a webhook.

spare pecan
#

well I can't advise you on the hosting part since that's really for you as a business(you do need a public server somewhere when you're ready to take real payments from your real site, that will cost money)

#

Snap okay I thought the node server was only for development.
no. Like, you're not just building the code as some temporary thing, what you're building is your actual website and payment integration. Before you go live you can host it on a simple local server on your laptop, but then later you deploy that to some server somewhere

#

I created a button on my page, with the code from img. Works all fine, processes payment etc.
yeah ok you're using the client-only Checkout integration, fair enough. So all you need is the webhook part. Which then yes, is a backend server. Unfortunately you're likely quite lost here and I'm not really sure how to untangle it for you. The frontend code would have no connection to the webhook.

The webhook is something Stripe sends you independently. i.e. you have that frontend code and it redirects to Checkout and the customer pays, and is returned back to your successUrl . That's all fine. Separately, Stripe's server sends a webhook. You'd need some server running somewhere to process that webhook. That can be a Node server you run locally and then use stripe listen --forward-to=localhost:4242 to test sending webhooks to, and then later you host that Node script on a server (like a DigitialOcean droplet or Heroku or indeed a firebase function) for production use.

#

in the backend code you posted you have some Node script receiving a webhook and then making a fetch to a firebase function which doesn't make a lot of sense to me, I'd just have the URL of the firebase function set up as the URL for the Stripe webhook, directly.

snow chasm
#

Okay thank you so much!
I clearly understand that my whole workflow/setup is wrong.

I will restructure things and start over.
Thanks alot for the thorough explaination, it's the type of information I was looking for