Most Kenyan customers would rather pay with M-Pesa than type card details. If your website, online shop, booking page or app can send an M-Pesa prompt to the customer's phone and confirm the payment on its own, you sell more and spend less time checking messages and matching payments by hand.
This guide explains how online M-Pesa payments work, what you need before you start, and the steps to go live.
How online M-Pesa payments work
There are two common ways a website collects M-Pesa:
- STK Push (also called Lipa na M-Pesa Online or an M-Pesa prompt). The customer enters their phone number on your checkout page. Their phone shows a pop-up with your business name and the amount, and they confirm with their M-Pesa PIN. Your system is told whether the payment went through, so the order can be marked as paid at once.
- Paybill or Till confirmations. The customer pays your Paybill or Till number from the M-Pesa menu as usual, and M-Pesa sends the payment details to your system so it can match the payment to an order or account number.
Both are provided by Safaricom through its developer platform, Daraja. Most websites use STK Push for checkout and keep Paybill confirmations for customers who prefer to pay from the menu.
What you need before you start
- Your own M-Pesa business number. A Paybill or a Till (Buy Goods) number registered to your business. The money is paid into this number, so it must be in your business's name.
- A website or app that can call an API. Online shops, booking systems, school or billing software and custom apps can all do this. If you do not have a developer, a payment link (see below) works without any code.
- A secure address for payment results. M-Pesa sends the result of each payment to a web address (a "callback URL") on your system. It must use HTTPS.
- Your business documents. Expect to verify your business before you can take live payments.
Step 1: Decide between building it yourself or using an integration service
You can connect directly to Safaricom's Daraja API. That means creating an app on the Daraja portal, testing in the sandbox, applying to go live with your Paybill or Till, and then writing and maintaining the code that requests payments, receives callbacks, retries failed messages and keeps records.
The alternative is an integration service that has already done that work. You connect your own Paybill or Till once, then call one simple API or share payment links from a dashboard. A good integration service does not hold your money: Safaricom pays each transaction straight into your own account.
Step 2: Connect your Paybill or Till
Whichever route you choose, your business number must be linked so payment prompts carry your business name and settle into your account. Keep your M-Pesa organisation portal login safe; only the business owner or an authorised person should handle it.
Step 3: Add M-Pesa to your checkout
For a website or app:
- Add a "Pay with M-Pesa" option to your checkout and ask for the customer's phone number in the format
07XXXXXXXXor+2547XXXXXXXX. - When the customer presses Pay, your system requests an STK Push for the order amount and a reference such as the order number.
- Show a message such as "Check your phone and enter your M-Pesa PIN".
- Wait for the result on your callback URL (or a webhook from your integration service), then mark the order as paid and show a receipt.
If you do not have a developer, create a payment link or QR code for an amount and send it by WhatsApp, SMS or email, or print the QR code at your counter. The customer opens it and gets the same M-Pesa prompt.
Step 4: Test before you go live
Test with small amounts and check each case:
- the customer pays successfully;
- the customer cancels or enters a wrong PIN;
- the customer does not respond before the prompt times out;
- your server is briefly down when the result arrives.
Your system should never mark an order as paid until it has a confirmed result, and it should handle the same notification arriving twice without recording the payment twice.
Step 5: Reconcile every day
Even with automation, someone should compare the day's paid orders with your M-Pesa statement. A dashboard with a list of payments, search by phone number or receipt code, and CSV export makes this a five-minute job.
Security tips
- Keep API keys and passwords in your server settings, never in website code that visitors can see.
- Only trust payment results that arrive on your callback or a signed webhook, never a "paid" message sent from the customer's browser.
- Give staff their own logins with only the access they need.
- Kenya's Data Protection Act, 2019 applies to the phone numbers and names you collect, so keep them secure and use them only for the purpose you collected them for.
Frequently asked questions
Do I need a Paybill or can I use a Till number?
Either works for STK Push. A Paybill lets customers enter an account number, which helps when you match payments to invoices or customer accounts. A Till is simpler for shops and one-off sales.
Does the money go to the integration provider first?
It should not. With a non-custodial service such as JMSURF PAY, Safaricom M-Pesa pays each transaction straight into your own Paybill, Till or bank account. The software only requests payments and reports the results.
Can I accept M-Pesa without a developer?
Yes. Payment links and QR codes let you collect a set amount from a dashboard and share it by WhatsApp, SMS or email, with no code on your website.
What happens if the customer does not enter their PIN?
The prompt expires and your system receives a failed or cancelled result. Your checkout should let the customer try again or choose another payment method.
Take M-Pesa on your website with JMSURF PAY
JMSURF PAY connects your own Paybill, Till or bank account to your website, POS or app with STK Push, payment links and QR codes, Paybill confirmations, reports and signed webhooks, through a dashboard or one REST API. It is not a payment gateway and never holds your money. The website lists flat monthly plans with no fee per payment, starting with a 14-day free trial, and the API documentation shows every endpoint.
