#MYoussef-invoice-paid-diff
1 messages ยท Page 1 of 1 (latest)
Hello ๐
I can surely look into it.
Do you have any example event IDs available for these by any chance?
Wait found it
this is a test id "evt_1KlJ8EGjZDiWw2MlnVSBlr56"
when trigger customer.subscription.created
and in my webhook, i am trying to use this code to listen
if(stripeEvent.Type == Events.InvoicePaid)
{
// code to renew customer subscription in my site database
//NOTE: i want this function to be implemented only when subscription renewed not created
}
You can look at the billing_reason property on the event body to find the reason behind invoice creation
https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
It would say subscription_create for a new subscription
and say subscription_update if created by an update to a subscription
in both cases it gave me "billing_reason : "subscription_create" "
do you have the event ID for when you trigger customer.subscription.updated?
evt_1KlJGWGjZDiWw2MlkQIaEkDK
are these events for two different subscriptions?
yes, and for your information i am trying to do it from stripe cli
so you're using stripe trigger customer.subscription.updated and looking at the invoice.paid event?
yes
This creates a new subscription every time hence the invoice.paid event on it would say subscription_create.
I haven't tested this but you should be able to do this via the dashboard. You can update a subscription with proration which should create an invoice which once paid should show the correct reason there.
let me quickly check something
Yeah I don't think CLI can support this by default unless you build your own fixture.
if i update it from dashboard, will it hit the local webhook, or it is a must to use a public url ?
You should be able to listen to it locally
got it
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i found that there is subscription_cycle
should i use it in my code or subscription_update is the proper one
i update my webhook like that
if (event.type == invoice.paid && event.billing_reason == "subscription_update" ){
// update my database with renewal
}
is that code logic correct or i should use subscription_cycle
?
If you're checking for renewal you should use subscription_cycle
I've got to hop off now but @rotund spoke should be able to help you if you have any follow up questions ๐
Good luck
Thanks
@rotund spoke as per henzo recommendation i should check if billing reason = subscription_cycle for subscription renewal in webhook
if i create subscription with 1 year trail, after 1 year and when the customer auto-charged for the new year after trial (will billing_reason = subscription_cycle also)
?
so in renewal and after trial to update my site database by webhook, the below code logic is correct?
if (event.type == invoice.paid && event.billing_reason == "subscription_cycle" ){
// update my database with renewal or renewal after-trial
}
?
yes correct