WiConnect

MikroTik hotspot billing with M-Pesa: how it works

How a phone goes from "joined the Wi-Fi" to "paid and browsing" on a MikroTik hotspot, and what to get right so payments switch customers on automatically.

WiConnect team · · 2 min read

MikroTik's built-in hotspot is the backbone of most pay-as-you-go Wi-Fi in Kenya. On its own, though, it only knows usernames and passwords. Billing software adds the part that matters to your business: taking M-Pesa, deciding who is allowed on, and for how long.

The flow, step by step

  1. The phone joins your Wi-Fi. The MikroTik hotspot catches its first web request.
  2. The captive portal opens. Instead of MikroTik's default login page, the phone is sent to a branded page listing your packages.
  3. The customer picks a package and enters their M-Pesa number. An STK push prompt appears on their phone.
  4. They enter their PIN. The payment provider (TinyPesa, PayHero or Safaricom Daraja) sends a confirmation to the billing system.
  5. The billing system checks the payment – right amount, right account, not a duplicate – and only then creates or extends the customer's access on the router.
  6. The phone is logged in automatically at the speed of the package.
  7. When time or data runs out, the router removes them and the portal shows up again.

What to get right on the router

  • Walled garden. Before payment, the phone must still be able to reach your portal and the payment provider. Everything else stays blocked.
  • User profiles with speed limits. Each package maps to a profile with a rate limit, for example rate-limit=2M/5M for 2 Mbps up and 5 Mbps down.
  • Shared users. Decide whether one account may be used on more than one device at a time. One is usually right for cheap passes.
  • Isolation. Keep hotspot clients on their own network so they can't reach your router's management or your office PCs.
  • A dedicated API user for the billing system, with only the rights it needs, instead of the admin account.

Never trust "I have paid"

The most common fraud on manual hotspots is a fake M-Pesa SMS or a screenshot. Automated billing removes this, but only if the system verifies the payment with the provider before switching anyone on. Callbacks can be faked too, so a good system checks each callback against the provider and ignores duplicates.

WiConnect activates a customer only after the payment is confirmed with the provider, records the M-Pesa receipt, and never counts a test or simulated payment as revenue.

Vouchers still have a place

Some customers don't use M-Pesa, and some venues (hotels, offices) prefer to hand out codes. A good setup lets you print vouchers for the same packages and redeem them on the same portal.

Remote routers

If your routers are spread across sites, you need a way to reach them from the billing system: a public IP, or better, a VPN tunnel that the router opens to the server. That way routers behind CGNAT still work, and no router management port is exposed to the internet.

Checklist

  • Portal opens by itself on Android and iPhone.
  • Payment prompt arrives within seconds.
  • Paid customers browse at the right speed; unpaid ones can only reach the portal.
  • Access ends on time, and the customer gets a reminder before it does.
  • Every payment has a receipt number you can find later.

More guides