Reputation: 516
I have two APIs for Stripe webhooks in my backend (Django).
/api/subscriptions/webhook/
/api/wallet/webhook/
In the subscription webhook, I listen for invoice.paid
and invoice.payment_failed
events and in the wallet webhook I listen for payment_intent.succeeded
event. The problem is whenever the subscription webhook gets called, the payment_intent.succeeded
event is also triggered for the wallet webhook. I think that's because payment intents are also created for subscription as well. I need a way to differentiate these two (one-time payment [aka add balance to wallet] and subscription) so I don't end up with extra credit in user's wallet whenever their subscription get renewed.
Upvotes: 2
Views: 4915
Reputation: 516
I ended up using the invoice.paid
event for both webhooks and check the data.object.lines.data[0].price.type
field which can be either one_time
or recurring
. You can read more about it at https://stripe.com/docs/api/invoices/line_item#invoice_line_item_object-type
Upvotes: 4