How to Set Up M-Pesa Payment Gateway on WooCommerce

How to Set Up M-Pesa Payment Gateway on WooCommerce

Adding M-Pesa to your WooCommerce store is one of the most impactful changes you can make for a Kenyan e-commerce business. M-Pesa dominates online payments in Kenya, and customers who reach checkout and cannot pay by M-Pesa is likely to leave your store without completing checkout.

Setting up an M-Pesa payment gateway on WooCommerce requires a Safaricom Daraja API account, a Paybill or Till number, and a plugin like ImaraPay that handles the Daraja integration for you. Full setup takes under 30 minutes. The most common failure points are incorrect callback URL handling and switching to production with sandbox credentials still active. Both are covered in this guide.

This guide covers the complete WooCommerce M-Pesa integration process: what you need before you start, every configuration step, the Daraja API limitations you will actually encounter, why some stores fail implementation, and the production best practices that keep a live checkout running reliably.

Why You Should Add M-Pesa to Your WooCommerce Store

If you sell products or services to customers in Kenya, offering M-Pesa at checkout is no longer optional. It is the payment method that most shoppers expect to see. When customers cannot pay using M-Pesa, many abandon their purchase rather than look for another payment option.

For store owners, integrating M-Pesa also simplifies order management. Payments are automatically matched with WooCommerce orders, reducing manual reconciliation and helping you process orders faster. You spend less time confirming transactions and more time fulfilling customer orders.

Some of the key benefits of accepting M-Pesa payments include:

Prerequisites: What You Need Before You Start

Before setting up M-Pesa on your WooCommerce store, make sure you have everything required for the integration. If you’re building a new online store, you’ll first need a registered domain name, reliable web hosting, and a WordPress website with WooCommerce installed before you can configure M-Pesa payments. Having these items ready will make the setup process much smoother and help you avoid delays later.

Step 1: Create a Daraja Sandbox App & Get Sandbox Credentials

Before WooCommerce can communicate with M-Pesa, you need to create a Daraja application. This application provides the API credentials ImaraPay uses to authenticate with Safaricom and send STK Push requests. In this step, you’ll create a sandbox application for testing and obtain the credentials needed for the initial setup.

You now have your sandbox Consumer Key, Consumer Secret, Passkey, and test phone number. These credentials will be used to configure ImaraPay in Sandbox mode, allowing you to test your WooCommerce checkout without processing real payments. Keep them somewhere secure, as you’ll need them in the plugin configuration steps later in this guide.

Note: Store all credentials securely. Do not put them in a public code repository or a shared document.

Step 2: Install ImaraPay Woocommerce M-Pesa Gateway

Now that you have your Daraja sandbox credentials, it’s time to install ImaraPay on your WooCommerce store. The plugin handles communication with the Safaricom Daraja API, allowing your store to send STK Push requests, receive payment confirmations, and automatically update WooCommerce orders.

After activation, ImaraPay appears in WooCommerce > Settings > Payments as a new payment method. It is not enabled by default. You enable it after completing configuration.

Step 3: Configure ImaraPay Plugin Sandbox Settings

With ImaraPay installed, you can now connect it to your Daraja sandbox application. In this step, you’ll enter your sandbox credentials, choose the Sandbox environment, and configure the plugin so your WooCommerce store is ready for testing.

Step 4: Test in Sandbox

Run a full test before touching Go Live. Sandbox testing costs nothing and catches most setup problems before real customers are affected.

If the test completes successfully, your WooCommerce store is correctly integrated with the Safaricom Daraja sandbox environment and you’re ready to request your production credentials.

Step 5: Request and Apply Go Live Credentials

After confirming that your WooCommerce integration works correctly in the sandbox environment, you’re ready to switch to Safaricom’s live environment. The Daraja Go Live process upgrades your application and generates the production credentials required to accept real M-Pesa payments.

Note: Keep these production credentials secure. You’ll use them in the next step to switch ImaraPay from the sandbox environment to production.

Step 6: Switch ImaraPay to Production

The final step is replacing your sandbox credentials with the production credentials issued by Safaricom and switching ImaraPay to Production mode. Complete one small live transaction to confirm everything is working correctly before opening M-Pesa payments to all your customers.

Place a small live test order and complete the payment using M-Pesa and confirm that:

Frequently Asked Questions

How do I set up M-Pesa on WooCommerce?

To add M-Pesa to WooCommerce, create a Safaricom Daraja sandbox application, obtain your API credentials, install the ImaraPay plugin, configure it using your sandbox credentials, test the integration, then switch to production using your live Daraja credentials.

You’ll need a WordPress website with WooCommerce installed, an active M-Pesa Paybill or Till Number, a Safaricom Daraja developer account, sandbox API credentials, a valid SSL certificate (HTTPS), and the ImaraPay plugin.

The sandbox environment is used for testing your integration without processing real payments. The production environment processes actual M-Pesa transactions using live credentials issued through the Daraja Go Live process.
Yes. ImaraPay supports both the classic WooCommerce checkout and WooCommerce Blocks, allowing customers to pay with M-Pesa regardless of which checkout experience your store uses.
Most WooCommerce stores can complete the setup in around 30 minutes once the required Daraja credentials are available. The process includes creating a sandbox application, configuring ImaraPay, testing the integration, and switching to production.

Launch Your Website with Confidence

Secure your domain name, host your website, emails, or business, and protect your data with reliable digital solutions and expert support.