#lil-nasty_best-practices

1 messages ¡ Page 1 of 1 (latest)

abstract matrixBOT
cosmic cryptBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

abstract matrixBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1275222130342236363

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

worldly cipher
#

I would assume that invoice.created is a decent date to show, but if there's a bank payment or a payment fails and is retried days later and succeeds then, I would think that invoice.created would be the wrong date to display

brisk wind
#

You would need to look at the underlying Payment Intent that represents the actual payment of the Invoice. There's also invoice.paid which sounds more like what you're looking for

worldly cipher
#

Invoice.paid is a boolean, I need a timestamp

brisk wind
#

No I mean the webhook event invoice.paid

worldly cipher
#

When a user fails a payment we want to retrieve the invoice for the failed method, display it's details and use the client_secret from the payment_intent to allow the user to retry the payment

#

We currently fetch the user's invoices and display them to show payment history, and if a payment failed we have a button that opens a modal with a payment element that uses the client secret to reattempt the payment with a different payment method, we need to display the date of all invoices

brisk wind
#

Then you need to get the underlying Charge object from the Invoice's Payment Intent latest_charge attribute (https://docs.stripe.com/api/payment_intents/object#payment_intent_object-latest_charge). The created date on the Charge object will actually represent the exact time that the payment succeeded or failed: https://docs.stripe.com/api/charges/object#charge_object-created

worldly cipher
#

I've been using that date, but on the invoice that failed, the latest_charge field is null

#

I expand it and know that it's getting properly returned on other invoices

#

the payment_intent.status = requires_confirmation

brisk wind
#

If you're trying to show failed payment attempts, then you need to be listening for webhooks and storing the payload from events like payment_intent.payment_failed or invoice.payment_failed

worldly cipher
#

Why? Don't both of those just send the invoice or payment_intent that failed? Which would be the same object that I get back when I request invoices from Stripe?

brisk wind
#

Yes, but the last_payment_error may change if they try to pay again, so you will only have that specific state of the last_payment_error for that specific payment attempt via the webhook (or if you happen to retrieve the Payment Intent before the next payment intent update that happens): https://docs.stripe.com/api/payment_intents/object#payment_intent_object-last_payment_error

worldly cipher
#

We retrieve the invoices directly from stripe and pass them on to the customer when they request them so I don't have a great deal of worry about them not being synced. That being said how does the webhook event give me a better date to show the user for the invoice itself?

brisk wind
#

What are you actually trying to get? You were talking about payment failures, now you're talking about "a better date to show the user for the invoice itself". What date do you want to show? The date it was created? The date a payment failed on it? The date a payment succeeded on it? The due date (applicable to only subscriptions)?

worldly cipher
#

I suppose if the payment failed, the date the payment was attempted, and if it succeeded then the date it succeeded

brisk wind
#

We went over that, no? You should have an explanation in this thread for both those situations I believe

worldly cipher
#

For paid you suggest the time when we get the invoice.paid event? And for failed we would just show the invoice.created date?

#

NVM, I'll do latest_charge.created for paid and invoice.created for failed

#

Thanks

brisk wind
#

invoice.created won't actually show the time of the payment failure, but if that works for your use-case then by all means

worldly cipher
#

Is there a better place to see that?

#

Other than invoice.payment_failed event

brisk wind
#

Not without using webhooks to get the last_payment_error off the Payment Intent