Magento 2 C2B M-Pesa Payment via OpenAPIPortal

Magento 2 C2B M-Pesa Payment via OpenAPIPortal by Meetanshi integrates C2B M-Pesa API with Magento 2 to allow customers pay using their phone number securely in the store.

 

Table of Content

  1. Extension Installation Guide
  2. Configuration
  3. OpenAPIPortal C2B M-Pesa Payment Method in Frontend
  4.  OpenAPIPortal C2B M-Pesa Payment Details in Order View Backend
  5.  OpenAPIPortal C2B M-Pesa Payment Method for Backend Order

 

  1. Extension Installation
    • For Magento Marketplace Customers
      • Create a folder structure in Magento root as app/code/Meetanshi/Vmpesa
      • Download and extract the zip folder and upload our extension files to the app/code/Meetanshi/Vmpesa 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
      • 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

 

  1. Configuration
    For configuring the extension, login to Magento 2, move to Stores à Configuration à Sales à Payment Methods à Openapiportal C2B M-Pesa - Meetanshi, where you can find various settings to configure the extension.
  • Enabled: Enable or disable Openapiportal C2B M-Pesa Payment extension from here.
  • Title: Enter title for the C2B M-Pesa Gateway payment method to show in the frontend.
  • Show Vodafone M-Pesa Logo: Select YES to show Vodafone M-Pesa logo on the checkout page in frontend.
  • Sandbox Mode: Set YES to enable sandbox mode for the payment gateway.
  • API Markets: The extension works only with Ghana and Tanzania, make sure to select one of the API markets where you sell your store products.
  • Public Key: Follow the steps below to get your public key from OpenAPIPortal.
  • API Key: Follow the steps below to get your API key from OpenAPIPortal.
  • Service Provider Code: Follow the steps below to get your service provider code from OpenAPIPortal.
  • Third Party Conversation ID: Follow the steps below to get your third-party conversation ID from OpenAPIPortal.
    • Login to https://openapiportal.m-pesa.com/ with your credentials. Click on “Applications” from the sidebar, create a new application or edit the existing one. Click on “glass” icon to view the application details.

    • Click edit button and select “C2B Single Payment”. You can see the sandbox API key, copy it and paste the same in the Magento 2 extension configuration. Don’t forget to select the currency here based on your API market selection. Now, under the response URL field, add URL as https://yourstore.com/vmpesa/payment/confirmation and click the “Save” button.

    • Go to “API Documentation” from the left sidebar and click “View” button on the “C2B Single Stage”.

 

    • Now, click C2B Single Stage under the “Snippets” and select PHP. You can find public key, service provider key and third-party conversation ID from here. Copy them and paste in the relevant fields in Magento 2 extension configuration.

Note:

 

  • Payment from Applicable Countries: Select all or selected countries to allow payments using C2B M-Pesa.
  • Payment from Selected Countries: If you have set selected countries from the above option, select the countries to allow payments using C2B M-Pesa.
  • Debug: Select YES to enable debug.
  • Instructions: Enter additional instructions to show on the checkout page in the frontend.
  • Sort Order: Enter sort order of the payment method.

 

  1. OpenAPIPortal C2B M-Pesa Payment Method in Frontend
    Once the payment method is configured, OpenAPIPortal C2B M-Pesa Payment method is shown on the checkout page in the frontend. Add products to the cart, select the M-Pesa Payment method, add M-Pesa phone number and click to “Place Order” successfully. As the extension works with Ghana currency, make sure to add correct address from Ghana to place the order.

 

  • 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, M-pesa number, conversation ID, response code, response description and transaction ID.

 

  1. OpenAPIPortal C2B M-Pesa Payment Details in Backend
    Apart from the frontend, the admin can also view OpenAPIPortal C2B M-Pesa Payment details in the Sales > Orders > Order View section in the backend. It displays the payment details like payment method name, Mpesa number, conversation ID, response code, response description and transaction ID.

 

  1. OpenAPIPortal C2B M-Pesa Payment Method for Backend Order
    Just as the frontend, OpenAPIPortal C2B M-Pesa payment method also works with the backend orders. Admin needs to create a new order, select the customer, add products, enter the address details and select Vodafone M-Pesa payment method, add M-Pesa phone number and click “Submit Order” to place a successful order from the backend.