How to Accept MPESA Payments on Your WooCommerce WordPress Website
Integrating WooCommerce MPESA Payment
We’ve previously explored how to integrate MPESA into custom PHP and Laravel websites. Now, let’s focus on integrating MPESA STK Push into a WooCommerce WordPress website using a plugin.
Step 1: Set up the MPESA App on Safaricom Daraja Portal
Before setting up the WooCommerce MPESA plugin on your e-commerce website, you need to configure the MPESA app on the Safaricom Daraja Portal. Here’s how:
- Create a new sandbox app:
- Log into the Daraja Portal.
- Click Add a New App and name your app.
- Select Lipa na MPESA Sandbox and MPESA Sandbox.
- Click Create App.
- After creating the app, copy the Consumer Key and Consumer Secret. You’ll need them during integration.
Step 2: Installing WooCommerce
To accept payments, your WordPress site must have the WooCommerce plugin installed. Follow these steps:
- Navigate to Plugins on your WordPress dashboard.
- Click Add New.
- In the search bar, type WooCommerce.
- Install the plugin by Automattic by clicking Install Now.
- Once installed, click Activate Now.
Step 3: Installing WooCommerce MPESA Payment Plugin
With WooCommerce set up, you can now add the MPESA payment gateway.
-
Download the WooCommerce MPESA Payment Plugin:
- Go to a trusted MPESA plugin provider or this page.
- Click Download.
-
Install the Plugin:
- On your WordPress dashboard, go to Plugins > Add New > Upload Plugin.
- Upload the plugin file, then click Install Now.
- Activate the plugin.
-
Configure the MPESA Payment Gateway:
- Go to WooCommerce > Settings.
- Select the Payments tab, then click MPESA.
Step 4: Fill in Your App and Business Details
To set up the MPESA payment gateway, complete the following fields:
- Environment: Choose Sandbox for testing or Live for real transactions.
- Identifier Type: Select either Till number or Paybill.
- Business Shortcode: Enter your business Paybill or Till number.
- Account Reference: Set your account reference (store ID or order ID).
- Consumer Key: Paste the Consumer Key from the Daraja Portal.
- Consumer Secret: Paste the Consumer Secret.
- Online Pass Key: Enter the pass key for MPESA.
Step 5: Test the STK Push
Once your setup is complete, you can test the MPESA payment process.
- Place a test order on your WooCommerce store.
- At checkout, select MPESA as the payment method.
- Enter your phone number, and an STK Push will be triggered on the phone.
- Enter your MPESA PIN to complete the payment.
If successful, the transaction will be marked as paid, and you can proceed with the order fulfillment.
Conclusion
By following these steps, you can seamlessly integrate MPESA STK Push payments into your WooCommerce WordPress website, offering customers a secure and convenient way to pay. Testing your setup in sandbox mode before going live ensures everything runs smoothly.
Thank you!