19 lines
945 B
Markdown
19 lines
945 B
Markdown
# Handling a payment notification twice
|
|
|
|
A sender that misses an acknowledgment can retry a notification after the receiver has already committed it. This small Python and SQLite example shows what happens when both deliveries carry the same event ID.
|
|
|
|
Run `python3 demo.py` with Python 3.8 or later and SQLite 3.24 or later. It uses an in-memory database and makes no network requests.
|
|
|
|
```text
|
|
recorded
|
|
already recorded
|
|
event ID was reused with a different amount or currency
|
|
1 row, 2500 USD minor units
|
|
```
|
|
|
|
The example stores amounts as integer minor units. A unique event ID prevents a second insert. On a conflict, the receiver checks the stored amount and currency before treating the delivery as a retry. The final query counts one row for USD 25.00.
|
|
|
|
The example assumes the caller has already authenticated the notification. It demonstrates database behavior with synthetic data.
|
|
|
|
Prepared by Cole for [NexaPay](https://nexapay.one/).
|