#Chhay-webhooks

1 messages ยท Page 1 of 1 (latest)

thorny lintel
#

Hi there! You like want customer.subscription.updated

torn forum
#

but this event will trigger as well when we switching from one plan to another, or changing the status from trial to active, right?

#

so Is it safe to listen this event?

#

I have checked some tutorial

#

and saw this notice

thorny lintel
#

Yes that is true... it really just depends on what you are looking to do exactly. I assumed you would only be updating when the Sub changed status.

#

So you would ignore the events if the status was the same

#

You want StartAt & EndAt of the Subscription, not each individual billing period, correct?

torn forum
#

what I am looking for is to update the startAt & endAt in the DB whenever User has been paid successfully.

thorny lintel
#

Oh okay so you want the billing period itself

#

That is a bit different

#

You can listen for invoice.paid in that case to only update on successful payment.

torn forum
#

but when I looking at the fields in Invoice Object, there is no "current_period_end" & "current_period_start".

#

It has only fields "period_start" & "period_end" where the value are the same.

thorny lintel
#

Upon an invoice.paid event you would retrieve the Subscription and look at the current_period_end and current_period_start which will be the new period at that point.

torn forum
#

Do you mean we need to look at

object.lines.data[0].period.start
object.lines.data[0].period.end

right?

#

or we need to get the subscription ID from "invoice.paid" and call Stripe API to get Subscription Detail by ID?

lethal bay
#

Hello. Taking over for bismarck as they have to step out. Give me a moment to catch up

torn forum
#

Is he got headache? ๐Ÿ™‚

lethal bay
#

Ah no we all rotate ๐Ÿ˜„

torn forum
#

Oh thanks God!

lethal bay
#

So I believe you can use the end and start values on that line item as well

#

I recommend retrieving the subscription to check the values there as well to make sure they match, but they should just be the same

torn forum
#

when you talk about "retrieving the subscription"

#

does it mean we need to call Stripe API to get Subscription Detail by ID?

lethal bay
#

Yeah because that's where current_period_end and current_period_start are located

#

They should match what's on that line item above

torn forum
#

If so, it would be increase the waiting time at the server.

lethal bay
#

Yeah I don't beleive you have to do it

#

Just suggesting you do it to verify the details match

torn forum
#

As I remember, we need to return the response as soon as possible after we received the webhook.

torn forum
lethal bay
#

Just saying that because I don't know the answer off the top of my head

#

You should be able to trust it as long as there aren't multiple line items

torn forum
#

Ok I got it

#

Could I ask another question here?

lethal bay
#

Yep! Go for it

torn forum
#

what is the different between

payment_intent.succeeded
invoice.payment_succeeded
invoice.paid
```?
#

when recurring happen does these 3 events trigger?

#

and when the customer subscription expired, which event should we listen in order to update some data (like user subscription status, update the user roles...etc) in DB?

lethal bay
#

Those 3 events get triggered on successful subscription payment. Subscriptions generate both invoices and paymentintent objects, that's why

#

What do you mean by subscription expired?

#

Like if a user cancels the subscription?

#

Or if a payment failed?

torn forum
#

yes

lethal bay
#

Which one?

torn forum
#

both of them

user cancels the subscription
and payment failed
lethal bay
torn forum
#

thank you boss

lethal bay
#

No problem!

torn forum
#

have a lovely day

lethal bay
#

Same to you!