How to Integrate M-Pesa Into Your Website: Options Explained
On this page
For most Kenyan customers, M-Pesa is the default way to pay. If your website takes orders, bookings or fees, integrating M-Pesa properly can be the difference between a smooth sale and a customer who gives up. This guide explains the main integration options in plain language.
What are the ways to accept M-Pesa online?
1. Manual payment instructions
The site shows your Paybill or Till number and the customer pays from their phone, then your team confirms manually. It is simple, but slow, error-prone and frustrating at scale.
2. STK Push through the Daraja API
The customer enters their phone number at checkout and receives a payment prompt on their phone. They enter their PIN, and your website receives an automatic confirmation. This is the smoothest experience and the most common choice for online stores and booking systems.
3. Paybill or Till confirmations (C2B)
Customers pay to your Paybill or Till from the M-Pesa menu, and Safaricom notifies your website of each payment automatically, so it can be matched to an order or account. Useful for invoices, fees and accounts where customers pay in their own time.
4. Payment gateways and plugins
Third-party gateways and e-commerce plugins bundle M-Pesa with card payments. They are faster to set up but may add fees, limit customisation or route payments through the provider before reaching you.
How do the options compare?
| Option | Customer experience | Automation | Setup effort |
|---|---|---|---|
| Manual instructions | Leave site, pay, wait | None | Lowest |
| STK Push (direct) | Prompt on phone, instant | Full | Moderate |
| C2B confirmations | Pay from M-Pesa menu | Full matching | Moderate |
| Gateway or plugin | Usually smooth | Full | Low to moderate |
What do you need before integrating?
- A registered business with an M-Pesa Paybill or Till number (Lipa na M-Pesa).
- A Safaricom Daraja developer account to build and test in the sandbox.
- Production credentials approved for your shortcode before going live.
- A website or system on secure HTTPS hosting that can receive callbacks reliably.
- A developer to build the payment flow, confirmations and error handling.
How does an STK Push checkout work, step by step?
- The customer chooses M-Pesa and enters their phone number.
- Your server sends a payment request to Safaricom.
- The customer receives a prompt and enters their PIN.
- Safaricom sends the result to your server's callback address.
- Your system marks the order paid, sends a confirmation and notifies your team.
What makes an M-Pesa integration reliable?
- Callback handling: confirmations must be processed once, even if they arrive twice.
- Status checks: if a callback is delayed or lost, the system queries the transaction status.
- Timeouts and retries: customers can resend the prompt easily.
- Matching: each payment is linked to the correct order, invoice or account.
- Logging and alerts so problems are noticed immediately.
- Security: credentials stored safely, never exposed in the website's front end.
Plugin or custom integration?
If you run a standard WooCommerce store, a reputable plugin may be enough. Choose a custom integration when payments must connect to bookings, portals, subscriptions or accounting software, when you need reliable reconciliation at volume, or when you want full control over the customer experience and your funds flow.
What does it cost to integrate M-Pesa?
There are two kinds of cost. The first is the development work to build the payment flow, confirmations, error handling and reconciliation, which depends on how M-Pesa connects to your orders, bookings or accounts. The second is the ongoing transaction charges, which depend on your Lipa na M-Pesa tariff with Safaricom; third-party gateways may add their own fees on top. When comparing options, look at both, not just the setup price.
Testing before launch
Test in the Daraja sandbox first, then make small real transactions on the live site: successful payments, cancelled prompts, wrong PINs, timeouts and duplicate callbacks. Confirm that receipts, order status and notifications all behave correctly.
Example: an M-Pesa flow for a booking site
A guesthouse requires a deposit to confirm bookings. When a guest selects dates, the site sends an STK Push for the deposit. On confirmation, the dates are blocked, the guest receives an SMS with the booking reference and the owner sees the booking in a dashboard. If the prompt expires, the dates are held briefly and the guest can resend the prompt, so no room is double-booked and no deposit is left unmatched.
Get M-Pesa integrated properly
Our M-Pesa integration service builds STK Push, Paybill and Till confirmations with full reconciliation. Read how STK Push works and Paybill vs Till, or see payment gateway options for online stores.
FAQ
Frequently asked questions
What is the Daraja API?
Daraja is Safaricom's developer platform that provides the APIs used to integrate M-Pesa payments, including STK Push, C2B confirmations and transaction status queries.
Do I need a Paybill to accept M-Pesa on my website?
You need a business shortcode, either a Paybill or a Till number, registered for Lipa na M-Pesa and enabled for API access.
Can a WordPress site accept M-Pesa?
Yes, through a plugin or a custom integration with the Daraja API, depending on how payments need to connect to your orders and systems.
How long does M-Pesa integration take?
The development itself is usually quick; obtaining production credentials and thorough testing often take longer, so start early.
Written by
Blessedave TechnologiesEditorial team
The Blessedave Technologies team designs and builds websites, custom software, e-commerce systems and SEO/AEO programmes for businesses in Nairobi and across Kenya.
Comments
No comments yet. Start the conversation.