Mpesa Kenya API (Safaricom Daraja)

Mpesa Kenya API (Safaricom Daraja)

I have been looking at Kopokopo API and the problems many people are facing trying to Integrate the Till Number payments to their websites or mobile apps and today I have decided to chip in to help a few guys here. First of all, Kopokopo gives Till Numbers to individuals and Businesses so that you can get paid in large and small amounts without the necessity of giving our your personal numbers.

Without Kopokopo API integration, you can receive payments to your Till number. However, your website goods and services will not be processed automatically. This gives a lot of headache trying to reconcile payments to their payers and orders.

Kopokopo Mpesa api Integration will ease this for you.

Let me dive in and take you through Kopokopo API integration:

Please note that I do offer Kokokopo Mpesa api Integration if this guide seems complicated for you. So do not worry. Just call me or whatsapp me on: +254706745202


 Requirements to Integrate Kopokopo Mpesa API

1. A buygoods Till number registered through Kopokopo.

2. An account from Kopokopo on the website


Common misconceptions about Kopokopo Mpesa API addressed below:

  1. Kopokopo has nothing to do with Daraja API. If you apply a Till number from Kopokopo guys, do not dream of getting the Mpesa portal username and password that will allow you Integrate with Daraja and enjoy the versed features that Daraja offers.
  2. Kopokopo Till numbers cannot help you get an stk push functionality.
  3. Kopokopo Till numbers have no account part. So if you are thinking about getting a paybill for the account number part, contact safaricom directly.

So now that you have a KopoKopo Till numbers, below is the integration process:

1. The first is to login your kopokopo account and click API settings.

2. Enter your Transaction push API * settings and save.

Note: Your Kopokopo API version should be V3, Notification URL  shoud a url that you can edit and have control over and should be hosted (preferrably accessible via https), username and password are optional.

3. Note your API Key and you can regenerate a new one.

 Fig 1: An illustration of the Kopokopo Push API settings. These are essentially what you need to setup so that you start receiving Push notification to your server via the provided endpoint anytime someone pays you via your Buygoods till acquired through Kopokopo. Essentially this Till number if from Safaricom Mpesa, but Kopokopo are like third-part techie company providing easy integration services and application of Buy goods till numbers.


 From this point, you are 1/3 done with the Kopokopo API integration.

Capturing and reading the data from Kopokopo API anytime a client pays to your Till.

In your endpoint that you entered as Notification url above, write in your best backend language a way to capture the data sent to that url. They are sending json data to that file.

Below is an example in php:


$kopokopo_push_data = $file_get_contents("php:\\input");


 Then result of the above is the json data for each transaction.

The next step is to consume that data depending on your business logic. This is where your programming skills come in. Do that thing using code that you wanted to do anytime a client successfully makes the payment.


The last step is to display to the clients the steps to make payment to your Till that you got from Kopokopo.


That is all. As easy as that.




WHMCS Mpesa API integration is something we have done for several clients and we can still do it for your Webs hosting website now. All you need is to contact us for this service. In this article, I will explain exactly what you need to have and the step by step documentation of how our module looks like and works.

Requirements to Integrate Mpesa API on a WHMCS website

  1.  Whmcs valid License and an installed WHMCS website.
  2. Mpesa paybill number or Till Number.
  3.  Daraja portal account.
  4.  A developer to do the work (This is where we come in as developer to write the code for you to integrate Mpesa API or Install and setup our custom developed Payment module).

You can easily get an Mpesa API integration solution on your WHMCS WEBSITE to automate your Domain and hosting Mpesa payments. Simply contact me on + 254706745202 now for a good price and quality clean Mpesa Integration work.

How will the Mpesa API Integrated WHMCS website look on the checkout process, payment and order processing.

Below is a step by step illustration of how the final Mpesa Integration solution will look like.

  1. Step 1: The customer will land on your WHMCS website, search for a domain name or hosting package, add to cart and proceed to make a payment. When making a payment, that is where the first instance of Lipa na Mpesa payment gateway will appear.

Add Mpesa payment gateway to WHMCS WEBSITES

Fig 1: An illustration of Lipa na Mpesa integrated as one of the Payment methods on a WHMCS website. Here, the customer will select Lipa na Mpesa and click Proceed to Checkout.

The customer will then be redirected to the Mpesa API in the background.

Lipa na Mpesa payment gateway Redirecting to make payment

 Fig 2: The above is an illustration of how the customer will see the redirection happening.

The customer will finally end up on a page that displays a message on what exactly happened during the Mpesa API checks of the required integration variables like Phone, amount and the Daraja portal credentials.


 STK PUSH message after a successful stk push api request

 Fig 3: This screenshot shows the page the customer sees after successful request. The message is that the customer should check his or her Mpesa phone and enter Pin to complete the transaction.


On checking the Mpesa phone, there will be a popup message which is as a result of stk push Mpesa api integration (Mpesa Express API on Daraja).

WHMCS stk push popup on client Mpesa phone

Fig 4: shows the stk push pop up message as it will appear on clients phone. The client will simply enter Mpesa PIN to complete the transaction. As easy as that.

The next that the customer will see is the a successfully paid up WHMCS invoice. That means Mpesa API is updating Invoices automatically when a successful payment hits the merchant Paybill or Till Number.

WHMCS invoices paid via Lipa na Mpesa payment gateway

Fig 5: Then Invoices will be marked as paid automatically and WHMCS system will detect it is paid and actually send a Payment Confirmation email to the customer registered email. This happens even if the customer hasn't reloaded the Order page or has not clicked the button to be redirected.

A nice idea in development is an auto-redirection to the customer invoices with a Payment successful page in consideration when payment hits the merchant account.


An individual WHMCS invoice paid via Mpesa

Fig 6: Look at the paid Invoice above which is automatically updated as soon as Mpesa payment hits the business Paybill number.



Mpesa API integration for wordpress websites

Mpesa API integration for Joomla websites

Mpesa API integration for Joomla Hikashop component

Mpesa API integration for Drupal websites

Mpesa API integration for Laravel framework websites

Mpesa API integration for plain/Vanilla PHP websites

Mpesa API integration for PHPStorm websites

Mpesa API integration for CodeIgnitor web framework websites

Mpesa API integration for Moodle websites

Mpesa API Integration for Android mobile apps