Callback receiver
By the end of this track you can write a small service that charges, stores every event and notifies your app.
0/6 finished
Step 1
The idea
POST /callbacks/<secret-token> stores the raw body, replies {"ResultCode": 0, "ResultDesc": "Accepted"}, then processes in the background: find the row, ignore it if it is already final, check the amount, and move it to confirmed or failed.
Step 2
How it works
The order of work
- Save the raw body.
- Reply with
{"ResultCode": 0, "ResultDesc": "Accepted"}. - In the background: find the row by
CheckoutRequestID. - If it is already final, stop.
- Check the amount, then move it to confirmed or failed through your one state function (D1).
The secret path
Put a long random token in the callback path, such as /callbacks/3f9c…, and reject other paths. It stops casual fake callbacks; checking the amount and the ID stops the rest.
Test it
Pay one prompt, cancel another, then POST a saved success body a second time. Nothing should change.
Step 3
Common mistakes
- Processing before replying.
- Skipping the amount check.
Go deeper
What happens if the same callback arrives twice?
Answer in your own words first.
Show the answerHide the answer
Nothing changes. The row is already final, so the second one is ignored.