How Metron ISP reconciles M-Pesa Paybill C2B payments
How Metron ISP receives Daraja C2B confirmations, stores them first, matches them to subscribers and handles unmatched payments and missed callbacks.
This page explains what happens between a customer paying your Paybill and their service being credited, and how failures are handled. It describes the design so you can reason about edge cases.
The flow in brief#
- The customer pays your Paybill with their account number as the reference
- Safaricom calls your C2B confirmation URL with the transaction details
- Metron stores the raw callback before doing anything else
- The payment is matched to a subscriber and credited
- The subscriber is reconnected if the balance is cleared, and a receipt is sent
Why the raw callback is stored first#
Every confirmation is written to an inbox table in its original form, and only then processed. If matching fails or the database is briefly unavailable, the callback is not lost. It stays in the inbox as failed and is retried by a scheduled sweep.
What happens to each payment#
Each payment ends in one of three states:
- Processed: matched to a subscriber and credited
- Unassigned: no subscriber matched, so it waits in a queue for staff to assign
- External: the customer is still billed by another system, so it is recorded as history only
An unmatched payment is never dropped. It appears in the unassigned queue so a person can assign it.
Validation URL#
Safaricom can ask your validation URL whether to accept a payment before it completes. Metron can run in an observe mode that accepts everything, and an enforce mode that rejects payments for unknown account numbers once you are ready to cut over.
Missed callbacks and statement checks#
Callbacks can occasionally fail to arrive. Two safeguards cover this:
- A statement import compares a Safaricom statement with the ledger and reports payments Safaricom received but your system never recorded
- Every change to a customer's wallet balance is written to a ledger, and consistency checks run on a schedule
Callback protection#
Confirmation endpoints limit the request size and the request rate per source, and can require an IP allowlist or shared secret so forged callbacks are rejected.
Partial and over-payments#
Payments are allocated against the subscriber's billing cycle, and any amount beyond what the cycle needs is kept as wallet credit. Each allocation is recorded in the wallet ledger.
Related#
See ISP billing with M-Pesa, and the guide to reconciling Daraja transactions in Excel.