Blog / Payments
Accept M-Pesa Payments on Your Website
How to accept M-Pesa on your website: Paybill vs Till, the STK push prompt, Daraja vs gateways or banks, payment callbacks, failed prompts and testing.
Titus Kaleli · · 6 min read
To accept M-Pesa on your website, you need a Safaricom Paybill or Till number and a way for your site to send an M-Pesa prompt to the customer's phone, then receive confirmation when they pay. You can connect to Safaricom's Daraja API directly, or go through a payment gateway or your bank, which handles much of that connection for you. Whichever route you choose, the important work is making sure every payment is matched to the right order.
Paybill or Till: which one you need
Safaricom offers two main types of business number for receiving payments.
- Paybill. The customer pays to a business number and enters an account number. On a website, the account number is usually the order number, which makes matching payments easier.
- Till number (Buy Goods). The customer pays to a single till number with no account number. Tills are common in shops and are simple for walk-in customers.
Both can work for online payments. Which one suits you, and what documents you need to apply, depends on your type of business, so check the current requirements with Safaricom or your bank. If you already have one, ask your developer whether it can be used for online checkout before applying for another. If you are planning a new shop, payments should be designed in from the start as part of your online store build, not added at the end.
What the customer sees: the M-Pesa prompt
The easiest checkout for customers uses the M-Pesa prompt, known technically as STK push. It works like this:
- The customer enters their phone number at checkout and taps pay.
- Your website asks M-Pesa to send a payment request to that phone.
- A prompt appears on the customer's phone showing the amount and who they are paying.
- The customer enters their M-Pesa PIN to approve.
- M-Pesa tells your website whether the payment went through, and the order page updates.
Compare that with asking customers to leave your site, open the M-Pesa menu, type your Paybill and order number by hand, then paste a confirmation code back into a form. That manual method is still useful as a fallback, but it leads to typing mistakes and abandoned orders.
Daraja directly, or through a gateway or bank
Safaricom Daraja
Daraja is Safaricom's developer platform for M-Pesa. It lets your website talk to M-Pesa directly using your own Paybill or Till. You get the most control and no middleman, but your developer has to build and maintain everything: the payment request, confirmation handling, security and error cases. Moving from testing to live payments also involves an approval process with Safaricom, so allow time for it.
Payment gateways
Gateways such as IntaSend, Kopo Kopo, Pesapal and Flutterwave sit between your website and the payment networks. They typically offer ready-made checkout pages or plugins, a dashboard to see payments, and often card payments in the same place. The trade-off is that you depend on their service and terms, and money may pass through their account before it reaches yours. Ask how and when they settle funds to you.
Your bank
Some banks offer their own developer platforms, such as Equity Jenga and KCB Buni. These can be used to send M-Pesa prompts and receive the money into your bank account. This can suit a business that already banks there and wants funds to land directly in its account.
There is no single right answer. Ask each option about settlement times, charges, which payment methods they support, what reports you get, and who helps you when a payment goes wrong.
What happens behind the scenes
Sending the prompt is the easy part. The careful work is everything that follows.
The payment confirmation
When the customer approves or cancels the prompt, M-Pesa sends a message to an address on your website, called a callback. It says whether the payment succeeded and, if it did, includes details such as the amount and the M-Pesa receipt number. Your website should only mark an order as paid when a successful confirmation arrives, never just because the customer tapped pay.
Matching payment to order
Each payment request should carry a reference that ties it to one order. When the confirmation comes back, the site finds that order, checks the amount matches, records the receipt number and marks it paid. Keep the receipt number on the order: it is what you and the customer will quote if there is ever a dispute.
Failed, cancelled and timed-out prompts
Not every prompt ends in a payment. The customer might cancel, enter the wrong PIN, not have enough balance, or simply not respond before the prompt expires. Sometimes the confirmation is delayed. A well-built checkout:
- Shows a clear message when a payment fails and lets the customer try again
- Waits for the confirmation instead of guessing success or failure
- Can ask M-Pesa for the status of a payment if no confirmation arrives
- Never records the same payment twice, even if a confirmation is sent more than once
- Offers a fallback, such as paying manually with the order number as the account
Reconciliation
At the end of each day or week, someone should compare the orders marked paid on the website with the payments in your M-Pesa statement or bank account. A good system makes this a quick check rather than an afternoon with a spreadsheet. You also need a process for payments that arrive without a matching order, such as a customer paying your Paybill directly with the wrong account number.
Cards alongside M-Pesa
Some customers prefer to pay by card, especially companies, buyers abroad and visitors to Kenya. If you sell to them, offer card payments alongside M-Pesa. Most gateways support both through one integration, which keeps your checkout and reports in one place.
Card payments come with strict security standards. It is usually better to let a payment provider collect card details on its own secure page or form than to handle card numbers on your own website.
Test in a sandbox before you go live
Daraja and most gateways offer a sandbox: a test environment where you can run payments without real money. Use it to try as many paths as it allows:
- A successful payment
- A cancelled prompt
- A customer who does not respond
- A confirmation that arrives late, or more than once
- An amount that does not match the order
Once the sandbox works, run a few small real payments on the live system before announcing the new checkout. Check that each one shows correctly in your website's orders, in your M-Pesa or bank statement, and in any receipt sent to the customer. Repeat these checks after any major update to the site or the payment provider's settings.
A short checklist before launch
- Your Paybill or Till is active and approved for the route you chose
- Orders are only marked paid after a successful confirmation
- Every payment is stored with its receipt number against one order
- Failed and timed-out prompts show a clear message and a retry
- Someone owns daily or weekly reconciliation
- Customers have a way to reach you if a payment goes wrong
Getting M-Pesa working on your site
We build online stores with M-Pesa checkout, including payment confirmation, order matching and failed-payment handling. You can see how we approach online store development in Kenya. If you also sell in a physical shop, SparkPOS, our point of sale system, sends M-Pesa prompts that pay straight into your bank account through Equity Jenga or KCB Buni. To talk through your setup, book a call with us or message us on WhatsApp.
Want this working in your business?
Book a discovery call →