Here's a comprehensive guide to implementing M-Pesa payments on your WooCommerce store:
- Go to the Safaricom Developer Portal
- Create an account or log in if you already have one
- Navigate to "My Applications" and create a new application
- Select "M-Pesa Express (STK Push)" as your API type
- Note down your:
- Consumer Key
- Consumer Secret
- Passkey (found under Lipa Na M-Pesa Online)
- Shortcode (Paybill or Till number)
-
For Sandbox Testing:
- Use test credentials provided in the developer portal
- Test numbers: 254708374149, 254703459309, etc.
-
For Production:
- Submit your business documents for approval
- Once approved, activate your production environment
- Use your live Paybill/Till number and credentials
- In your WordPress admin, go to Plugins > Add New
- Click "Upload Plugin" and select your
woo-mpesa-gateway.zipfile - Click "Install Now" then "Activate Plugin"
-
Go to WooCommerce > Settings > Payments
-
Find "M-Pesa" in the payment methods list and click "Set up"
-
Configure the following settings:
- Enable/Disable: Check to enable
- Title: "M-Pesa" (or your preferred display name)
- Description: "Pay via M-Pesa STK Push"
- Instructions: Add payment instructions for customers
- Consumer Key: Your Daraja API consumer key
- Consumer Secret: Your Daraja API consumer secret
- Shortcode: Your Paybill or Till number
- Passkey: Your Lipa Na M-Pesa Online passkey
- Sandbox Mode: Enable for testing, disable for production
-
Click "Save changes"
-
In your Daraja API settings on the Safaricom portal:
- Set your callback URL to:
https://yourdomain.com/wc-api/mpesa_callback - (Replace "yourdomain.com" with your actual domain)
- Set your callback URL to:
-
In WordPress, go to Settings > Permalinks
- Click "Save Changes" to flush rewrite rules (no need to change settings)
- Place a test order on your site
- Select M-Pesa as payment method
- Use test phone numbers (254708374149, etc.)
- Enter test PIN: 174379
- Verify payment is processed correctly
- Use a tool like Postman to simulate callbacks
- Send test payload to your callback URL
- Check WooCommerce orders to verify status changes
-
Once testing is successful:
- Disable Sandbox mode in plugin settings
- Enter your production credentials
- Submit your production application if not already done
-
Verify with real transactions:
- Start with small test amounts
- Confirm payments reflect in your M-Pesa account
-
API Errors:
- Verify all credentials are correct
- Check Daraja API status page for outages
-
Callback Issues:
- Ensure your server can receive POST requests
- Check WooCommerce logs for errors
-
Common Problems:
- "Invalid consumer key/secret" → Regenerate credentials
- "Request timeout" → Check your server's internet connection
- "Callback not received" → Verify URL is correct and accessible
-
Regularly:
- Check for plugin updates
- Monitor transaction logs
- Renew API tokens before expiry
-
Security:
- Keep API credentials secure
- Implement SSL certificate (HTTPS)
- Regularly update WordPress and WooCommerce
This complete setup will give you a fully functional M-Pesa payment gateway integrated with WooCommerce. The plugin handles the STK Push process automatically, providing a seamless payment experience for your customers.