M-Pesa Reconciliation: How to Automate Matching Till and Paybill Payments to Invoices (2026)

Photo: M-PESA mobile money and Equity agent, Nairobi, Kenya by wrcomms, CC BY-SA 2.0. Cropped.
Key takeaways
- Paybill with a unique account reference (invoice, admission or customer number) is the foundation of automatic matching.
- The Daraja API's C2B confirmation and STK Push callbacks deliver payment details to your system in real time.
- Good systems handle the messy cases: wrong account numbers, partial payments, overpayments, duplicate and reversed transactions.
- Sync matched payments to your accounting software and keep an audit trail for KRA and auditors.
Why manual M-Pesa reconciliation breaks down
For a small shop with twenty payments a day, scrolling through SMS confirmations works. For a school with 800 families, a distributor with 300 retailers, a SACCO, a property company collecting instalments or an online store, it doesn't. The typical manual process:
- Download the M-Pesa statement from the M-Pesa portal (or worse, read SMS messages).
- Open the invoice list or student fee register in Excel.
- Match each payment by name, phone or account number, often guessing.
- Update balances, issue receipts and post entries in the accounting system.
- Chase the unidentified payments: "Who paid KES 15,000 from 0722 xxx xxx with account 'fees'?"
It takes hours, errors are common, and customers who've paid still get reminders, which damages trust. Meanwhile management never has an up-to-date view of collections.
How automated M-Pesa reconciliation works
Automation uses Safaricom's Daraja API:
- C2B (Customer to Business): when a customer pays your paybill or till from their phone, Safaricom sends the transaction (receipt number, amount, phone number, name, account reference, time) to your system's confirmation URL.
- STK Push (Lipa na M-Pesa Online): when your system requests a payment, for example at checkout or from an invoice link, Safaricom sends a callback with the result, already tied to the order that requested it.
- Transaction status and account balance queries: used to verify transactions and investigate missing callbacks.
Your system receives each payment, applies matching rules, updates the customer's balance or order, sends a receipt by SMS or WhatsApp, and posts to accounting. All of it happens within seconds.
Matching rules that actually work
Automatic matching is only as good as the rules. A robust setup checks in order:
- Exact account reference: paybill account number equals an invoice number, admission number, plot number or customer code. This is the most reliable, so design your references to be unique, short and easy to type.
- Known phone number: the paying phone number belongs to a single customer with an open balance.
- Fuzzy reference matching: common typos (an extra space, "INV-0123" vs "INV123", letter O vs zero) resolved automatically.
- Amount and timing: a payment exactly equal to an open invoice from a likely customer, flagged for one-click confirmation.
- Exceptions queue: everything else goes to a person with suggestions, never silently dropped.
With good references, most organisations see the large majority of payments matched automatically. The rest are handled in minutes instead of hours.
Handling the messy cases
| Case | How the system should handle it |
|---|---|
| Wrong or missing account number | Try phone and amount matching. Otherwise queue for review with suggestions. |
| Partial payment | Apply to the invoice and show the remaining balance. Send a receipt with the balance. |
| Overpayment | Hold as credit on the account or apply to the next invoice, per your policy. |
| One payment for several invoices | Allocate oldest first, or as the customer instructs. |
| Someone else paying (parent, employer, relative) | Match by account reference. Optionally link the payer's number to the customer. |
| Duplicate callbacks | Deduplicate by M-Pesa receipt number. Never count a transaction twice. |
| Reversals | Record the reversal and reopen the invoice balance. |
| Missed callback (system downtime) | Daily statement import or status queries to catch anything missed. |
Till or paybill: which is better for reconciliation?
A Buy Goods till is simple for walk-in retail, but customers can't enter an account reference, so matching relies on phone numbers, amounts and timing. A paybill lets customers enter an account number, which makes automatic matching far more reliable. For schools, landlords, property developers, SACCOs, distributors with credit accounts and any business sending invoices, a paybill is usually the right choice. For e-commerce and invoice links, STK Push is best of all: the system knows exactly which order each payment belongs to.
Merchant fees differ by product and agreement, with reported figures ranging roughly from 0.55% to 1.5% for collections and paybill tariffs negotiated with Safaricom, so confirm current charges directly with Safaricom.
Syncing with accounting and KRA requirements
Matched payments should flow into your accounting software (QuickBooks, Xero, Zoho Books, Sage or your ERP) as receipts against the right customer and invoice, with the M-Pesa receipt number as reference. This gives you:
- A clean audit trail from M-Pesa transaction to ledger entry
- Accurate customer statements and debtor ageing
- Faster month-end closing
- Records that support your tax filings and eTIMS invoicing
Keep raw callback data stored securely and unchanged, so you can always prove what was received.
Who benefits most?
- Schools and colleges: fees by admission number. See school management systems in Kenya.
- Real estate and land companies: deposits and instalments by plot or unit number. See AI for real estate.
- Landlords and property managers: rent by house number.
- Distributors and wholesalers: payments against invoices and credit accounts.
- E-commerce: STK Push at checkout with automatic order confirmation. See e-commerce with M-Pesa.
- Clinics, gyms and subscription businesses: recurring and per-visit payments.
Building the integration: step by step
- Get a paybill (or till) in the business name and access to the M-Pesa organisation portal.
- Register on the Daraja portal, create an app and develop against the sandbox.
- Register C2B URLs (validation and confirmation) and implement the STK Push callback if needed. Use HTTPS and verify incoming requests.
- Design account references and communicate them clearly to customers.
- Implement matching rules, receipts, and the exceptions queue.
- Add the daily safety net: statement import or status checks to catch missed callbacks.
- Connect accounting and dashboards.
- Go live with Safaricom's production approval, then monitor closely for the first weeks.
Developers commonly build this in PHP, Python, Node.js or similar. The code itself is not the hard part. Reliable handling of edge cases, security and monitoring is.
Security essentials
- Keep Daraja credentials and passkeys secret: environment variables, never in code repositories.
- Accept callbacks only over HTTPS and validate their source and structure.
- Never mark an order paid based only on the customer's browser. Wait for Safaricom's callback.
- Log every callback and protect logs, since they contain personal data covered by the Data Protection Act.
- Restrict who can manually match or reverse payments, and audit those actions.
What results to expect
Organisations that automate reconciliation typically cut reconciliation time from hours a day to minutes, issue receipts instantly, stop "I paid but it's not reflecting" calls, and get a live view of collections on their dashboard. Collection rates often improve too, because accurate balances make reminders trustworthy. See custom business dashboards for how collections data fits into the bigger picture.
Example: a land company collecting instalments
Picture a land company selling plots on 12-month payment plans to 600 buyers, many in the diaspora. Before automation, two staff spent most of each day matching paybill payments to buyers using an Excel register, and buyers waited days for receipts. After automation, buyers pay using their plot number as the account reference. Each payment updates the buyer's balance within seconds, a WhatsApp receipt shows the amount paid and the balance remaining, and reminders go out automatically before each due date. Payments with wrong references, usually relatives paying for someone else, land in an exceptions queue that takes minutes to clear. Management sees collections, arrears and expected inflows live.
Next step
Count how many hours your team spends each week matching M-Pesa payments, and how many payments end up unidentified. That's the size of the opportunity. If you'd like reconciliation automated with your own paybill, invoices and accounting system, ask for a free 7-day prototype.
Frequently asked questions
How do I reconcile M-Pesa payments automatically?
What is the Daraja API?
Is paybill or till better for reconciliation?
What happens when a customer uses the wrong account number?
Can M-Pesa payments sync with QuickBooks or Xero?
How much does M-Pesa integration cost?
Want this built for your business?
Kavenacc Digital Solutions builds custom AI dashboards, AI agents and web apps in days β with a free working prototype in 7 days and 100% ownership of the code.
Start My Free Prototype βExplore Kavenacc services & pricing β
Chat with a Real Personon WhatsApp