#Anil

1 messages · Page 1 of 1 (latest)

storm thistleBOT
inner hazel
#

Hello. How can we help?

iron haven
#

Hi sir,

  1. I am creating a checkout.sessions.create for payment.
  2. After that i am calling a webhook to listen the event's

I am trying to listen three events
checkout.session.completed and invoice.paid and invoice.failed

I am using console there to check but all the three are printing

#

And i check there are three different event ids

#

Do you have any idea why is this happening?

inner hazel
#

They are 3 distinct events, so they will have different event id's. This is expected

iron haven
#

Okay so for one payment all the three are printing.

inner hazel
#

Yeah

iron haven
#

FYI these three are inside the switch case

#

But all three are printing

inner hazel
#

What do you mean?

iron haven
#

Like if the invoice is paid then only invoice.paid case console should be printed

inner hazel
#

Well if you are set up to receive all 3 events, then your code will receive all 3 events

#

That should happen through 3 separate requests to your endpoint though

#

1 for each event

iron haven
#

Okay.

#

Basically i need webhook because i am using subscription.

#

So that's why i am using invoice.paid and invoice.paymemt_failed and checkout.session.completed

#

So what i want to do here is i want to update something in the UI so i have to call an api that i have created in the invoice.paid will that work?

inner hazel
#

What UI are you trying to update? There's nothing stopping you from calling an api in the webhook handler code

iron haven
#

It will update the credits
Like i have a button which will deduct 100$ from account and update the credit in my ui account

inner hazel
#

Yeah you can do that

#

Or you can just update your database in the webhook handler code

iron haven
#

Yes i will do that

#

But i am trying to call that api inside invoice.paid but api is not getting called

inner hazel
#

You'll need to debug why then

#

It's your code

iron haven
#

But when i try to call the api inside checkout.session.completed then api is getting called.

#

If i have monthly subscription then invoice.paid will be called every month right?

storm thistleBOT
inner hazel
#

yep assuming the invoice was successfully paid

#

it could fail

iron haven
#

Yes and is there any way i can return something to the ui if invoice paid successfully or fail

inner hazel
#

Yeah change your db

#

And have the ui pull from your db via an api

iron haven
#

Sorry Change your db means

inner hazel
#

Write the data to your databse

iron haven
#

Okay means we directly can't return to ui

#

Even if have to return simple invoice paid successfully or invoice failed

inner hazel
#

What ui?

#

You said you were using checkout sessions

#

You could also rely on the success_url of the session to pass data

iron haven
#

Okay yes we are returning success url and cancel url

#

But for subscription they will not get called right?
Because payment will be automatically deducted

inner hazel
#

If they paid successfully on a checkout session for a subscription they'll still be redirected to success url

iron haven
#

No this will be gor the first time,
For second month payment will deduct automatically, user will not do anything

slow pond
#

Hi 👋 @inner hazel had to step away so I'm taking over