Payments
How to add M-Pesa payments to your website

Most Kenyan customers would rather pay with M-Pesa than a card. If your website can send the payment prompt straight to their phone, you’ll close more sales. Here’s how it works, in plain language.
What is an M-Pesa STK push?
An STK push is the pop-up that appears on a customer’s phone asking for their M-Pesa PIN. On a website, it works like this:
- The customer enters their phone number at checkout.
- Your website asks Safaricom to send a payment request to that number.
- The customer sees the prompt on their phone and enters their PIN.
- Safaricom tells your website whether the payment succeeded, and your site confirms the order automatically.
You can try a real KSh 1 payment on our site to see exactly what your customers would experience.
What you need
- A till or paybill number. Payments go straight to your business account.
- A Safaricom Daraja account. Daraja is Safaricom’s system that lets websites connect to M-Pesa. It gives you the keys your website uses.
- A website with SSL (https). Safaricom only sends payment results to secure addresses.
- A server-side script. The part that talks to Safaricom must run on your server, never in the visitor’s browser, so your keys stay secret.
Mistakes to avoid
- Putting your keys in the website code. Anyone can read them and misuse your account. Keep them in a private file on the server.
- Trusting the browser. Only mark an order as paid when Safaricom confirms it, never just because the customer clicked a button.
- No handling for failed payments. Customers cancel, enter the wrong PIN or have low balance. Your site should explain what happened and let them try again.
- No record of payments. Save every M-Pesa receipt number with the order, so you can match payments and handle disputes.
M-Pesa, cards or both?
For most Kenyan businesses, M-Pesa should come first. If you also sell to customers abroad or corporate clients, add card payments through a gateway like Paystack or PayPal alongside it.
Customers only type their M-Pesa PIN on a site they trust. Before you add payments, make sure your site uses https, loads quickly and looks right on a phone. Run a free website check to see where your site stands.
Can I add it to my existing website?
Usually, yes. Whether your site is custom-built or on WordPress, an M-Pesa checkout can be added without rebuilding everything. We’ve built it into online shops and a Wi-Fi hotspot billing system that connects customers automatically once they pay.