You have heard about Mpesa Integration and the fact that you can start accepting Mpesa payments on your website. This is true and actually very easy if you follow the right steps and get the best source code or expertise.

In this post, I will dive in explaining every detail like to a 2 year old baby on how to integrate your core PHP website with Mpesa C2B.

Note: I have decided not to use code here because it is very possible for you to start accepting Mpesa payments or to add Mpesa Payment gateway on your website without you knowing how to write a single code line.

So, how exactly can you Integrate Mpesa API on your PHP website without writing any code. This is the simplest way to Integrate any PHP website with Mpesa.

But before that, let us know a few things so that we make it even simpler to complete this important ecommerce task.

What is C2B Mpesa integration?

Simple. It is that Mpesa linking feature that will help customers pay you automatically then you can process their orders or continue with whatever business logic your website does using other payment options.

What is a core PHP website?

Once more. Simple. It is a website that is built in PHP without those other stuff you hear known as CMS, Frameworks etc. Just plain PHP opening your notepad or any text editor and writing your website from there and processing data using PHP to maybe a Mysql database.

Note: Some CMS's like wordpress, Drupal and Joomla are developed in PHP. Because of the way they are developed, they have special ways to do their Mpesa Integration through the use of plugins, components and modules. For those, you will benefit from below posts on how to add Mpesa Payment gateways on them:

Hikashop Mpesa payment plugin | Hikashop Mpesa Payment plugin | Hikashop Mpesa Payment gateway | Hikashop Mpesa payment component

Mpesa C2B with your Woocommerce | m-pesa mobile payment for woocommerce nulled | m-pesa mobile payment for woocommerce nulled | m-pesa mobile payment for woocommerce free download | mpesa wordpress plugin | mpesa for woocommerce github | wc mpesa | mpes

Types of Mpesa C2B API integration to have in mind before deciding on Integrating your website with an Mpesa Payment option.

1. Mpesa C2B General API:

This is whereby users pay using their phones without having to touch your website or app and everything else is processed by your website/server automatically. In this case, your website users do not need to visit your website or app or be online to make a payment. All they need is to know how to pay you and the account that identifies their payment in your website or software or servers.

The technical aspects involved here are:

a) . Url registration: ==> This involves telling Mpesa servers the urls which they will need to communicate to in case a payment is received on a your Mpesa  Paybill or Till Number.

b). Validation : ===> The transaction received is validated on its legitimacy and your own conditions.

c). Confirmation:===> If valid, the Mpesa transaction is confirmed and the business logic is executed.


So now, let us integrate a C2B Mpesa gateway to process transactions from your clients.

Before I dive too deep, here is an Mpesa C2B Integration Assistant that through a few Clicks will help integrate Mpesa C2B API in your website within minutes without any coding skills. Just add it to cart and checkout, download and follow the instructions located here: How to use the Mpesa C2B API Integration Assistant

$50.00 each Mpesa C2B API Integration Assistant


 Requirements to Integrate your website with Mpesa C2B API:

1. The above Mpesa API integration assistant.

2. A C2B Paybill from Safaricom.

3. A developer account from Safaricom.

4. Webmaster knowledge.

 Process on how to integrate C2B.

a) Set up the Mpesa API integration Assistant in your server/Hosting Cpanel. Since most people use Cpanel these days, I will explain using a Cpanel. The Apache server should be running PHP and Mysql and support PHP 7+. Let this be set in its own folder in your cpanel. If your main website is running in the main directory, consider a folder like this maindirectory/payments

b) Add the C2B Mpesa integration plugin to the above Payments processor.

After the above procedure, you are now ready with a payment gateway which can automatically process Mpesa payments from Clients. However, you are not yet ready to process the orders against these transactions.

c) Now set the Core PHP Payments Mpesa integration plugin. This is the plugin that connects your order process to above processed payments.

  •  Create a folder inside your main directory and call it "Mpesa" or any other name you prefer. It is advisable to choose another name apart from Mpesa.
  • Inside this folder, upload the Core PHP Mpesa plugin zipped file you downloaded from your Payment processor script account.
  • Unzip it.

Open your "Payment successful page" and include code to factor in any Payments from Mpesa. This is upon you as per the functionality of your Core PHP website.

Recall that all Payments are deposited on the Payments core Gateway and you can view them from the admin end under Transactions--->Mpesa

Now you are done. Test your work.

You have successfully integrated C2B Mpesa payments with your Core script.

2. Lipa na Mpesa Online API - The Mpesa Express Api.

This is also a form of Mpesa C2B API. Customers will pay your business. However, unlike the General C2B Mpesa API, customers will need to do an online Checkout of whatever they are buying or paying for, then, a popup will appear will appear on their Phones with the payment details and a form to just enter the Mpesa PIN and click OK and fuaaaahhhhh, the Mpesa payment is completed and the item processed.


Fig 1: An illustration of the message you receive after Lipa na Mpesa online Checkout (STK push).


Mpesa Integration - stk push

Fig 2: An illustration showing the POPUP form that will appear on the customers phone after checkout ready to be paid.