Magento 2 C2B M-Pesa Payment integrates C2B M-PESA API with Magento 2 to allow customers to pay using their phone securely in the store.
Table of Content
- Extension Installation
- Configuration
- C2B M-Pesa Payment Method in Frontend
- C2B M-Pesa Payment Details in Backend
- Extension Installation
- For Magento Marketplace Customers
- Find the Composer name and version of the extension in the extension’s composer.json file.
- Login to your SSH and run:
- For Magento Marketplace Customers
-
-
- composer require meetanshi/magento2-c2b-mpesa-payment
-
-
- Enter your authentication keys. Your public key is your username; your private key is your password.
- Wait for Composer to finish updating your project dependencies and make sure there aren’t any errors.
- To verify that the extension installed properly, run the command:
- php bin/magento module:status Meetanshi_Mpesa
-
- By default, the extension is probably disabled.
- Enable the extension and clear static view files:
-
- php bin/magento module:enable Meetanshi_Mpesa --clear-static-content
- php bin/magento setup:upgrade
- For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
- For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
- php bin/magento cache:flush
- php bin/magento module:status Meetanshi_Mpesa
-
- For Meetanshi Customers
- Extract the zip folder and upload our extension to the root of your Magento 2 directory via FTP.
- Login to your SSH and run below commands step by step:
- php bin/magento setup:upgrade
- For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
- For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
- php bin/magento cache:flush
- For Meetanshi Customers
For configuring the extension, log in to Magento 2, move to Sales à Payments Methods à C2B M-Pesa Payment - Meetanshi where you can find various settings to enable the extension.
- Enabled: Set “YES” to enable the payment method.
- Title: Set the title of the payment method to be displayed in the frontend.
- Show M-Pesa Logo: Set YES to show M-Pesa logo along with the payment method in the frontend.
- Sandbox Mode: Select YES to enable sandbox mode.
- ShortCode: Enter Shortcode provided by M-Pesa while registration with Safaricom.
- Consumer Key: Enter consumer key provided by M-Pesa while registration with Safaricom.
- Consumer Secret: Enter consumer secret provided by M-Pesa while registration with Safaricom.
-
- Login to Safaricom and move to My Apps. Click “Create New App” button and create new app for M-Pesa sandbox.
-
- Immediately after the app is created, you can see consumer key and consumer secret. Copy both and paste them in relevant fields in Magento 2 extension configuration.
-
- Move to https://developer.safaricom.co.ke/APIs, click “Simulate” under Customer to Business.
-
- Select the app you created.
-
- Click on “Test Credentials”.
-
- From the Test Credentials popup, copy the shortcode and paste it in the relevant field in Magento 2 extension configuration.
- URL for Request Payment: Payment request URL will be pre-filled on extension installation.
- Access Token URL: Access token URL will be pre-filled on extension installation.
- Register URL: Register URL will be pre-filled on extension installation.
- Payment from Applicable Countries: Select countries to allow using this payment method.
- Debug: Select YES to enable debug.
- Instructions: Enter instructions to show along with the payment method in the frontend.
- Sort Order: Enter Sort Order of the payment method display in the frontend.
- C2B M-Pesa Payment Method in Frontend
Once the payment method is configured, C2B M-Pesa Payment method is shown on the checkout page in the frontend while checking out the products. Just select the C2B M-Pesa Payment method, add M-Pesa mobile number and click “Place Order” to place order.
- C2B M-Pesa Payment Confirmation on Order Success
Once the order is placed, follow the instructions on the order success page to confirm the payment.
- C2B M-Pesa Payment Details in “My Account” section
Once the order is placed, the C2B M-Pesa Payment details are shown in the Account dashboard, in “My Orders” tab which includes payment method name, transaction ID, transaction time, and Mpesa number.
- C2B M-Pesa Payment Details in Backend
Apart from the frontend, the admin can also view C2B M-Pesa Payment details in the Sales > Orders > Order View section in the backend. It displays the payment details like payment method name, transaction ID, transaction time, and Mpesa number.