#Suyype
1 messages · Page 1 of 1 (latest)
Hi, can you share more details here? Step by step details on what you're doing would be helpful
How are you integrating with Stripe? What documentation are you using?
Im using https://stripe.com/docs/js/elements_object/create, as docs and im just importing it to my addtobutton.js component in nextjs. I can send you the file if needed, I dont know much about the API and such.
Please don't send a file. So what is the exact issue? Can you share step by step details here so we can debug this together?
I really dont know but it just seems to be that its outputting this error
'Cannot read properties of undefined (reading 'retrieve')' at one of my parts of code
You should start logging in your code and seeing exact where this error is thrown. This error typically means that you have a variable that is undefined. Can you start there?
it seems that const price = await stripe.prices.retrieve(priceId); is where the error is occuring in my cart.js file
My code is in javascript, the framework is Next.Js
What are you using on your server side code?
as in server side code, I am using the normal Stripe.js API
It looks like your code to retrieve the price is correct:
const price = await stripe.prices.retrieve
Can you explicitly pass the price id on your retrieve instead of passing priceId?
how could I achieve that?
Were in your code do you have this variable priceId?
Find that and pass that id explicitly in your code above.
I have a priceId that gets passed from this tag in a index.js page <AddToCartButton priceId={'price_1MmQ7QH0DaIfyf0YMDy17QTo'} />
Ok, can you pass the price_ here? Your code will look something like this:
const price = await stripe.prices.retrieve( 'price_1MmQ7QH0DaIfyf0YMDy17QTo' );
well, the thing is, I have a component of a add to cart button because it needs to get repeated for different items that are added to cart, I cant have a price like that because that is just one constant price that will apply to all addtocart buttons.
I know but we're just trying to debug what the issue might be... if this works, then we know with 100% certainty where the issue lies
Also, this should be in your server side code.
what do you mean as server-side?
You need to retrieve the price from your server-side code, https://stripe.com/docs/api/prices/retrieve?lang=node using your secret API key: https://stripe.com/docs/keys
ok, now it is returning the name and image and price, but in my mongoDB it is returning the priceId as null
and I think thats because we took out the priceId out of the button
Yeah, I'd keep debugging this on your code..
It just seems weird...
How do you mean?
idk, its just weird, but coding in general is weird 🤣
I fixed it, but now Im trying to show the image part for this link "https://files.stripe.com/links/MDB8YWNjdF8xTDhzUFJIMERhSWZ5ZjBZfGZsX3Rlc3RfVUtoZ0VZUjJsZkJuemVCbEozR2xaR09w00cIM9Zm5X" but that link just leads me to a download link so how could I pull the direct image link?
Hi @fierce hawk I'm talking over, give me a sec to catch up
ok, thanks.
Is you question about how to display a image in <AddToCartButton /> component?
actually, I kinda moved on from that, its now a how to display a image in this function CartList({ items }) { // component to display items in the cart return ( <div> {items.map((item) => ( <div key={item._id}> <p>Name: {item.name}</p> <p>Price: {item.price}$</p> <Image src={item.image} alt={item.name} /> </div> ))} </div> ); } and that connects to my mongoDB but I get the image, name, and price from the priceId it shows, it shows the price and name, but not the link since that link sends me to a download the image page.
What do you by link ? I don't see a <Link> in the code that you provided earlier/
no, my bad for not specifing, I mean as in this link https://files.stripe.com/links/MDB8YWNjdF8xTDhzUFJIMERhSWZ5ZjBZfGZsX3Rlc3RfVUtoZ0VZUjJsZkJuemVCbEozR2xaR09w00cIM9Zm5X and that link shows in my database from my priceId but if you click it, it will just download the image.
I present it in here function CartList({ items }) { // component to display items in the cart return ( <div> {items.map((item) => ( <div key={item._id}> <p>Name: {item.name}</p> <p>Price: {item.price}$</p> <Image src={item.image} alt={item.name} /> </div> ))} </div> ); } and its the ```<Image src={item.image} alt={item.name} />
Is this <Image> component a custom component you own?
nope, just one that I imported from import Image from "next/image"
You might want to check with the developer who created this component and ask how it renders a image.
but even if I try the <img> tag it looks the same.