Skip to content

How to Automatically Record M-Pesa Payments from the Confirmation SMS

Every M-Pesa payment sends a confirmation SMS. A small Android gateway can forward that message to your system the instant it arrives, so payments record themselves instead of being typed in by hand.

By Karani Geoffrey, Founder & CEO, Upeosoft
In short

You install a gateway app on an Android phone that holds the paying line. When an M-Pesa confirmation SMS arrives, the app forwards it securely to your server, which parses the amount, code and account and matches it to the right invoice. The phone becomes a reliable bridge between M-Pesa and your software without needing Daraja API access.

Key takeaways
  • Every M-Pesa transaction sends a confirmation SMS that already contains the amount, code, name and account.
  • An Android gateway app can read that SMS and forward it to your backend in real time, so a person never has to retype it.
  • This works for tills and personal lines that have no Daraja C2B feed, which is where most small businesses are stuck.
  • Upeosoft's open-source SMS Gateway signs every message, queues offline, and delivers each one exactly once.
  • The backend still has to parse the message and match it to an invoice using a clean account reference.
  • It is a bridge, not a replacement for full Daraja integration when you can get it - but it closes the gap reliably.

The confirmation SMS is already a complete record

Every time someone pays you on M-Pesa, Safaricom sends a confirmation SMS. Look at one closely and you will notice it already contains everything your accounts need: the transaction code, the amount, the payer's name, the time, and often the account or reference they entered. The information exists the instant the money moves.

The problem is where that information sits. It lands in a phone's inbox, where a human has to read it and type the details into a system - or, more often, not bother, and reconcile in a rush at month end. The data is perfect; the delivery is the weak link. Fixing that delivery is exactly what an SMS gateway does.

How a phone becomes a payment gateway

The idea is simple. You dedicate an Android phone to the M-Pesa line that receives payments, and you install a small app on it. That app watches for incoming SMS from M-Pesa and forwards each one to your server over the internet the moment it arrives.

  • The paying line's SIM sits in a dedicated phone that stays on and charged.
  • The gateway app reads incoming M-Pesa messages and posts them to a URL you control.
  • Your backend receives the message, parses it, and updates the invoice or ledger.
  • Staff see the payment appear automatically, usually within seconds of the customer paying.

Why the naive version fails, and what a real gateway fixes

It is tempting to think this is a weekend script: read SMS, POST to a webhook, done. That version works in a demo and quietly loses money in production. Real conditions break it - the internet drops, the phone reboots, Android kills background apps to save battery, the same message gets sent twice, or a fake SMS tries to inject a payment that never happened.

Upeosoft's open-source SMS Gateway (github.com/Upeosoft-Limited/upeo-sms-gateway) is built for exactly those conditions. It stores messages in an encrypted on-device queue so nothing is lost when the connection fails, and retries with backoff until they land. It runs as a persistent foreground service with a scheduled backstop, so it survives battery optimisation and reboots. It signs every message with a shared secret using HMAC, so your server can reject anything that is not genuinely from your device. And it guarantees exactly-once delivery using a message hash and nonce, so one payment is never recorded as two.

The part you still have to get right: parsing and matching

Forwarding the SMS is half the job. The other half happens on your server, and it is a business decision as much as a technical one. Your backend has to parse the message text to extract the amount, code, name and reference, then match that payment to the correct invoice.

The amount alone will not identify an invoice, because two customers can owe the same figure. The reliable signal is the account reference the customer entered. If your reference scheme is clean - an invoice number, member number or account number your system recognises - matching is automatic. If it is messy, you fall back to manual matching. Designing that reference scheme well is what turns forwarded messages into a self-updating ledger.

Where this fits, and where full integration is better

The SMS gateway shines when Daraja is off the table: a personal line, a till you cannot register for C2B, or a business that needs automatic recording today. It is honest, low-cost, and it works. But it is a bridge. Where you can get a registered paybill or till and Daraja credentials, direct integration is cleaner - it gives you structured data, STK Push at checkout, and payouts.

We often deploy the SMS gateway first to stop the manual typing immediately, then move a business to full Daraja integration as it grows, or run both together for coverage. The right choice depends on your line, your volume, and how the money actually flows through your business.

How Upeosoft can help

The SMS Gateway is open source, so you can inspect exactly how it handles your payment data - the security model, the queue, the delivery guarantees are all there to read. What most businesses want, though, is the whole loop working: the phone forwarding messages, the backend parsing them correctly for your M-Pesa message format, and the payments matching your invoices in your accounting or ERP system automatically.

That is what we build. If you are drowning in manual M-Pesa reconciliation, or you cannot get Daraja on your line, talk to us and we will set up the gateway, wire the parsing to your system, and design the reference scheme so payments match themselves from day one.

Frequently asked questions

Do I need the Daraja API to record M-Pesa payments this way?

No. That is the whole point of the SMS approach. Daraja gives you a clean C2B callback, but it requires a registered paybill or till and API credentials, and it is not available on a personal M-Pesa line at all. The confirmation SMS, on the other hand, arrives for every payment to any line. A gateway app reads that SMS and forwards it, so you can record payments even when Daraja is not an option.

Is reading the SMS reliable enough to trust with money?

The SMS itself is as reliable as M-Pesa - it arrives for every completed transaction. The risk is in the forwarding and parsing. A serious gateway handles that: it queues messages when the internet is down and sends them when it returns, it signs each message so your server knows it is genuine, and it guarantees each payment is delivered once and only once so nothing is missed or double-counted.

What does my server actually receive?

It receives the raw text of the SMS along with metadata: the sender (for example MPESA), a timestamp, the SIM slot, a hash of the message and a signature. Your backend then parses the text to pull out the amount, the transaction code, the payer name and the account reference, and uses those to update the right invoice or ledger entry.

Can one phone handle payments for a busy business?

Yes, for most SMEs a single dedicated Android phone holding the paying line is enough, because SMS volume is low compared to the phone's capacity. The gateway runs as a persistent background service and keeps working across reboots. For higher volume or redundancy you can run more than one line, but a busy shop or clinic is comfortably served by one.

How is this different from full M-Pesa integration?

Full integration uses Safaricom's Daraja API to receive structured payment data directly, which is cleaner and supports STK Push and payouts. The SMS gateway is a pragmatic bridge for the many businesses that cannot get Daraja on their line, or want automatic recording today without waiting on paybill registration. Many businesses start with SMS and move to Daraja later, or run both.

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

Money and Financial Control

How to Reconcile M-Pesa Till Payments Without Daraja API Access

Plenty of Kenyan businesses take payments on a till or personal line with no Daraja feed. You are not stuck with manual reconciliation - the confirmation SMS can be turned into an automatic record.

6 min readRead article →
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 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.

7 min readRead article →