Reputation: 1080
I have a scenario where I need to take an action in our system for a past_due status on stripe. But it depends on whether the subscription went from active (which was paid at least once) or trialing (which was in trial period and the first payment fails). Is there any way I can distinguish between those 2 scenarios?
Upvotes: 1
Views: 3243
Reputation: 116
There is a customer.subscription.updated
webhook event you can listen to, this event contains the Subscription where you can check if the status is past_due
[0].
For a Subscription that is past_due
, there are 2 pieces of information to obtain to determine whether the Subscription has previously been paid for:
trial_end
[1]:latest_invoice
is one of the fields from the Subscription, this is an Invoice id, upon retrieving the relevant Invoice [3], the epoch timestamp of interest can be found via lines.data[0].period.start
.If the value of these two epoch timestamps match, this indicates the Subscription has never been paid for, i.e. the latest invoice was created when the trial ended and payment has not been successful.
[0] https://stripe.com/docs/api/subscriptions/object#subscription_object-status
[1] https://stripe.com/docs/api/subscriptions/object#subscription_object-trial_end
[2] https://stripe.com/docs/api/invoices/line_item#invoice_line_item_object-period-start
[3] https://stripe.com/docs/api/invoices/retrieve
Upvotes: 1