Alireza Beitari
Alireza Beitari

Reputation: 516

Stripe: 'payment_intent.succeeded' is also triggered when subscription gets renewed

I have two APIs for Stripe webhooks in my backend (Django).

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

Answers (1)

Alireza Beitari
Alireza Beitari

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

Related Questions