#Mahesh K
1 messages ยท Page 1 of 1 (latest)
๐ How can we help?
when the invoice payment is failed because of some random issues. i am able to catch through webhooks, and the problem i am facing is ..how to find the reason of failure of invoice payment
Can you share the invoice ID (in_xxx), so that I can have a check?
yes
in_1MyYDDQrHwH0FKGrghmBdiLI
i am able to find the reason from the dashboard
when i receive the webhook event how to find the reason of failure through the response
You may use Invoice Retrieval API and expand payment_intent field. payment_intent.last_payment_error.message will share the failure reason
- Invoice retrieval API: https://stripe.com/docs/api/invoices/retrieve
- Expand an object: https://stripe.com/docs/api/expanding_objects
wow, that's so helpful.
An additional Invoice Retrieval request can be made after receiving the the invoice.payment_failed event
wait i will check
ok i will do that
๐
const invoice_failed_reasons = await stripe.invoices.retrieve(failed_invoice.id, {
expand: ['payment_intent', 'payment_intent.last_payment_error.message'],
stripeAccount: accountID,
});
is it true?
It should be something like this:
const invoice = await stripe.invoices.retrieve('in_xxx',
{
expand: ['payment_intent',],
}, {
stripeAccount: 'acct_xxx',
});
No problem! Happy to help ๐
yoooooh!
it works
Thank you river
last_payment_error: {
code: '',
decline_code: 'generic_decline',
message: "The customer's bank account has been closed.",
payment_method: [Object],
type: 'card_error'
},
That's awesome! Great to hear that ๐
hey river
last_payment_error: {
code: '',
decline_code: 'generic_decline',
message: "The customer's bank account has been closed.",
payment_method: [Object],
type: 'card_error'
},
Yes, how can I help?
Isn't the payment_method in the last_payment_error already an expanded object?
It's likely because you log the object instead of accessing it directly. Could you try to retrieve and log last_payment_error.payment_method directly instead?
Since it's in object type, this means that it's already expanded
Just that you need to retrieve it directly to get the details instead of logging high level object such as last_payment_error