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.

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.

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.

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


1. Payments core script.

2. A C2B Paybill from Safaricom.

3. A developer account from Safaricom.

4. Webmaster knowledge.

5. C2B Mpesa integration plugin.

6. Core PHP Paynents Mpesa integration plugin.

 Process to integrate C2B.

a) Set up the Payments processor gateway 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.

d). Now, this step requires PHP knowledge, you can hire a PHP developer or our Team to do this part for you.

  1. Locate in your core PHP website where you are processing the orders. Examples.

[Code block to add orders to cart]
[Code block to select Payment methods

// Here, add "Mpesa"

Examples: If using a Form:

<form action="action-page-here" method ="POST">
<option hidden>Select Payment method</option>
<option>Other method</option>

<!----type Mpesa in the case I typed above--->



//This is just an example. You well know how your code selects payments methods. Could be plain, from form, or form fetching from Database or simply you haven't attended 
a Payment method selection before. I suggest forms fetching from DB.


On the Form action file, Add below code:


$payment_method = $_POST['method'];

require_once "mpesa/core_php_mpesa.php";


//Other payment methods if any




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.