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, with over 30 million active users. 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:

  1. Customer adds items to cart and clicks "Pay with M-Pesa"
  2. They enter their M-Pesa phone number
  3. Your website sends a request to the Daraja API
  4. Safaricom sends an STK Push to the customer's phone
  5. Customer enters their M-Pesa PIN on their phone
  6. Payment is deducted from their M-Pesa balance
  7. Safaricom sends a callback to your website confirming the payment
  8. Your website confirms the order and sends a receipt

The entire process takes under 30 seconds and is seamless for the customer.

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. Processing takes 2-4 weeks.
  • 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: Free (Safaricom doesn't charge for API access)
  • Business shortcode registration: KES 0 for Paybill, varies for Till numbers
  • Transaction fees: Safaricom charges a small percentage per transaction (varies by amount)
  • 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 but charges higher fees.
  • 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, card, and Bitcoin 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 slightly higher 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.