M-Pesa integration for your website: how it works and what you need

Customers in Kenya expect to pay with M-Pesa. If your website or system can't accept it directly, you end up asking people to send money manually, then checking messages and matching codes by hand. M-Pesa integration fixes that: the customer pays from their phone, and your website records the payment automatically. Here's how it works and what you need to get started.
How M-Pesa integration works
Safaricom offers developers a set of APIs called Daraja. Your website or system talks to these APIs to start payments and receive confirmations. The most common setups are:
M-Pesa Express (STK Push)
The customer enters their phone number on your checkout page. A payment prompt pops up on their phone, they enter their M-Pesa PIN, and the payment is done. They never leave your website or type a paybill number. This is the smoothest option for online shops, bookings and deposits.
Customer to business (C2B)
The customer pays to your paybill or till number from their M-Pesa menu as usual, and Safaricom notifies your system of each payment. This suits businesses where customers already pay by paybill, such as rent, school fees or utility-style accounts.
Business to customer (B2C)
Your system sends money to customers, for refunds, payouts or commissions. It needs extra approval and is used less often by small businesses.
How a payment gets confirmed
This is the part that matters most. After the customer pays, Safaricom sends a confirmation to a secure address on your server, called a callback URL. Your system checks the result, saves the M-Pesa receipt number and marks the order or invoice as paid. A good integration never trusts a payment until that confirmation arrives, and it handles cases where the customer cancels, enters the wrong PIN or has insufficient funds.
What you need for M-Pesa integration
- A paybill or till number registered to your business, from Safaricom.
- A Daraja account on the Safaricom developer portal, where the integration is first built and tested in a sandbox.
- Go-live approval from Safaricom, which links your paybill or till to your live app.
- A secure website or system on HTTPS hosting that can receive the payment callbacks.
- Somewhere to record payments, such as your orders, invoices or POS, so your records stay accurate.
Where M-Pesa integration helps most
- Online shops: customers pay at checkout and orders are marked paid instantly.
- Bookings and appointments: collect a deposit to cut no-shows.
- Schools and clubs: fees and memberships recorded against the right account.
- Rentals and property: rent payments matched to tenants automatically.
- POS systems: in-store M-Pesa payments reconciled with sales. Read our guide to choosing a POS system in Kenya.
Common mistakes to avoid
- Marking orders as paid before Safaricom's confirmation arrives
- Storing API keys inside website code that others can see
- Not handling failed or cancelled payments clearly for the customer
- No record of receipt numbers, which makes reconciliation and refunds painful
How long does it take?
Building and testing the integration usually takes days rather than weeks, depending on how complex your checkout is. Safaricom's go-live approval can add time, so it's worth starting that paperwork early.
What a good checkout looks like
The technical connection is only half the job. The customer experience decides whether people actually complete the payment:
- Clear instructions. Tell the customer to check their phone for the M-Pesa prompt and enter their PIN.
- Accept common number formats. People type 07..., 01..., +254... or 254.... Your form should handle all of them.
- Live status. Show "Waiting for payment" and update automatically to "Paid" when the confirmation arrives, instead of making people refresh.
- A retry option. If the prompt times out or fails, let the customer try again with one tap.
- A receipt. Show and email the M-Pesa receipt number with the order details.
- A fallback. Display your paybill or till number for customers who prefer to pay manually, with clear account instructions.
Keeping payments secure
Payment systems attract fraud attempts, so security matters from day one. Keep API keys and passwords on the server, never in the browser. Use HTTPS everywhere. Check every callback carefully and confirm the amount and account match the order before marking it paid. Limit who can view payment records, and keep logs so you can trace any problem. If you take card payments too, use a licensed payment provider rather than handling card details yourself.
M-Pesa integration: frequently asked questions
Do I need a paybill, or will a till work?
Both can be integrated. A paybill suits payments tied to an account number, such as invoices or fees. A till suits straightforward purchases. Your business model decides which fits better.
Can M-Pesa be added to my existing website?
Usually yes. As long as the site runs on secure hosting and can receive callbacks, the payment flow can be added to your current checkout or booking form.
Add M-Pesa to your website or system
We build M-Pesa integration into new websites, online shops and business systems, and add it to existing ones. See our website design and business systems services, or request a quote and tell us how your customers pay today.




