MikroTik hotspot with M-Pesa payments: how it works
· 3 min read
A MikroTik hotspot holds every new device on a login page until it has a valid username and password. M-Pesa billing adds a payment step in front of that: the customer picks a bundle, approves an STK prompt, and once the payment is confirmed the router is given a voucher for exactly that bundle and logs them in. The pieces that make it reliable are the walled garden, payment verification and recovery when phones drop off mid-payment.
The pieces inside the router
RouterOS has a built-in hotspot. Turn it on for a WiFi or LAN interface and every new device is redirected to a login page. Behind that page sit a few settings worth understanding:
- Hotspot profile: how customers log in, and the page they see.
- User profiles: one per bundle, carrying the speed limit and how many devices may share a code.
- Users (vouchers): a code plus a time or data limit. The code is the customer's password.
- Walled garden: the short list of addresses a customer may reach before paying. Without it, the payment page cannot even load.
Where M-Pesa fits
M-Pesa does not talk to your router. It talks to a server, so the payment page loads from that server, through the walled garden, and the server talks back to the router. A typical purchase goes like this:
- The customer joins your WiFi and the login page opens on its own.
- They choose a bundle and enter their phone number.
- An M-Pesa prompt (STK push) appears on their phone and they enter their PIN.
- M-Pesa confirms the payment to the server, which checks it and matches it to the order.
- The server creates a voucher on the router for that bundle and shows the code, and the page logs the customer in.
- The same code arrives by SMS, so they can get back on later or on another device.
Why your router does not need a public IP
Most Kenyan internet connections put your router behind the provider's NAT, so nothing on the internet can reach it directly. The answer is for the router to call out instead: with PAY N BROWSE each MikroTik keeps an encrypted WireGuard tunnel to us, so voucher pushes, health checks and management all travel down a connection the router itself opened. No port forwarding and no public address.
Three things that go wrong, and how to handle them
Fake payment confirmations
If your system believes any message that says "paid", someone will eventually send one. A payment should only count once it has been confirmed with M-Pesa and matched to an order you created, for the amount you set, and it should count exactly once however many times the confirmation arrives.
The customer paid but is not online
Phones change networks, screens lock, and people close the page too early. The payment is still real. The customer needs a code by SMS, and a way to recover a purchase with their M-Pesa transaction code. If a payment cannot be fulfilled automatically, it should wait somewhere you can see it and approve it, not vanish.
Browser warnings on the login page
Phones, iPhones especially, warn loudly about a login page without a valid certificate, and some customers will stop there. Serving the page over HTTPS with a trusted certificate, and renewing it before it expires, removes that doubt.
Speed limits and fair sharing
Each bundle's user profile carries a rate limit, for example 5 Mbps down for a cheap hourly bundle and more for a day pass. Without limits, one person downloading a film slows everyone else, and the slow ones ask for refunds. Set limits that keep the evening rush usable, then adjust from what you see.
Setting it up
You can build all of this by hand in WinBox, write the login page, host a payment server and integrate with M-Pesa yourself. Or connect the router to PAY N BROWSE: we set up the hotspot, profiles and walled garden step by step, deploy the payment page with a trusted certificate, and handle M-Pesa, vouchers and SMS. Any MikroTik on RouterOS 7 works, including hAP, hEX, RB750, RB951, RB2011 and CCR models. If the router already sells vouchers, a read-only scan brings the existing profiles and codes across so customers holding codes keep browsing.
Connect a MikroTik in a few minutes. It works behind any internet provider.
Connect your MikroTikQuestions people ask
Does MikroTik support M-Pesa payments?
Not on its own. RouterOS provides the hotspot and vouchers; a billing server handles M-Pesa and creates the voucher on the router after the payment is confirmed. PAY N BROWSE is that server.
Which RouterOS version do I need?
RouterOS 7. We manage routers through the RouterOS REST API, which RouterOS 6 does not have.
What is a walled garden on a MikroTik hotspot?
The list of addresses customers can reach before they log in. The payment page and M-Pesa need to be on it, or the page cannot load.
Can I keep the vouchers I already sold?
Yes. Adopting a router reads the existing profiles and users without changing anything, so codes your customers hold keep working.
Keep reading
UniFi hotspot with M-Pesa payments
How to sell WiFi on a UniFi site with M-Pesa: the guest portal, pre-authorised addresses, what the customer sees, and switching over without losing vouchers.
How to start a WiFi hotspot business in Kenya
A practical guide to selling WiFi in Kenya: the internet connection, the router, M-Pesa payments, pricing your bundles and keeping customers online.