I have an automated invoicing web app and I'm trying to build in some failsafes and a structure that will, under no circumstance, allow an invoice to be double charged.
All things working perfectly, the scheduled task runs and everything charges as it's supposed to. But there are a few scenarios we know of that can cause problems.
I've had a DB server go down in the middle of a process, which lead to a number of duplicate charges. Also if for whatever reason, the file needs to be checked in a browser, a developer hits refresh before the file is done processing, duplicate charges will occur.
There are a few similar scenarios to protect against, so you can see the need for a way to handle this given the sensitivity of the transactions (imaging seeing your power company auto charging you twice on your bank statement).
Current configuration:
Query
API POST For Transaction
<!--- Parse Reply String ---> if response = "1" - Insert Into Payments - Update Invoice Amount Due - Insert Into Transactions - Email Accepted Notification else - Email Declined Notification
There's a few more smaller processes that happen between a few of these, as well as quite a few if statements but those are the heavy lifting parts.
What I would like to learn and hear about are what would be the best way to handle safeguarding this with considering the Third Party API for the gateway being there?
How would you break it up?
One idea I had was flagging each process after it ran to give a record of where it was when it failed, and build out the query to handle it accordingly. Not sure how efficient or more likely how inefficient it would be.