#Bryce Tolle
1 messages ยท Page 1 of 1 (latest)
Hi there
So the initial 500 error indicates that you aren't able to hit your server at that endpoint
Are you running your server at port 3000?
Hi bismarck ! I believe so, i have app.listen(3000) in my server.js file and am using localhost:3000/ to find my
pages
Okay so the first thing to do is to add a log at the top of your endpoint in your server
So before your try/catch
Add something simple like console.log("testing")
Then run a test and see if that log shows up in your server logs
okay ! this testing appears in my visual studio code terminal but not in my console on the webpage
Okay then you are hitting your server successfully
So you are actually returning that 500 from your server in that case
Likely due to your try/catch
So then that can't read properties of undefined is likely relevant as well at this point
Where are you initializing your price variable?
inside the storeItems Map on the top of the image of the server
i am setting it to the price hash (i believe) from the products i created on stripes website
Can you show me that code?
Ah yeah okay so the issue is just as you noted
It is trying to look for storeItem.price but storeItem is undefined
So it is erroring
So up above your Checkout Session creation request you want to log out storeItem
Just above the stripe.checkout.session.create request
You want to know what that variable is before you run the code for that request where it is erroring
You can do it within the try or outside
Doesn't really matter in this case since it is just a log
sorry I am a little confused. Should I log storeItems ? the storeItem is being defined 2 lines up in the const storeItem = storeItems.get line
๐ I'm hopping in since bismarck has to head out
Hi karbi! Sounds good thanks so much for helping me
So I'd actually recommend logging req.body.items before you create the Checkout Session - and also, I'd recommend checking your logs (https://dashboard.stripe.com/test/logs) to see if the Checkout Session request is even being made
gotchu so my req.body.items only printed : [ {} ]
and then my last log on the website given was an hour ago so I'm assuming that was the last time I ran it with the commented out sections that gave me the static checkoutpage
maybe for better name than static checkoutpage, the page with the items not correlating to the items inside the cart
If req.body.items is empty then something is wrong with your client-side request to your server - are you sure you're sending the items from your frontend to your backend correctly?
I am not sure. I was thinking putting the map into body: JSON.stringify({
items: [
//NOT WORKING
map,
/* BELOW WORKS BUT DOESN'T ADJUST BASED OFF ITEMS THAT ARE IN CART from ('checkoutrow')
{ id: 1, quantity: 1 },
{ id: 2, quantity: 2 },
{ id: 3, quantity: 3 },*/
],
}),
would do the trick
What is map? What do you get when you log that?
map is defined in my scriptMain.js and prints
Map(2) {'1' => '1', '2' => '2'}
when there is product 1 with quantity 1 and product 2 with quantity 2 in my cart when i click checkout
And where is map coming from? How is it being created?
map is being created inside my ScriptMain.js, right above my fetch("/create checkout session"
Instead of creating a map, why aren't you just creating the items array directly in your for loop?
I just had thought it would be easier to create a map and give it to items i guess, I just failed an attempt of creating an array directly in the for loop
Yeah using a map is unnecessary and makes it more complicated - it also explains why you're getting empty, since JSON.stringify doesn't work with maps
gotcha I did not know that. I am getting items2.append is not a function error now
I am so appreciative of your help.
You're getting that error because append is not an Array method
You need to use push
gotcha. Thanks! now my items2 is being logged correctly, but when i log (req.body.items2 i am getting :
[ 'id: 4, quantity: 1' ]
Why are you constructing a string and adding that to your array?
I changed that to just items2.push( itemId, itemQ )
Sorry i am just learning javascript
You need to do items2.push ({id: itemId, quantity: itemQ})
and if this is going to be a live site, I really would recommend you hire someone to help you with this - payments are really important to get right and there's a lot of things to consider for these integrations
my goal was to create this to add on to my resume to help me find an entry-level web developer position
I definitely have some more learning to do though. I appreciate your help. Now i am working on going through the req.body.items2 and adding that to the line_items: section inside the server
๐ Glad we were able to sort out that map confusion
same!! that was incredibly helpful. Thank you so much.