M-Pesa Reconciliation: How to Automate It in Your ERP
For most Kenyan businesses, M-Pesa is the main way customers pay. That is good for cash flow and bad for bookkeeping. Every payment arrives as a separate transaction with a reference code, and someone has to work out which customer it came from and which invoice it settles. At a few payments a day that is a chore. At a few hundred, it is a full-time job, and the books are always a day or two behind.
Automating it is mostly a matter of getting the payment data into your ERP directly, then letting clear rules do the matching. This guide covers how that works and how to set it up.
Why Manual M-Pesa Reconciliation Breaks Down
The problem isn't that matching one payment is hard. It's that the exceptions pile up:
- Customers type the wrong account number, or their own name, or leave it blank.
- One invoice is paid in three instalments over two weeks.
- One payment covers several invoices, with no indication of which.
- Till (Buy Goods) payments carry no account number at all.
- The M-Pesa statement is downloaded hours later and re-keyed into the accounts, adding a second chance for errors.
Each exception needs a person to investigate it, and while they do, the customer's balance is wrong. That leads to chasing customers who have already paid, or releasing goods to customers who haven't.
How M-Pesa Payments Reach Your ERP
Safaricom's Daraja API is the official way for business systems to connect to M-Pesa. For incoming payments, your business registers a confirmation URL for its Paybill or Till number. From then on, every payment to that number is posted to your ERP automatically, usually within seconds of the customer receiving their confirmation SMS.
Each notification includes the M-Pesa transaction ID, the amount, the time, the payer's name and, for Paybill payments, the account number the customer entered. Safaricom partially masks the customer's phone number in these notifications, so the account number, not the phone number, is the reliable way to identify who paid.
Daraja also supports STK Push (Lipa na M-Pesa Online). Instead of waiting for the customer to pay, your ERP sends a payment prompt to their phone from the invoice itself. The customer enters their PIN, and the result comes back linked to that exact invoice. There is nothing to match, which makes STK Push the cleanest option for B2B collections and online orders.
Matching Rules That Actually Work
Good rules are strict at the top and cautious at the bottom. Apply them in this order:
- Account number equals an open invoice number: apply the payment to that invoice.
- Account number equals a customer code: apply the payment to that customer's oldest open invoices first.
- Payer name and amount closely match an open invoice: suggest the match for someone to confirm, but don't apply it automatically.
- Anything else goes to an unmatched queue for review.
Partial payments leave the invoice part-paid, with the balance still showing. Overpayments are held as a credit on the customer's account, ready to apply to the next invoice. Either way, the customer's statement is correct the moment the payment arrives.
Most of the work is in rule 1. If customers reliably use the invoice number as their account number, the large majority of payments match with no human involvement. Print the Paybill number and "Account no: invoice number" on every invoice, quotation and payment reminder SMS.
See M-Pesa Matching Live
We'll connect a test Paybill and show payments landing on invoices in real time.
Book Free DemoPaybill or Till: Which Should You Use?
Use a Paybill number wherever customers pay against an invoice, such as distributors, wholesalers, schools, landlords and service businesses. The account number field is what makes automatic matching possible.
A Till number suits walk-in sales, where the customer pays at the counter and the cashier can see the payment arrive. Because there is no account number, Till payments should be matched at the point of sale, not reconciled later. Many businesses run both: a Till for the shop, and a Paybill for credit customers.
Closing the Day
Automation doesn't remove the daily check. It makes it take minutes instead of hours. At the end of each day, compare your M-Pesa account balance in the ERP with the balance on the M-Pesa organisation portal, then clear anything left in the unmatched queue.
Two items regularly trip people up. M-Pesa transaction charges should be booked as an expense, not netted off sales. And when money is moved from M-Pesa to your bank account, it should be recorded as a transfer between two of your own accounts, not as income or a payment.
Setting It Up
- Apply for Daraja production access for your Paybill or Till number. Safaricom's approval can take some time, so start early.
- Link the shortcode to an M-Pesa account in your ERP, so every incoming payment is posted there.
- Put your Paybill number and the invoice number on every invoice and payment reminder.
- Configure the matching rules above, and decide who owns the unmatched queue.
- Run the automated matching alongside your existing process for a couple of weeks, then switch over.
What's Next?
Once collections are automated, the next bottleneck is usually stock. Read how to set reorder points around real import lead times, or see how KRA eTIMS invoicing fits into the same sales flow.