Skip to content

How to Automatically Match M-Pesa Payments to Invoices

Matching M-Pesa payments to invoices by hand is slow and error-prone. With a clean account reference and the right setup, your system can do it automatically.

By Karani Geoffrey, Founder & CEO, Upeosoft
In short

To automatically match M-Pesa payments to invoices, give each invoice a unique account reference that customers enter when they pay your paybill or till. Your system receives Safaricom's payment confirmation, reads that reference, and marks the matching invoice paid. The amount alone is not enough - a clean reference is what makes automatic matching reliable.

Key takeaways
  • Automatic matching depends on a unique account reference per invoice, not on the payment amount.
  • The amount alone cannot identify an invoice, because two customers can owe the same figure.
  • Payments made via STK Push are easiest to match, since your system sets the reference for the customer.
  • For paybill and till payments, customers must enter the reference, so it has to be short and clear.
  • Payments with a missing or wrong reference fall into an exceptions queue for a human to match.
  • Done well, matching updates your ledger in real time and removes hours of manual reconciliation.

The real problem: money arrives, but which invoice is it for?

When an M-Pesa payment lands, the money is safe - it is the knowing what it is for that is hard. Your account fills up with confirmations, but connecting each one to the right invoice is where businesses lose hours and make mistakes. Someone sits with the M-Pesa statement in one hand and the invoice list in the other, matching line by line.

This manual matching does not just waste time. It causes real errors: customers marked unpaid who actually paid, payments credited to the wrong account, and disputes that erode trust. The goal of automatic matching is to answer one question the instant money arrives - which invoice is this for - without a human doing detective work every day.

Why the account reference is everything

The single most important idea in automatic matching is the account reference. This is the piece of text that travels with the payment and tells your system which invoice it belongs to. Get the reference right and matching is easy. Get it wrong or leave it blank and no software can match reliably.

The reference has to be unique to one invoice. An invoice number is the natural choice, or a customer account number your system knows. What it cannot be is a name or a guess. When the payment confirmation reaches your system, it reads the reference, finds the one invoice it points to, and marks it paid. Everything else in automatic matching is built on getting this one field clean and unique.

Why the amount alone will never work

Business owners often assume the amount can identify a payment. It cannot, and relying on it causes exactly the errors you are trying to avoid. Amounts are not unique - the moment two customers owe the same figure, a payment for that figure is ambiguous, and your system either guesses or gives up.

The amount is still useful, but only as a confirmation. Once the reference has identified the invoice, checking that the amount matches catches underpayments and overpayments. Think of it as reference first, amount second: the reference says which invoice, the amount says whether it was paid in full. Trying to reverse that order - amount first - is the classic mistake that keeps businesses stuck matching by hand.

STK Push versus paybill: two paths, two levels of certainty

How the customer pays changes how easy matching is, so it helps to understand both paths.

  • STK Push (Lipa na M-Pesa Online): your system triggers the payment prompt and sets the reference itself. The customer cannot mistype it, so matching is near-certain. This is the cleanest path when you control the checkout.
  • Paybill or till (C2B): the customer pays on their own and types the reference as the account number. Matching depends on them entering it correctly, so the reference must be short and easy to copy.
  • The practical answer: use STK Push where you can, keep paybill references simple, and let your system handle both so no payment path is left unmatched.

How the automatic match actually happens

The mechanics are straightforward once the reference is in place. When a customer pays, Safaricom sends a payment confirmation to your system through the M-Pesa integration. Your system reads the reference from that confirmation, looks up the matching invoice, checks the amount, and marks the invoice paid - all in seconds, without anyone touching it.

The customer can be sent an automatic receipt, your ledger updates in real time, and your team sees an up-to-date picture of who has paid. The work that used to take a person an hour at the end of the day happens continuously and invisibly. This is the whole promise of automatic matching: the moment money arrives, the right invoice is settled and everyone downstream sees the truth.

Handling the payments that do not match cleanly

No system matches everything automatically, and pretending otherwise is where cheap setups fail. Customers mistype references, leave them blank, underpay, overpay, or pay the wrong account. A good system expects this and has a plan for it.

