#Arghya Das

1 messages ยท Page 1 of 1 (latest)

umbral compassBOT
cerulean mortar
#

Hi!

lament imp
#

are you an official?

#

where are the other channels there is a new thread opened on my name

cerulean mortar
#

Yes, I work at Stripe.

lament imp
#

And anybody can see my messge

#

whatever

cerulean mortar
#

What message are you referring to?

lament imp
#

I am using checkout. session.create method

lament imp
lament imp
#

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?

cerulean mortar
#

Yes, let me check.

lament imp
#

actually this is my time using discord support

#

this is fantastic system ๐Ÿ‘๐Ÿผ

cerulean mortar
#

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

lament imp
#

I can use webhooks with test key?

lament imp
#

the session url gives me how to do that?

lament imp
#

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

cerulean mortar
cerulean mortar
lament imp
#

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

cerulean mortar
#

In this case, you need to use webhooks, you can listen to payment_intent.succeeded or checkout.session.completed events.

lament imp
#

what will be the code can you help me with that?

lament imp
cerulean mortar
lament imp
#

yes I am reading that thanks

#

that css style question see if you can help me

cerulean mortar
#

Sorry for delay

#

For that you can use the success URL query parameters.

#

css style question
Or are you referring to something else?

lament imp
lament imp
cerulean mortar
#

You need webhooks for giving tokens to customers.
For displaying the success message you can use the URL query parameters.

lament imp
#

i did a payment

#

I get a success responze

#

I update my token in my database whichever I am using

#

correct?

cerulean mortar
#

Yes

lament imp
#

then but do I need to install cli for local

#

or I can create a endpoint using my local adress

cerulean mortar
#

Please follow the docs I sent you, everything is explained there.

lament imp
#

hey delete all test data is not working

#

its showing the loading sign but after processing all data are there

safe valley
#

Delete all test data? In the Dashboard?

lament imp
#

yes

#

and also I am not understanding the webhooks ๐Ÿ˜ฅ

lament imp
safe valley
#

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?

lament imp
#

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

safe valley
#

Ok, and what particular issues are you having using webhooks?

lament imp
#

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

safe valley
#

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.completed event will be forwarded to your local endpoint.
lament imp
#

but how to forward that in frontend

safe valley
#

I'm not sure what you mean

lament imp
#

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

safe valley
#

Generally that's not possible. I guess your front-end could read from the same database that your webhook posts data to?

lament imp
#

let me explain

safe valley
#

But we don't recommend that for any business critical logic

lament imp
#

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

safe valley
#

Then you should do that in your webhook that handles checkout.session.completed events

lament imp
#

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?

safe valley
#

Do you understand why your issue is happening?

lament imp
#

no

#

I am all ears

safe valley
#

Your handleClick function creates both the Checkout Session and then handles your custom logic to update tokens.

lament imp
#

okay

safe valley
#

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.

lament imp
#

yes

#

so I need to add another endpoint to check the success

safe valley
#

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).

lament imp
#

so I need to create another endpoint right?

safe valley
lament imp
#

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

safe valley
#

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.

lament imp
#

ok ok

#

I will get back to you

#

microsoft defender blocking the exe

lament imp
#

cause my both are differnet

#

so should I give the server port or the client port?

#

?

trail orbit
#

Hi! I'm taking over this thread.

lament imp
#

ok

trail orbit
#

Could you try to summarize your question?

lament imp
#

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

trail orbit
#

I want to return back a response
What do you mean by that? Webhook events?

lament imp
#

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

trail orbit
#

This code is creating a Checkout Session. Does it work?

lament imp
#

yes

#

the payment is working also cancellation

trail orbit
#

So you redirect users to the Checkout Session and their are able to pay?

#

Perfect.

lament imp
#

yes

lament imp
#

here

#

I am updating the token they are buying in my user mongodb

trail orbit
#

And you want to know when the payment is successful and then run some specific code?

lament imp
#

now for now it doesnt matter if payment is sucessful or canceled

#

it updates the token

#

which is not correct

lament imp
#

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

trail orbit
lament imp
#

thats what I am trying

#

I have created this

#

now I have seen some tutorial but couldn't understand

trail orbit
#

And if you have specific questions, I'm happy to help!

lament imp
#

let me try

lament imp
#

I was able to install stripe cli

#

I logged in

#

now what to do?

lament imp
#

and should i use server port or client

trail orbit
lament imp
#

hey I hve locally tested

#

but how to send the response bac

#

back

#

when I paid it got that success

vapid tendon
#

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

lament imp
#

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

vapid tendon
lament imp
#

why should I go to the custom page

lament imp
#

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

vapid tendon
#

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

lament imp
#

no

#

there is no status

#

shown in the docs

vapid tendon
#

The docs retrieve the checkout session object. You'll need to access session.status to see it

lament imp
#

is this the correct way

vapid tendon
#

Yes, try it out..

lament imp
#

do i need to pass the session_id in body?

vapid tendon
#

Yes, it won't know which session to fetch without it

lament imp
#

nope man

#

not for me

#

๐Ÿ™‚

#

I cant get the session id from the success_url

#

๐Ÿ™‚

#

see if you can help me with the code

#

๐Ÿ˜ญ

vapid tendon
#

Sorry I can't fix/write your code for you ๐Ÿ˜ฆ
Where exactly are you passing the sessionID to your API ?

lament imp
#

here

vapid tendon
#

That's for the creation though, you're trying to fetch the status after completion right?

lament imp
#

this code

vapid tendon
#

that code won't work after you do window.location.href = url;

You need to run that code on success page URL instead

lament imp
#

thanks

next yoke
#

I'm unclear what you are trying to delete, there's nothing sensitive in this thread, but just let me know once you're done so I can close

lament imp
#

yes sir done

#

thanks a lot

#

you can close it sir