#Mike M - Transaction Failures
1 messages ยท Page 1 of 1 (latest)
Yo!
The first thing that comes to mind is to write something to the DB about a pending payment prior to Step 1, including the Payment Intent ID. Then, later, if Step 2 fails, periodically check for DB entries about pending payments, fetch the Payment Intent from the API, check the status, and make the appropriate adjustments.
Yes, I had thought about that option too. Use a state of incomplete on the purchase in the database.
It has two drawbacks:
- I need to have some machine scanning for incomplete transactions. My system is serverless, so that's a small challenge. It's really a variant of Solution 4: a periodic reconciliation.
- The UX still sucks for the user. They payment has gone through but they don't immediately have their product. It might solve itself somewhere down the line if they're patient!
Maybe there is no nice solution to this problem. ๐
Another thing you could do is set up a webhook endpoint to listen for payment_intent.succeeded events and use that as a redundant way to make sure the payment has been recorded.
Yes, less machinery my end. I can use a cloud function for that...
Can you tell me more about the possible causes of failure for Step 2 you're trying to work around?
Very few in practice. I'm writing to Google Firestore, from a Google Cloud Function. The chances of failure are probably very low! ๐
Still, it's not a good position to leave a customer in.
The only issue with a webhook is that I create a race between the webhook and my own function, so I need to make sure the write is idempotent
Which it is naturally I think
Perhaps it even makes sense to just rely on the webhook: do the transaction with Stripe, wait for the webhook to update my database, then listen for changes to the database from the client.
Depends how quickly Stripe invokes the webhook really; don't want to leave a customer waiting for an event tat might take a while (or never come!)
Ugh.
I think a combination of telling a customer to try again and having a webhook for backup is probably the right answer here.