After a customer enters their PIN, your server needs to find out what happened. Safaricom tells it by sending a callback to an address you provide.
What a callback contains
It identifies the request, says whether it succeeded and, if so, includes the amount and the M-Pesa receipt number. Your system matches it to the request it created.
Why you cannot trust it blindly
A callback address is public. Anyone could send a fake message to it. Safe systems use a secret token in the address, only accept results for requests they actually issued, compare the amount and, ideally, ask Safaricom to confirm.
Respond quickly
Return a simple acknowledgement fast, then do the work. If your server is slow or down, results can be missed, so provide a way to check a request's status later.
Make it idempotent
Handling the same callback twice must have the same effect as handling it once. This protects you from retries and replays.
Callback safety checklist
- Use https with a secret token in the address
- Only accept results for requests you created
- Compare amount and currency
- Verify with the provider before confirming
- Store each receipt once
How PixelBilling helps
PixelBilling implements these checks: a per-ISP token, matching to issued requests, an amount check, a provider status query and unique receipts, with anything doubtful held for review.
Common questions
What if I do not receive a callback?
The request stays pending. After a time it can be marked timed out, and staff can check status with the provider.
Can I test callbacks locally?
Safaricom needs a public https address. Use the sandbox with a public test address, or simulate callbacks in your own tests.
Why return success even for bad requests?
The sender only needs an acknowledgement. Returning detail about why something was refused can help an attacker.
See PixelBilling with your own data
Start a free trial, import your customers and watch a payment turn into a connection. Or send us your questions.