#Arghya Das
1 messages ยท Page 1 of 1 (latest)
Hi!
are you an official?
where are the other channels there is a new thread opened on my name
Yes, I work at Stripe.
What message are you referring to?
I am using checkout. session.create method
this messages I am talking with you
I am pointing the success url and cancel url
but based on the success I want to return something so frontend can know that payment is successful then I can call another endpoint to update something
but If that was cancel I do nothing
I am using react and node can you help me with that?
๐ hello?
Yes, let me check.
The success URL will have query parameters attached to it, based on it you can check the status.
However, you should not use it for business logic, please use webhooks instead: https://stripe.com/docs/webhooks
I can use webhooks with test key?
and if I want to change the font and look of the page
the session url gives me how to do that?
Can you give me a short snippet I just started it show I don't know about ut
I just created that checkout.session.create with item id price and quantity
with success_url and cancel_url
based on success I want to call another api to update something this is what I want
Yes
I am not sure what is your goal.
Do you want to display a success message to the customer?
Or do you want to perform business logic based on successful payment?
so after the payment success I want to call another api in my backend to update some tokens I am giving each users
so they are actually buying tokens so after successful payment I want to add that token I have that logic build
But as I am not checking if the payment is successful or cancel, each situation it is adding the tokens in users
so I need to make that check before updating
In this case, you need to use webhooks, you can listen to payment_intent.succeeded or checkout.session.completed events.
what will be the code can you help me with that?
And answer of this will be helpfu
Please refer to the docs I shared, there are code examples: https://stripe.com/docs/webhooks
This one is also helpful: https://stripe.com/docs/webhooks/quickstart
Sorry for delay
For that you can use the success URL query parameters.
css style question
Or are you referring to something else?
then I don't need the webhooks right?
Yea I mean the checkout form stripe is giving me with the checkout.session.create is basic and if I can change it's font that what I asking
You need webhooks for giving tokens to customers.
For displaying the success message you can use the URL query parameters.
if I am understanding correctly
i did a payment
I get a success responze
I update my token in my database whichever I am using
correct?
Yes
then but do I need to install cli for local
or I can create a endpoint using my local adress
Please follow the docs I sent you, everything is explained there.
hey delete all test data is not working
its showing the loading sign but after processing all data are there
Delete all test data? In the Dashboard?
I delete it but the api usage and logs are still showing
We don't really know much about the Dashboard here, so if you need help with that: https://support.stripe.com/contact
Otherwise, what's the issue with webhooks I can help with?
actually let me explain my problem
I have some user in my mongodb
and I am giving them some free token
now after a time they have to buy the token and when they buy the token I will call an api in my backend to update the token value in the mongodb of that user
but I am using checkout.session.create method
so I am having a hard time to know if payment was successful or cancelled in that api call
because now if I cancel the payment it is still updatng the tokens in mongodb
if you want to know about the code you can ask for it
Ok, and what particular issues are you having using webhooks?
This fulfilment flow with Checkout is detailed here: https://stripe.com/docs/payments/checkout/fulfill-orders
let me read that then I can tell you
do i need to install stripe cli or I can start in node and react
I am using this code now I also have to send a success or cancel message
at least success
Well, you'd use the CLI to forward test events from your account to your endpoint in your development environment
- Setup your local endpoint at
localhost:3000/stripe(or similar). - Use the CLI to 'listen' to events on your account and send them to your endpoint:
stripe listen --forward-to=localhost:3000/stripe - Create a Checkout Session and complete it as you normally would.
- The
checkout.session.completedevent will be forwarded to your local endpoint.
but how to forward that in frontend
I'm not sure what you mean
I think I couldn't explain the problem
๐
I need to send that payment success or cancelled response in the frontend so I can do some action based on that
Generally that's not possible. I guess your front-end could read from the same database that your webhook posts data to?
yea that's what I understood
let me explain
Or alternatively you can utilise the success_url: https://stripe.com/docs/payments/checkout/custom-success-page
But we don't recommend that for any business critical logic
you see this part
I want to only do this task if the payment was successful
for now it doesnt matter if I cancel or my payment was succesful it just updates the tokens
Then you should do that in your webhook that handles checkout.session.completed events
but how to send that response in here so I can perform task based on that
if you can create me some snippets
I just started so I got confused
sorry
you got the idea what I am trying to do right?
Do you understand why your issue is happening?
Your handleClick function creates both the Checkout Session and then handles your custom logic to update tokens.
okay
The issue being is it doesn't care whether the subsequent payment succeeded or failed, only that the API request to create the session succeeded.
So you need to split up that function, and use the webhook flow I outlined to handle the token logic.
That way it'll only trigger when you receive checkout.session.completed events (i.e. when the payment succeeds).
so I need to create another endpoint right?
Did you follow the steps I outlined here?
yes I am trying to install cli
but defender is blocking that exe
can I do that from web shell?
I mean on the website there is stripe shell right
I'm not sure if that supports listen like you'd need. Maybe it'll work if you open up your localhost to an external URL (via ngrok or something)
It should be the port your webhook server/endpoint is running on. 3000 is the Node.js default.
this should be the server port or client
cause my both are differnet
so should I give the server port or the client port?
?
Hi! I'm taking over this thread.
ok
Could you try to summarize your question?
so I was using checkout.create.session to do the payment
and I want to return back a response if the payment was successful or not or canceled
then based on that on the frontend I will perform some action
am using react and node
I really need this so any help will be appreciated
you can check the code
I want to return back a response
What do you mean by that? Webhook events?
that I don't know I am new
so I want assistant with that
what will be the best way to do that
if you check this code
This code is creating a Checkout Session. Does it work?
yes
but if you see this
here
I am updating the token they are buying in my user mongodb
And you want to know when the payment is successful and then run some specific code?
now for now it doesnt matter if payment is sucessful or canceled
it updates the token
which is not correct
yes not when if the payment succesful
then i will update the new credits or token in my mongodb
before doing this I need to check that if my payment is successful
if it is not or canceled I will do nothing
If you want to update your database when a payment is successful, you should do that with a webhook event. You can learn more about this here: https://stripe.com/docs/payments/checkout/fulfill-orders
database in mongodb
thats what I am trying
I have created this
now I have seen some tutorial but couldn't understand
To build your own webhook event handler, I would recommend to follow this guide: https://stripe.com/docs/webhooks/quickstart
And if you have specific questions, I'm happy to help!
let me try
this?
or that?
and should i use server port or client
Both cover the same thing, but I guess https://stripe.com/docs/webhooks/quickstart will give you more detailed explanations
hey I hve locally tested
but how to send the response bac
back
when I paid it got that success
Hello ๐
Stepping in as soma had to step away
Send the response back to what exactly? Stripe only expects a 200 as an acknowledgement that you've received the event. No other response is expected
frontend
in react
so I can get the success object in payload
then I can perform some task
so after I paid I need to send some success message to the frontend
only then if payment is successful I can perform some task
Your app would need to call your backend APIs to retrieve these OR you can retrieve PaymentIntent information client-side to check its status
If you're using Checkout, we have a doc here which might help
https://stripe.com/docs/payments/checkout/custom-success-page
why should I go to the custom page
how to check its status
I am using checkout
If I dont know if the money is paid I cant increate his or her token
so I need to know the payment status if its succeed only then I will do it
why should I go to the custom page
Not sure what you mean by that. When the checkout session succeeds, your users will be redirected to the success page URL. Passing the Checkout Session ID as a query parameter will give you access to the ID on your success page which you can use to call the API and check its status as shown in step 2
The docs retrieve the checkout session object. You'll need to access session.status to see it
is this the correct way
Yes, try it out..
do i need to pass the session_id in body?
Yes, it won't know which session to fetch without it
nope man
not for me
๐
I cant get the session id from the success_url
๐
see if you can help me with the code
๐ญ
Sorry I can't fix/write your code for you ๐ฆ
Where exactly are you passing the sessionID to your API ?
here
That's for the creation though, you're trying to fetch the status after completion right?
this code
that code won't work after you do window.location.href = url;
You need to run that code on success page URL instead
I would recommend looking at this video, it uses HTML example but the idea should be the same for react app
https://www.youtube.com/watch?v=UjcSWxPNo18
thanks