#arielbo-subscription-webhooks
1 messages · Page 1 of 1 (latest)
hello toby
I want to understand how the logic of the first, second and subsequent payments with subscriptions works, I am using the invoice.payment.succeeded event, what I do not understand is how I will know if it is a new payment
?
What do you mean here by "new payment"?
You can check the Invoice's billing_reason for info on what the Invoice was created for https://stripe.com/docs/api/invoices/object
The reason will be subscription_create if this is the first payment and subscription_cycle for renewal payments
In my database I am saving the subscription id and I can use that data to identify the event (invoice.payment.succeeded) when they send it to me but I would like to know if they will also send me the new subscription start and end dates
I mean renew payment, pompey
The billing_reason will be subscription_cycle if this is payment is to renew the subscription
well you say that when I receive the event invoice.payment.succeeded i need to read billing_reason and if this is in subscription_cycle this is a renew payment? right
Yes that sounds right
Also we typically recommend listening to invoice.paid for this
That event is triggered every time invoice.payment.succeeded is triggered and it also includes out of band payments
you advise me for listen renews use invoice.paid more than invoice.payment.succeeded?
Yes
and inside the event invoice.paid use billing_reason for?
Check if invoice.billing_reason == 'subscription_cycle'
If so then this invoice was generated for a renewal
let me test
Pompey is correct that the first invoice.billing_reason is "billing_reason": "subscription_create", ?
how can I testing one renew payment to check invoice.billing_reason == 'subscription_cycle' ?
@torn yarrow https://stripe.com/docs/billing/testing
thank you, please how can I trigger one renew payment?
it's explained in details on that doc
you can't fast forward time, so the only way is to change the billing cycle, it's similar to the payment failure example
1/ Create a subscription with a short trial period, or billing_cycle_anchor a few minutes in the future
2/ Wait for the period or the trial to end
3/ New cycle starts, invoice.created is sent, as you needed
let me see