Technical Guide
M-Pesa Integration for Websites: A Guide for Kenyan Businesses
Everything you need to know about adding M-Pesa payments to your website, from the Daraja API to STK Push and beyond.
M-Pesa is the most widely used mobile money platform in Kenya. For any Kenyan business selling products or services online, M-Pesa integration is not optional — it's essential. Customers expect to pay via M-Pesa, and if your website doesn't support it, you're losing sales.
What is M-Pesa Website Integration?
M-Pesa website integration allows your customers to pay directly through your website using their M-Pesa mobile wallet. When a customer clicks "Pay", they receive an STK Push notification on their phone, enter their M-Pesa PIN, and the payment is processed instantly. Your website confirms the payment in real-time.
This is done through Safaricom's Daraja API (previously known as the M-Pesa API). The Daraja API provides several services, but for website payments, the most commonly used feature is Lipa Na M-Pesa Online (STK Push).
How STK Push Works
Here's the step-by-step flow when a customer pays on your website:
- Customer adds items to cart and clicks "Pay with M-Pesa"
- They enter their M-Pesa phone number
- Your website sends a request to the Daraja API
- Safaricom sends an STK Push to the customer's phone
- Customer enters their M-Pesa PIN on their phone
- Payment is deducted from their M-Pesa balance
- Safaricom sends a callback to your website with the result
- Your website double-checks the result with Safaricom (an STK Query), then confirms the order and sends a receipt
For the customer it takes only a few taps.
Requirements for M-Pesa Integration
Before you can accept M-Pesa payments on your website, you need:
- Safaricom Daraja Developer Account: Free to create at developer.safaricom.co.ke
- Business Shortcode (Paybill or Till Number): Apply through Safaricom Business; ask Safaricom how long it will take.
- SSL Certificate: Your website must use HTTPS (this should be standard anyway)
- Server with callback URL: A publicly accessible URL to receive payment confirmations
- A developer experienced with the Daraja API: This is where a professional web development company comes in
Cost of M-Pesa Integration
The cost of integrating M-Pesa into your website includes:
- Daraja API access: Safaricom lists no fee for using the Daraja API itself
- Business shortcode registration: check the current requirements and any costs with Safaricom
- Transaction fees: the normal M-Pesa tariffs on each payment. For a Till, at the time of writing (October 2026), payments up to KES 500 cost the merchant nothing, KES 501 to 36,363 cost 0.55%, and above that a flat KES 200 (Safaricom's tariff page). Paybill tariffs are agreed with Safaricom.
- Development cost: KES 30,000 - KES 80,000 depending on complexity
At KenZobe Technologies, M-Pesa integration is included in our Premium website package (KES 400,000) or available as a standalone service. See our complete pricing guide.
Alternative Payment Options for Kenya
While M-Pesa is dominant, you may want to offer additional payment methods:
- PesaPal: A Kenyan payment gateway that supports M-Pesa, Airtel Money, Visa, and Mastercard. Easier to integrate than direct Daraja API; it charges its own fee per transaction.
- Flutterwave: A pan-African payment platform supporting M-Pesa, card payments, and bank transfers. Good for businesses serving customers across Africa.
- IntaSend: Another Kenyan-built payment gateway with M-Pesa and card support.
- Direct card payments: Visa and Mastercard through a payment gateway
Common Challenges and How to Solve Them
1. Slow Callback Responses
Sometimes Safaricom's callback takes longer than expected. Solution: implement a polling mechanism that checks payment status every few seconds, and show a "Processing..." screen to the customer.
2. Failed Transactions
Customers may enter wrong PINs, have insufficient balance, or let the STK Push timeout. Solution: handle all error codes from the Daraja API gracefully and show clear error messages.
3. Duplicate Payments
If a customer clicks "Pay" multiple times, you may trigger multiple STK pushes. Solution: disable the pay button after the first click and use unique transaction references.
4. Testing
Safaricom provides a sandbox environment for testing. Always test thoroughly in sandbox before going live with real money.
When to Use Direct Daraja API vs. Payment Gateway
Use direct Daraja API if: You only need M-Pesa, want lower transaction fees, and have an experienced developer.
Use PesaPal/Flutterwave if: You need multiple payment methods (M-Pesa + cards), want faster setup, and don't mind paying the aggregator's fees.
Get M-Pesa Integration for Your Website
KenZobe Technologies has extensive experience integrating M-Pesa payments for Kenyan businesses, from e-commerce stores to booking platforms and subscription services. We handle everything from Safaricom Daraja API setup to testing and deployment.
Contact us today to add M-Pesa payments to your website, or visit our office at BBS Mall, Eastleigh, Nairobi.