#furkanayilmaz-checkout
1 messages ยท Page 1 of 1 (latest)
So if there is a product that is $39.99 and you click it gives you a link and you go back and choose a different product the price and url doesn't change and when you click on the link that it returns for the new product the price stays at $39.99
I assume your integration is creating a new Checkout Session each time the user cilcks on a product, right?
Yeah
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
mode: "payment",
line_items: [
{
price_data: {
currency: "usd",
product_data: {
name: "Ride Request",
},
unit_amount: convertedPrice,
},
quantity: 1,
},
],
mode: 'payment',
success_url: http://localhost:3000/success,
cancel_url: http://localhost:3000,
}).then((response) => {
// console.log(response.url)
app.post("/payment", (req, res) => {
console.log(currentOption, convertedPrice)
res.send(response.url)
//console.log(response.url);
})
}).catch((err) => {
console.log(err)
})
This is the code
That does the checkout
Do you have examples of the request IDs made to create these Checkout Sessions?
What do you mean by request IDs
Or where can I find it
If you go to the dashboard you should be able to see your recent requests - https://dashboard.stripe.com/test/logs
Here is one of the request ID
req_A1XeUox67njb94
So when I generate a link for 30 dollar item the link generates and the item price is 30 and when I go back and click on a different the link is same as the item that was $30 and the price is also same
I can also send the full code for the server that generates the link
Looking at the two most recent requests on your account I see that you created one Checkout Session with a unit_amount of 9100 and another with 3300. When you click on the next price, are you being directed to the same checkout link or a different one?
Same checkout Link
What exactly is your code doing? Are you making sure to make a request to your backend to create a new Checkout Session each time a product is clicked?
Yes!
So when you choose a new product it goes to the Checkout Session and creates a new session
And are you making sure that the you are redirecting the correct checkout session URL? It should be generating a new URL if a new CHeckout Session is being created
Yeah I am sure I am redirecting to the correct url
This is the code
The code that should be generating the link is in the server file and called server.js and there is another file in components file
That is rideselector
That is the code that contacts with the server and create the link
Why is your Checkout Session creation request then making another request to "/payment"? Why aren't you juse sending back the Checkout session URL right there?
Your code seems to be using a framework I'm not super familiar with, but I'm guessing the issue lies with your "/payment" endpoint sending back the wrong Checkout session URL
The code is using a Next.Js but most of it is just normal react code
In the .then block I am returning the url
๐ Hi I was just lurking in this thread to do some reviewing but I think I see something that might be causing a problem.
Really ? What is the problem.
The URL to the checkout session is being returned in the session object on line 59 of server.js
Yeah
In order to access the Checkout URL I think you can redirect your users to the session.url parameter
But doesnโt the promise return a result already
I would start by inspecting the flow and making sure each of the objects is what you expect it to be.
All the data is being being forwarded to server correctly. I did do console.log to check every data
I just don't think the URL being returned in the .then block is the session URL. I would try skipping the .then() block altogether and just redirect to session.url
What is getting written into session currently appears to be modified by the then() block.
I see! Because much as I know promise returns the result but I will make sure Iโll give it a try for session.url
Well you await1 the promise so you should just get the data object back.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Let me take a look.
Here's the docs on the session, just as a handy reference
So there is a chance that .then block modifying the url
I would just suggest commenting out the then() block and redirecting the flow to the session.url property. I think that should work ๐ค
Cool! Let me give that a try
@mighty nimbus Thank you so much. It worked. I can't thank you enough.
Now the url chances and as well as the price
You solved the problem in 10 minutes and I have been trying to solve this the past days
Awesome! Happy to Help ๐
Hey @mighty nimbus
So I came across another problem and that is weird
So when I console.log(session.url) I get the right url for every product but when I forward it to the frontend I still have the same problem where the price stays the same
Have a look at this video
This is my screen recording showing the issue
In the server the url is right but when being forwarded to frontend the url doesn't work properly
Hi there,
Hi
Please allow to step in to help and follow up with your question
I was looking at your frontend code, I was wondering what paymentURL() does? https://github.com/furkanayilmaz/Uber-Updated/blob/master/pages/components/RideSelector.js#L38
And where is this defined?
paymentURL() is the function that gets the url from the backend
and being called inside of the ConfirmButtonContainer
in the return statement
@maiden fulcrum Did you see the video I posted.
the one in the google drive
Hi @sacred prism so basically opening the checkout URL that you received from Stripe shows the product with the correct price. am I right?
Yes, when I open the link that server is returning it shows the correct item price. If you taked a look at the video you can understand the situation better
It shows the correct product with the correct price when I opened the link that server returns but when I open the link when I forward it to the frontend it shows the wrong price
Can you check your code and see if the url variable is cached?
Which code or section is that
I think you are more familiar with your code than me.
I just checked and yes the variable is being cached
Sorry for the late respond
Had some issues with my pc
No problem. I guess the issue is resovled? ๐
Yeah and I was able to check and see if the url variable is cached
Nice, happy to hear that