How to Accept M-Pesa Payments on Your Website

Many customers in Kenya already pay with M-Pesa on their phones. If your website asks them to pay by card only, you lose people who would have bought. Adding M-Pesa to your checkout fixes that.
This guide explains what you need, how the payment flow works and how to test it before real money moves. It is written for business owners, so you can follow the plan and ask your developer the right questions.
What M-Pesa on a website means
A customer enters their phone number at checkout. Their phone shows a prompt asking for their M-Pesa PIN. They approve it, and your site marks the order as paid. That is the whole experience for the customer.
Behind the screen, your website talks to Safaricom through a developer service called Daraja. The most common option for online shops is the prompt on the customer phone, often called STK Push. Daraja also supports other payment types, so ask your developer which one fits your business.
What you need before you start
- A registered business. Safaricom needs to know who is receiving the money.
- An M-Pesa business account. This is usually a Paybill or a Till number. Safaricom tells you which fits your case.
- A Daraja developer account. Your developer creates an app there and receives the keys for testing.
- A website with https. Safaricom sends payment results back to your site, and the address must be secure and public.
- A clear product list and prices. Use one currency and show the total before the customer pays.
Rules and requirements change, so always check the current steps on the Safaricom developer portal. We do not repeat them here because old advice causes delays.
How the payment flow works
| Step | What happens | Who does it |
|---|---|---|
| 1 | Customer fills the cart and enters a phone number | Customer |
| 2 | Your site asks Safaricom to send a payment prompt | Your website |
| 3 | The prompt appears on the customer phone | Safaricom |
| 4 | Customer enters their PIN and approves | Customer |
| 5 | Safaricom sends the result to your callback address | Safaricom |
| 6 | Your site marks the order paid and sends a receipt | Your website |
Step 5 matters most. Never mark an order as paid because the customer clicked a button. Mark it paid only when the confirmation from Safaricom arrives. Otherwise anyone can claim to have paid.
From test to live
Work in two stages.
Stage 1: the test environment
Daraja gives developers a sandbox with test numbers and test keys. No real money moves. Your developer builds the checkout, the callback and the order updates here.
Stage 2: going live
When the test flow works, you apply to go live with your real business details. Safaricom reviews the request. Then your developer swaps the test keys for the live ones. Plan for some waiting time and do not promise a launch date to customers before approval arrives.
Design the checkout for phones
Most of your customers will pay from the same phone they browse on. Make that easy.
- Ask for the phone number in the right format and show an example.
- Tell the customer to watch their phone for a prompt.
- Show a clear waiting message with a short timer, not a blank screen.
- Handle a cancelled prompt with a friendly message and a retry button.
- Offer a second option, such as card or bank transfer, for customers without M-Pesa.
- Show the receipt on screen and send it by email or WhatsApp.
If you want customers to ask questions before they pay, add a WhatsApp button near the checkout.
What to test before launch
- A successful payment updates the order and sends a receipt.
- A wrong PIN or a cancelled prompt leaves the order unpaid.
- A customer with too little balance sees a clear message.
- A slow reply from Safaricom does not create a double order.
- Two customers paying at the same time both get the right order.
- The amount charged equals the total on the screen.
- You can find every payment in your records and match it to an order.
After launch, make one small real payment yourself and refund it. Do this before you announce the feature.
Keep your records clean
Every payment needs a record that links the M-Pesa transaction code to the order. Check these records weekly against your M-Pesa statement. If a payment arrives and no order matches it, follow up with the customer quickly. Good records also make tax time and refunds much easier.
Choosing between Paybill and Till
A Paybill suits businesses that want customers to enter an account number, such as an invoice or a student ID. A Till suits shops with simple sales. Safaricom controls the options and the approval, so ask them which one you qualify for. Your developer can then build the checkout for that choice.
Common mistakes
- Marking orders paid before the confirmation arrives.
- Skipping the test stage because the deadline is close.
- Showing prices in one currency and charging in another.
- Offering no other payment option.
- Forgetting a refund and support process.
- Storing keys in places where other people can read them.
Questions to ask your developer
You do not need to read code to manage this work. Ask these questions and listen to the answers.
- Which payment type will you use, and why does it fit my shop?
- How will you confirm a payment before marking an order paid?
- What happens if the customer closes the page during payment?
- Where are the keys stored, and who can see them?
- How will I see a list of payments and match them to orders?
- What is the plan if Safaricom is slow or unavailable for an hour?
A developer who answers clearly has done this before. A vague answer is a warning sign.
After launch: support and refunds
Payments will go wrong sometimes. A customer pays twice, a prompt times out or someone types the wrong number. Decide in advance how you will handle each case.
- Publish a support number or WhatsApp contact on the checkout page.
- Reply to payment questions the same day.
- Keep a written refund process, with who approves it and how long it takes.
- Look at failed payments each week to spot patterns.
Customers forgive a problem when you fix it fast. They do not forgive silence.
Planning for more than one country
Many businesses sell in several markets. M-Pesa covers Kenya, but your customers elsewhere use other tools. In Cameroon, for example, people pay with MTN MoMo and Orange Money. Our guide on accepting MTN MoMo and Orange Money explains that side. A good checkout can offer each customer the option they already trust.
Building this with us
We build payment flows for clients on four continents. Our studio is in Buea, Cameroon, and we have shipped over 100 products. You can read about how we work in Kenya on our web design Kenya page.
A website with payment integration starts from $2,000, while a simple site starts at $500 and a business site runs $800 to $1,500. The pricing page shows each tier. Starter sites take 2 weeks and bigger projects take 3 to 6 weeks. Payment is 50% to start and 50% on delivery, with 2 to 3 revisions.
Message us on WhatsApp with your product list and we will tell you what the checkout needs.
Need a website or app like this?
Tell us about your project on WhatsApp. You get a free call and a fixed quote.