Menu

My payment script left orders stuck as "pending" forever. Here is the small reconciliation job that fixed it
📰

My payment script left orders stuck as "pending" forever. Here is the small reconciliation job that fixed it

DEV Community: beginners·rene·4 days ago
#zdPmDUn5
#devtobeginners#devto#dev#charge#order_id
Reading 0:00
15s threshold

Last week I found 11 orders in my database that had been "pending" for days. The customers had paid. My script had crashed between "charge succeeded" and "mark order paid". Nothing was wrong with the payment provider. The bug was mine: I trusted a single write to happen exactly once.

This post shows the failure and a small reconciliation job that repairs it. It uses only the Python standard library, so you can copy it.

The failure

def checkout ( order_id , amount ): charge = provider . charge ( amount ) # 1. money moves db . execute ( " UPDATE orders SET status= ' paid ' WHERE id=? " , ( order_id ,)) # 2. we record it

Enter fullscreen mode

Exit fullscreen mode

If the process dies, times out or is restarted between step 1 and step 2, the money has moved but the row still says pending . Retrying the whole function can charge the customer twice. Doing nothing leaves the order stuck.

Fix part 1: a stable request fingerprint

Give each logical charge one key that never changes across retries.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.