#MYoussef-subscription-webhooks

1 messages ยท Page 1 of 1 (latest)

remote pine
#

You'll likely wait invoice.paid and/or customer.subscription.updated. The invoice.paid event will specifically notify you when the customer has paird, and the customer.subscription.updated event will tell you when the subscription has renewed

oblique siren
#

so if you want to update the records of renewed subscription in my site database

1- i will check invoice.paid
if(stripeEvent.Type == Events.InvoicePaid){
// update my site database for customer subscription and set flag pending activation till customer.subscription.updated called
}

2- then check customer.subscription.updated
if (stripeEvent.Type == Events.CustomerSubscriptionUpdated){
// update the subscription to be active
}

#

is that correct ?

remote pine
#

Overall that's correct - but you won't typically get the customer.subscription.updated AFTER the invoice.paid event.

oblique siren
#

when can i get it it? can you help me to clarify this point

remote pine
#

Sorry let me clarify - typically you'll get the customer.subscription.updated first, and you'll get the invoice.paid event afterwards.

#

But you should also be careful that your code can handle these events coming out of order

oblique siren
remote pine
#

So usually, you'll get the customer.subscription.updated event first because the billing cycle, latest_invoice, and some other parameters are changing on the subscription. At this point, the invoice is still a draft, and will be finalized at a later point as long as the webhook event is correctly responded to. Around an hour later, the invoice will be finalized and payment will be attempted, which is when you'd get the invoice.paid event

oblique siren
#

what do you think if listen to invoice.paid only and ignore customer.subscription.updated ? is it enough or it is a must to listen to the both events ?

remote pine
#

it really depends on your integration - if you find that you don't need the informatino from customer.subscription.updated then you're welcome to not use it, but again, it's up to you

#

I need to head out, but if you have other questions @whole void can help!

whole void
#

Hi ๐Ÿ‘‹ happy to keep helping, let me know if there are any lingering questions.

oblique siren
#

sorry but i got lost can you help for the proper solution for my case

#

i am trying to create weebhook to check when the customer subscription is renewed and the payment is done successfully to update the customer records on my site
is invoice.paid the proper event that i should use in weebhook for this case?

whole void
#

Yup, invoice.paid would be a good fit for that.

modest river
#

You need to bare in mind that a payment may fail for whatever reason and could be attempted again days later so like the guys have said it really would depend on how and what you're trying to do

oblique siren
#

i only want to renew the customer subscription for one year in my site database (and i want to do that once the customer subscription renewed successfully on stripe and payment done)

#

for that i am trying to create a webhook to listen on invoice.paid event to achieve this requirement

#

and in case of invoice.failed , i will cancel the subscription in both (stripe and mysite)

#

can you help me for the proper steps of this case?

modest river
#

I obviously don't know what you're app does but I would ask yourself if it made sense to cancel someone's subscription after invoice.payment_failed? A year is a long time and a card may expire, you don't really want to lose a customer without giving them a chance to add their new card. Also the subscription object will help you identify when the subscription should be cancelled. For example based on your stripe configuration you could cancel after x failed payment attempts. A failed attempt will update the subscription to status to over due or something similar and cancelled after all the attempts

#

So what I'm trying to say is, I would personally keep the services running until the subscription ends unless it costs you to renew their service but bare in mind, if their service stops at x date, there could be a delay to resume their service if you rely on invoice.paid

oblique siren
#

thanks a lot i really appreciate

#

is there any event that i can listen to (which indicate the customer reach maximum failed attempts )?

modest river
#

I don't think so but you can listen for subscription.updated and where the status is cancelled you can cancel internally

#

Actually I think it's customer.subscription.deleted

oblique siren
#

so my webhook will b something like that

if(event.type == invoice.paid){
// subscription renewed successfully and i will update my system
}

if(event.type == customer.subscription.deleted){
// delete subscription in my system
}

#

it that correct ?

whole void
#

Keep in mind that the subscription's state changes are dirrectly influenced by the settings defined here:
https://dashboard.stripe.com/settings/billing/automatic

You'll want to make sure that you set these to fit your scenarios first, and then determine what events to listen for. For example, if you have this setting this way, then the subscription won't cancel when the retry attempts end.

#

But if you have it set to cancel instead, then yes, customer.subscription.deleted is the event to listen for.

oblique siren
modest river
#

Yeah sounds fine. Use the test clocks to test your scenarios

oblique siren
#

@modest river thanks a lot for your awesome help ๐Ÿ’

#

@whole void thank you so much, i really appreciate ๐Ÿ’