Home / Blog / E-commerce & Payments

How to Integrate M-Pesa into Your E-commerce Store in Kenya

In Kenya, M-Pesa has completely transformed the way people pay for goods and services. With millions of users relying on it for daily transactions, integrating M-Pesa into your e-commerce website is no longer a luxury — it's a necessity.

Why M-Pesa Integration Matters for Your Online Business

Widespread Use in Kenya

M-Pesa dominates Kenya's digital payment landscape, with over 30 million active users. When you integrate M-Pesa, you instantly make your online store more accessible and trusted by Kenyan shoppers.

Faster and Safer Transactions

Unlike traditional bank transfers, M-Pesa payments are instant and secure. Customers can make payments using their mobile phones in seconds, reducing abandoned carts and increasing your conversion rate.

Builds Customer Trust

Kenyans associate M-Pesa with reliability. When customers see the "Pay with M-Pesa" option on your website, they're more likely to complete their orders. It gives them confidence that your business is genuine and locally aligned.

How M-Pesa Online Payments Work

Before jumping into integration, it's good to understand how M-Pesa works in an e-commerce setting. Here's a quick overview:

The M-Pesa Payment Process:

  • Customer Selects M-Pesa: At checkout, customer chooses "Pay with M-Pesa" option
  • STK Push Triggered: The system sends a payment prompt (STK push) to the customer's phone
  • Customer Authorizes: Customer enters their M-Pesa PIN to authorize the payment
  • Payment Confirmed: M-Pesa confirms payment and sends feedback to your website through an API callback
  • Order Completed: Your system verifies payment and marks the order as complete
  • That's the entire process — fast, secure, and easy to automate.

    Step-by-Step Guide to M-Pesa Integration

    1. Create a Safaricom Developer Account

    Start by visiting Safaricom's Developer Portal. Create an account to access M-Pesa APIs. Once logged in, you can create a new app to generate your Consumer Key and Consumer Secret — which are required for all API requests.

    What You'll Get:

    • Consumer Key: Unique identifier for your application
    • Consumer Secret: Secure key for authentication
    • Access to Sandbox: Testing environment for development

    2. Choose the Right M-Pesa API

    Safaricom offers several APIs for different business needs:

    Lipa na M-Pesa Online (STK Push)

    Best for e-commerce sites. Prompts users to pay directly from their phones. This is the recommended option for most online stores.

    C2B (Customer to Business)

    Ideal for receiving payments from customers via Paybill or Till Number. Good for businesses with existing M-Pesa infrastructure.

    B2C (Business to Customer)

    Used when you need to send payments back to customers (refunds, payouts). Not typically used for e-commerce payments.

    For most e-commerce stores, Lipa na M-Pesa Online API is the best choice.

    3. Get a Paybill or Till Number

    You'll need either:

    Paybill Number

    For businesses receiving payments linked to an account. Customers enter your Paybill number, then account number (usually order ID).

    Till Number

    For retail businesses, often called "Buy Goods". Customers just enter the Till number to pay.

    You can apply for one through Safaricom Business. If you're a small startup, Safaricom offers Pochi la Biashara as an alternative, though it has limited integration options.

    4. Set Up Your API Credentials

    Once your Paybill or Till is active, Safaricom will link it to your developer app. You'll then use:

    Essential Credentials:

    • Short Code: Your Paybill or Till number
    • Consumer Key & Secret: From your developer app
    • Passkey: Provided by Safaricom for your Paybill

    Store these credentials securely — you'll need them for your integration code.

    5. Connect the API to Your Website

    You can integrate the M-Pesa API manually or use ready plugins depending on your platform.

    For WordPress (WooCommerce)

    Use plugins like M-Pesa for WooCommerce by PesaPress or WooCommerce M-Pesa Payment Gateway by KenyaPay. Simply install the plugin, enter your credentials, and activate M-Pesa as a payment method.

    For PHP Websites

    You can implement the STK Push API using PHP cURL requests. Here's a basic workflow:

    // Generate access token
    // Initiate STK push using /mpesa/stkpush/v1/processrequest
    // Handle callback responses to confirm payment success

    If you're not familiar with code, Angazalabs can handle this setup for you professionally and securely.

    For Shopify or Custom Stores

    Use third-party services like:

    • PesaPal
    • iPay Africa
    • Flutterwave
    • DPO Group

    These act as payment aggregators that already include M-Pesa integration options for multiple e-commerce platforms.

    6. Test in the Sandbox

    Before going live, Safaricom provides a Sandbox Environment — a testing space where you can simulate M-Pesa payments without real money.

    Testing Checklist:

    • Test your checkout flow end-to-end
    • Confirm callback URLs work correctly
    • Ensure order statuses update automatically
    • Verify payment confirmation emails are sent

    This prevents costly mistakes and ensures smooth customer experiences.

    7. Go Live

    Once testing is successful, request Safaricom to move your app from Sandbox to Production mode.

    After approval, you can start accepting live payments from customers on your e-commerce site.

    Post-Launch Monitoring:

    • Monitor payment success rates
    • Set up error logging and alerts
    • Track customer feedback on payment experience
    • Regularly update your integration as APIs evolve

    Common M-Pesa Integration Issues (and How to Fix Them)

    Invalid Credentials

    Double-check your Consumer Key, Secret, and Passkey. Ensure they're correctly entered without extra spaces.

    Callback URL Not Working

    Ensure your website uses HTTPS (not HTTP). Safaricom requires secure connections for callbacks.

    Payment Delays

    Might be caused by incorrect time synchronization or slow API response — check your server logs.

    STK Push Not Triggering

    Confirm your Paybill/Till number supports Lipa na M-Pesa Online and is properly configured.

    For businesses without in-house developers, it's best to work with experts like Angazalabs, who can set up a fully functional, secure payment system for you.

    Why Choose Angazalabs for M-Pesa Integration

    At Angazalabs, we specialize in creating modern, secure, and conversion-optimized e-commerce websites. Our developers are skilled in M-Pesa API integration, ensuring that your checkout process is seamless and reliable.

    Expert Integration

    We handle the entire M-Pesa integration process from start to finish

    Security Focused

    We implement secure payment handling and data protection

    Ongoing Support

    We provide maintenance and updates as APIs evolve

    Mobile Optimized

    We ensure perfect payment experience on all devices

    We also offer:

    • Custom website development
    • SEO optimization
    • AI-powered tools and automation
    • Branding and digital marketing services

    So, whether you're launching your first online store or upgrading an existing one, we can help you integrate M-Pesa quickly and professionally — boosting your business credibility and sales.

    Final Thoughts

    Integrating M-Pesa into your e-commerce store isn't just about convenience — it's about trust, accessibility, and growth. With the right setup, you'll make it easier for Kenyan customers to buy from you, improve your sales conversion rate, and future-proof your online business.

    Builds Trust

    Customers trust businesses that offer familiar payment methods

    Reduces Abandonment

    Instant payments mean fewer abandoned carts

    Boosts Conversions

    Familiar payment options increase purchase completion

    Local Advantage

    Align your business with Kenya's preferred payment method

    If you're ready to take the next step, reach out to Angazalabs today. We'll help you set up a smooth, secure M-Pesa integration that your customers will love — and your business will benefit from.

    Ready to Integrate M-Pesa into Your E-commerce Store?

    Let Angazalabs handle the technical complexities while you focus on growing your business. Get a seamless, secure M-Pesa payment system that boosts conversions.

    Expert integration • Kenyan market expertise • Ongoing support

    Author

    About Angazalabs

    Angazalabs is a digital agency specializing in custom web development, digital marketing, and brand strategy. We combine technical expertise with creative vision to deliver solutions that drive business growth across Africa.