#gabor-period-end-sub

1 messages ยท Page 1 of 1 (latest)

little boltBOT
onyx bobcat
#

Hello ๐Ÿ‘‹
So your end goal is to check when the current period ends?

honest cypress
#

Hi @onyx bobcat ๐Ÿ‘‹ , yes, I want to update my db with the new end of the period when plan has changed and successful payment happened.

#

For example when a user switches from monthly to yearly payment.

onyx bobcat
#

gabor-period-end-sub

honest cypress
#

Well, I experimented with watching for customer.subscription.updated events so that I can rely on the subscription object. But I am not sure how I could make the db update only on successful payment.

onyx bobcat
#

On the invoice.paid event, you'd want to retrieve the subscription again and check the current_period_end timestamp

honest cypress
#

Ah, okay, thank you.

onyx bobcat
#

NP! ๐Ÿ™‚ Happy to help

honest cypress
#

Do you recommend to do this also when a user just signs up, and when a new cycle happens?

#

Is this solution more reliable than using the line items?

#

I am asking because of the double request.

#

I mean one more request.

onyx bobcat
#

So you can certainly just use customer.subscription.updated event as it is sent when the subscription is successfully started, after the payment is confirmed. Also sent whenever a subscription is changed. but in that case you'd need to check if the latest invoice was paid or not

https://stripe.com/docs/billing/subscriptions/webhooks

honest cypress
#

That's very useful to know.

#

Thank you for your help!

onyx bobcat
#

NP! ๐Ÿ™‚ Good luck

honest cypress
#

Thanks ๐Ÿ™‚