#Bryce Tolle

1 messages ยท Page 1 of 1 (latest)

ivory groveBOT
hard mesa
#

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?

deep oar
#

Hi bismarck ! I believe so, i have app.listen(3000) in my server.js file and am using localhost:3000/ to find my

#

pages

hard mesa
#

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

deep oar
#

okay ! this testing appears in my visual studio code terminal but not in my console on the webpage

hard mesa
#

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?

deep oar
#

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

hard mesa
#

Can you show me that code?

deep oar
#

definitely, how would you suggest i do so?

hard mesa
#

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

deep oar
#

inside or outside the try{ ?

#

oh above the post?

hard mesa
#

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

deep oar
#

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

glad dagger
#

๐Ÿ‘‹ I'm hopping in since bismarck has to head out

deep oar
#

Hi karbi! Sounds good thanks so much for helping me

glad dagger
#

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

deep oar
#

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

glad dagger
#

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?

deep oar
#

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

glad dagger
#

What is map? What do you get when you log that?

deep oar
#

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

glad dagger
#

And where is map coming from? How is it being created?

deep oar
#

map is being created inside my ScriptMain.js, right above my fetch("/create checkout session"

glad dagger
#

Instead of creating a map, why aren't you just creating the items array directly in your for loop?

deep oar
#

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

glad dagger
#

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

deep oar
#

gotcha I did not know that. I am getting items2.append is not a function error now

#

I am so appreciative of your help.

glad dagger
#

You're getting that error because append is not an Array method

#

You need to use push

deep oar
#

gotcha. Thanks! now my items2 is being logged correctly, but when i log (req.body.items2 i am getting :

#

[ 'id: 4, quantity: 1' ]

glad dagger
#

Why are you constructing a string and adding that to your array?

deep oar
#

I changed that to just items2.push( itemId, itemQ )

#

Sorry i am just learning javascript

glad dagger
#

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

deep oar
#

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 dagger
#

๐Ÿ‘ Glad we were able to sort out that map confusion

deep oar
#

same!! that was incredibly helpful. Thank you so much.