
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.
Why You Should Add M-Pesa to Your WooCommerce Store
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.
- Increased customer confidence through a familiar and trusted payment method
- Faster checkout with secure STK Push payment requests
- Higher conversion rates by reducing cart abandonment
- Secure transactions backed by Safaricom's M-Pesa platform
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.
- A live WordPress site with WooCommerce installed and active
- A Safaricom M-Pesa Paybill or Till number linked to an active M-Pesa Business (G2) account.
- A verified Safaricom Daraja developer account
- A Daraja app with the Lipa Na M-Pesa Online (STK Push) API product enabled
- Your site on HTTPS with a valid SSL certificate.
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.
- Register or log in at developer.safaricom.co.ke.
- Go to My Apps and create a new Sandbox app. Give it a name that identifies your store.
- Copy your sandbox Consumer Key and Consumer Secret. Store both securely.
- Navigate to the Test Credentials section. Note the sandbox test MSISDN (phone number) and Passkey.
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.
- Download ImaraPay Woocommerce M-Pesa Gateway
- In your WordPress dashboard, go to Plugins > Add New > Upload Plugin
- Upload the ImaraPay .zip file and click Install Now.
- Activate the plugin once installation completes
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.
- Go to WooCommerce > Settings > Payments
- Click "Manage" next to ImaraPay
- Set the Environment to Sandbox.
- Enter your Sandbox Consumer Key, Consumer Secret. Shortcode (test Paybill/Till) and Passkey.
- Click Save Changes.
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.
- Open your WooCommerce store and add a product to the cart.
- Proceed to the checkout page and select M-Pesa as the payment method.
- Place the order to initiate the STK Push request.
- Verify that the payment request is sent successfully and that the sandbox transaction is processed.
- Return to your WordPress dashboard and confirm that the WooCommerce order status changes
- Review the ImaraPay payment logs to confirm that the transaction was recorded successfully
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.
- Log in to your Safaricom Daraja account.
- Open Go Live from the main navigation menu.
- Complete the Go Live information requested by the portal
- Once complete, retrieve your Consumer Key and Consumer Secret from your Live application
- Retrieve your production Passkey from your email or the Live application.
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.
- In your WordPress dashboard, go to WooCommerce > Settings > Payments.
- Locate ImaraPay and click Manage.
- Change the Environment setting from Sandbox to Production.
- Replace your sandbox Credentials with your production Credentials
- Save your changes.
Place a small live test order and complete the payment using M-Pesa and confirm that:
- The STK Push is received on your phone.
- The payment is completed successfully.
- The order automatically changes to Processing or Completed depending on your settings
- The payment appears correctly in the ImaraPay transaction logs.
Frequently Asked Questions
How do I set up M-Pesa on WooCommerce?
What do I need before integrating M-Pesa with WooCommerce?
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.


