Lesson G4 · Build your own gateway
Status job
By the end of this track you can write a small service that charges, stores every event and notifies your app.
● Sandbox only3 steps + checkpoint
0/6 finished
Step 1
The idea
Callbacks can go missing. Every minute, run STK Query on each payment that has been accepted for over two minutes, and move it on.
Step 2
How it works
The job
Every minute, find payments still accepted after two minutes and run STK Query on each. Move them with the same state function the callback uses, so both paths follow the same rules.
sql
SELECT id, checkout_id FROM payments WHERE status = 'accepted' AND updated_at < now() - interval '2 minutes';Give up gracefully
If a payment is still processing after, say, ten minutes, mark it for a person to look at. Don't keep querying forever.
Step 3
Common mistakes
- Querying every pending payment every few seconds.
- A second, slightly different state update in the job.
Go deeper
How do you test it?
Answer in your own words first.
Show the answerHide the answer
Block the callback route and pay a prompt. The payment still ends confirmed.