#rnluu
1 messages · Page 1 of 1 (latest)
Hi, you might want to use the Search Invoices API: https://stripe.com/docs/api/invoices/search for this.
Hmm what do you mean by that?
There is no status on the invoice that shows failed payment
for invoices.Next() {
i := invoices.Invoice()
// For failed payment invoices, status is open.
if i.Status == stripe.InvoiceBillingStatusOpen {
// TODO: not sure if we need another check
// for the payment intent because we want to
// specifically find invoices that failed payment.
pi := i.PaymentIntent
if pi != nil && pi.Status == stripe.PaymentIntentStatusRequiresPaymentMethod {
// Then this means that it failed payment.
}
}
}
Would this work by the way?
If I look at the payment intent status === requires payment method (indicates it failed right) ?
Oh, you're looking for invoices that had failed payments. Looking
Yep exactly
Invoices that had failed payments
Actually more precisely, invoices where latest payment failed.
I see, I do not think that is directly possible. You'd need to list all of your invoices: https://stripe.com/docs/api/invoices/list and filter through the results.
Ok so I list all invoices
And I'm iterating through them
Then what can I do to see if they failed payment?
open can be open for various reasons, not just failed invoices
Right now I'm iterating through and looking for open invoices that have payment intent status === requires_payment_method
Would that suffice?
Yes, that would work.
Ok is there a better status to look at?
Or does require_payment_method basically indicate that it's a failed payment?
Yes, when the payment fails, you'd see requires_payment_method and that is what you'd filter through.