Skip to content
Guides

How to set up a MikroTik hotspot with M-Pesa payments

A MikroTik hotspot that sells Wi-Fi by M-Pesa needs four things: a working router, a hotspot server, a captive portal that can take payments, and something that creates and expires logins when money arrives. Here is how each part works, and the short way to do it with JMSURF ISP.

What you need

  • A MikroTik router (hAP, RB951, RB2011, CCR or similar) on RouterOS 7 if possible.
  • An internet line into the router's WAN port, and access points or the router's own Wi-Fi for customers.
  • An M-Pesa Paybill or Till for collections, ideally with Safaricom Daraja API access (for STK push). You can start without Daraja by collecting through a gateway.
  • A computer or phone with Winbox, WebFig or a terminal to reach the router.

Step 1: get the router online

Connect the WAN port to your internet line and make sure the router itself can reach the internet (ping 8.8.8.8 from the terminal). Put the ports and wireless interfaces customers will use on one bridge. Update RouterOS to a current stable version: old versions have known security problems.

Step 2: create the hotspot server

On a plain MikroTik you run /ip hotspot setup on the customer bridge. The wizard asks for the address range, a DHCP pool, an SMTP server (leave empty), DNS servers and a DNS name for the login page. It creates a hotspot server, a DHCP server and a NAT rule so customers can reach the internet once logged in.

With JMSURF ISP you skip the wizard: add the router in the dashboard, paste the one-line setup command into the terminal, and the platform builds a private tunnel and sets up Hotspot, DHCP, speed limits and the portal pages for you. It also adds a rule so FastTrack does not bypass your speed limits, a common reason plans run faster than sold.

Step 3: the captive portal

The MikroTik serves its own login page from the hotspot folder. To sell by M-Pesa, that page must show your plans and send the customer to a payment page, then log them in when the payment is done. The payment page lives on the internet, so it must be in the hotspot's walled garden (the list of addresses customers may open before logging in). Forgetting the walled garden is the most common reason a portal "does nothing" when customers tap Pay.

JMSURF ISP installs portal pages on the router, keeps the walled garden right, and gives you more than 40 designs with your logo, in English and Kiswahili.

Step 4: take the payment

With Daraja access on your Paybill or Till, a payment works like this: the portal asks for the phone number, the server sends an STK push request to Safaricom, the customer enters their PIN, and Safaricom calls your server back with the result. Only a successful result should create a login. In JMSURF ISP you paste your Daraja details once under Payment settings, and every prompt goes to your own account.

Step 5: create and expire logins automatically

After payment, the system creates a hotspot user on the router with the plan's limit (uptime for time plans, bytes for data bundles), a speed profile and the number of devices, then signs the device in. When the limit is reached the router ends the session. JMSURF ISP also remembers the device for the life of the plan, so a phone that drops off is signed back in automatically, and sends the customer an SMS with their account and password.

Step 6: test like a customer

  1. Join the Wi-Fi with a phone that has never connected. The portal should open by itself.
  2. Buy the cheapest plan. Time how long until you can browse (it should be seconds).
  3. Turn Wi-Fi off and on: you should be back online without paying again.
  4. Let the plan run out and check you are cut off and see the portal again.
  5. Check the payment in your M-Pesa statement and in the dashboard.

Common problems

  • Portal does not open: the device is using a private DNS, or the hotspot is on the wrong bridge.
  • Connected but no internet: missing NAT rule, the router has no internet, or the DNS is wrong.
  • Pay does nothing: the payment page is not in the walled garden.
  • Speed higher than the plan: FastTrack is bypassing the queues.

JMSURF ISP's Fix a problem page walks through each of these with a read-only check of your router.

Questions ISPs ask

Can I use a Till instead of a Paybill?
Yes. STK push works with a Till (Buy Goods) or a Paybill, as long as Daraja access is set up for it.
Do I need Daraja to sell Wi-Fi by M-Pesa?
For STK push on your own Paybill or Till, yes. Without it you can collect through a payment gateway such as PayHero or JMSURF PAY.
How long does setup take with JMSURF ISP?
Linking the router takes about a minute; adding packages and payment details usually takes under an hour.

Your network, billing itself by tonight.

Sign up, paste one command into your MikroTik, connect your own M-Pesa Paybill or Till and add your packages. Customers pay and connect on their own.