The answer is an exceptions queue. Anything that cannot be matched automatically goes into a clearly marked list for a person to resolve, using the phone number, amount and timing as clues. The point is that automatic matching handles the large majority of payments, so your team only deals with the handful that need judgement. That is realistic and honest - the aim is not zero human effort, it is turning hours of daily matching into a few minutes on the exceptions.

Common mistakes that break matching

Most matching failures trace back to a few avoidable decisions made early. Getting these right from the start saves endless trouble.

  • Designing references that are long or confusing, so customers get them wrong.
  • Relying on the amount to identify payments instead of a unique reference.
  • Not capturing Safaricom's payment confirmations reliably, so payments never reach your system.
  • Having no exceptions queue, so unmatched payments simply disappear or pile up.
  • Not checking the amount against the invoice, so underpayments slip through as fully paid.

How Upeosoft builds automatic M-Pesa matching

At Upeosoft we build M-Pesa reconciliation that matches payments to invoices automatically for Kenyan businesses. We design a clean account reference scheme with you, connect your paybill or till so Safaricom's confirmations reach your system reliably, and set up the matching logic that reads the reference, checks the amount and updates your ledger in real time.

We build a proper exceptions queue so unmatched payments are caught, not lost, and we can connect matching to your accounting, invoicing and WhatsApp receipts. If you are still matching M-Pesa payments to invoices by hand, talk to us and we will automate the part that is costing you hours.

Frequently asked questions

Why can't payments just be matched by amount?

Because amounts are not unique. If three customers each owe 2,500 shillings, a 2,500 payment could belong to any of them. Matching by amount alone guarantees confusion and mistakes. The reliable signal is a unique reference tied to a single invoice - an invoice number or account number - that the payment carries with it. The amount is a useful check, but the reference is what actually identifies the invoice.

What is an account reference, and where does it come from?

It is the text a customer enters as the account number when paying your paybill, or that your system sets automatically in an STK Push. It should uniquely identify one invoice - typically the invoice number or a customer account number your system recognises. When the payment confirmation arrives from Safaricom, your system reads this reference and knows exactly which invoice to mark paid.

What happens if a customer types the wrong reference?

The payment cannot be matched automatically, so a good system puts it in an exceptions queue rather than losing it. A person then matches it by hand using the phone number, amount and timing as clues. The aim is to make automatic matching handle the large majority of payments, so your team only touches the small number that were entered wrongly, instead of matching everything manually.

Do I need STK Push or is paybill enough?

Both can work, and many businesses use both. STK Push is easiest to match because your system controls the reference, so there is no room for customer error. Paybill and till payments rely on the customer entering the reference correctly, so matching depends on keeping that reference short and clear. A robust setup handles both paths and sends anything unmatched to the exceptions queue.

Karani Geoffrey
Karani Geoffrey
Founder & CEO, Upeosoft

Karani Geoffrey is the Founder & CEO of Upeosoft, a software and automation company rooted in Kenya. He builds custom software, AI systems, and production-grade ERPNext for businesses across East Africa, and writes about the Kenyan realities - eTIMS, M-Pesa, SHIF, unreliable internet and power - that make or break real systems.

Next step

Want this working in your business?

Upeosoft builds and hardens the systems behind this article - for real Kenyan operations, with eTIMS, M-Pesa and offline realities handled.

Keep reading

Customer Growth and MessagingBuyer's guide

Stop Losing Track of Payments: SMS Reconciliation

Every M-Pesa payment sends an SMS confirmation. Read and matched properly, those messages become a reliable record. Left in an inbox, they become a mess.

7 min readRead article →
Customer Growth and Messaging

How to Get More Customers Using AI

AI does not magically find customers. It wins you the ones you already reach by replying faster, following up without fail, and never dropping a lead.

7 min readRead article →
Customer Growth and Messaging

Why You Lose Customers After the First Sale

Most businesses pour money into finding new customers and let the ones they already won drift away in silence. That silence is the leak, and it is fixable.

7 min readRead article →