M-Pesa API Integration - Step-by-step Guide

August 13th, 2022 by Felix Cheruiyot


The digital payment space is maturing and users are demanding a seamless experience across apps and services. This drives the need for enterprises to integrate payments (M-Pesa API integration) as a feature within their apps or services.

To achieve this, businesses can leverage APIs to create a frictionless user experience while integrating mobile payments. By using APIs, developers are able to easily build integrations without having to store confidential information or build on top of an SDK. A good example of this would be the M-Pesa API integration, which lets businesses leverage the power of M-Pesa in their products and services. In this blog post, we will explore how you can leverage APIs like the M-Pesa integration to embed payments into your app or service with ease.

1. M-Pesa API Integration using IntaSend SDKs

Integrating any API is never easy, especially when you’re adopting an approach that hasn’t been previously worked on by people who genuinely want to make things easy for you. With IntaSend, you don’t have to go through the tough route because we’ve done the heavy lifting for you. You must use the SDKs provided to connect the M-Pesa API to your mobile/web app so operations can run smoothly. If you choose to integrate the M-Pesa API through IntaSend, you will also have access to the M-Pesa B2B API, which enables B2B payments within your application for easy operation. So, what if you ever run into any issues while you’re trying to integrate? Our team of developers is just a phone call or live chat away from fixing your problems - it’s that easy!

Why IntaSend?

Easy setup and activation

It may not have been possible for your to set up an account, integrate the API, and go live the same day with the usual M-Pesa integration process, but that’s something you can do with IntaSend. IntaSend allows you to set up your account and activate it as soon as possible to start collecting and disbursing payments without waiting an extra day. The tools and SDKs we offer will enable you to initiate transactions and track them to know their statuses. Below is a list of our M-Pesa API SDKs;

Send single and bulk payments seamlessly

Whether you’re settling payroll payments or settling suppliers’ bills, you can get everything with a single request. One of the things people love most about the IntaSend M-Pesa API is how you can perform up to 5000 transactions in a single request.

M-Pesa STK push

Our M-Pesa Express STK push is a good alternative to card payments, and you can use it to push payment requests to your clients using the API.

Secure and scalable

IntaSend is one of the leading payment providers with the best payment security standards in the industry. IntaSend’s APIs (including the M-Pesa API) are PCI DSS compliant. IntaSend also deploys PSD2 standards to provide extra security and authentication of payment requests; it doesn’t get better than that!

Easy documentation

You don’t need to wait longer than necessary to get your API set up without hassles. Go to your sandbox to test your keys and begin testing your implementation as soon as possible. To learn more about this, visit our Developers API Documentation.

What can you do with the IntaSend’s M-Pesa API Integration

Salary payment

IntaSend's M-Pesa API Integration provides an ideal mechanism for employers to pay their staff salaries and other ad-hoc expenses through mobile phones. The API provides both bulk payments and single payment options for your business disbursements. M-Pesa makes salary payments quite easy; better still; it significantly reduces the cost connected to making payments to all staff, including those who do not have a bank account; such employee can easily use their M-Pesa account as a wallet to keep their salary, especially when they are willing to save up. They can later affect a withdrawal or pay for goods and services using their M-Pesa Visa card.

This process is even more convenient for employers with many employees and those with some employees with no bank accounts.

Bill payments automation

With IntaSend's M-Pesa API integration bill payments is made easy through our B2B API. This is an innovation that targets alleviating the pains that come from making some repeated suppliers and vendors payments.

This process is so automated that all payments received through M-Pesa are instantly reconciled on the platform, providing an option to add payments manually.

E-commerce - M-Pesa express (STK Push)

With IntaSend's M-Pesa express STK Push API, a merchant can simply conduct mobile money transactions and push its details to a customer's mobile phone. This implies that the merchant can initiate an M-Pesa transaction on a customer's behalf. In contrast, the customer does not need to enter the merchant’s information or any other transaction details.

One of the benefits that the M-Pesa express affords is the simplicity of M-Pesa transactions. Hence, the customer only has to hit one button instead of a complicated transaction process. Another benefit of the M-Pesa express is the real-time functionality it affords as transactions take place instantly, with no waiting time, when details are punched in. Lastly, the M-Pesa express features afford maximum security throughout your transactions.

Pros of using IntaSend API

Cons of using IntaSend API

2. M-Pesa Integration through Daraja API

Since the launching of M-Pesa by Safaricom in 2007, it has gained the hearts of many, particularly in Kenya and Tanzania, because it affords every user a seamless deposit, withdrawal, transfer, and even air recharge through its M-Shwari or Fuliza service. However, you can pay for goods or services via Paybill or buy goods till number. Almost every business organization has a Lipa na M-Pesa till number or Paybill number to accept payments from customers and other business organizations.

Despite the widespread adoption of M-Pesa like wildfire, a section of the masses remains unsatisfied with their services, majorly because it is not wholesome enough, especially in API integrations. Software developers wanted an API to access the M-Pesa services, and soon after this 'outcry,' Safaricom heeded by developing the M-Pesa G2 API. In the adoption and integration of this API, web developers polarised into two factions: those who struggled but eventually found a way to make this integration work and those who did not even have the infrastructure, expertise, or know-how to pull this integration. The latter faction was mostly limited because of the stringent requirements for this integration; it was far from seamless as there was a need for a VPN connection and the soap protocol, to mention but a few.

Following the difficulties encountered in integrating the M-Pesa G2 API, Safaricom improved it and recently introduced a new M-Pesa API, called ‘The Daraja API’ (Daraja in Swahili means bridge), implying an attempt to bridge the wide gap between the web developers' factions. With this new API, you now have access to the public internet space - a significant improvement from the G2 API, which required a VPN connection and soap protocol for integration.

The other major improvement to the previous API is that it interacted using the REST protocol in a bid to reduce the pain of the developers whose Apps use REST protocol but had to find a way to accommodate M-Pesa’s SOAP. Now, the Daraja API not only incorporated the good features of the previous API but also introduced new and interesting ones, such as; B2B, Transaction status, Account balance, and Lipa na M-Pesa online.

Below is a step-by-step guide to integrating M-Pesa into a website, App, or system using the Daraja API.

Step 1: Create an account on the M-Pesa G2 Portal

Creating an account on the M-Pesa G2 portal will allow you to create a user who will be sent a One-Time Password (OTP) that you can use to test if M-Pesa API integration is a success. This procedure is necessary if one must access pay bill number transactions.

However, note that M-Pesa API integration requires a windows internet explorer browser, certified by Safaricom, to set up the M-Pesa portal. Hence, you need to request and get a certificate before you can use your windows internet explorer. To get this certification for your browser from Safaricom, send a blank email to [email protected]

Safaricom will respond to the email automatically with a link for you to request a certificate. Click on the link to install the certificate in Windows Internet Explorer.

Step 2: Create an app on the M-Pesa Developer portal

The process is simple;

Step 3: Write C2B, B2C, or B2B code

This stage is where things get a little complicated because, for these banking transactions to go smoothly, you have the codes yourself, but the good news is, you can pick any language you like when writing the code, and experts do this at web development; you may need to procure their services for this one. An M-Pesa API developer will go through all the steps in this tutorial and do all the processes for you. You will be required to apply for a Paybill account only, and the developers will take care of the rest.

Step 4: The time to go live

This fourth stage is where you go live. However, before you do this, ensure that all your codes are running properly and that there are no areas whatsoever- the minutest errors can cause a disaster to your integration process.

Go to the developer portal and 'go live' to go live. After this action, you will be required to verify the API's ownership; if it is yours, you should have no issues with going live. To verify, however, you need to follow the following steps;

Once this is done, input the URL endpoint to the action button with which a client will interact on your website. Test if the integration was successful by clicking on the button to initiate payments and pay before making your site or app live for customers to make payments.

Pros of using Daraja API

The above pros only apply if having a direct relationship with Safaricom is a business requirement.

Cons of using Daraja API

Why M-Pesa API Integration

With a growing population and increasing internet penetration in Africa, there will always be a need to advance payment solutions. Despite the astronomical growth in technological inclusion and economic diversification in Africa, in recent times, it is sadly so that the continent is still largely characterized by a less developed financial structure and a largely unbanked population, and this is the reason why fintech solutions have to look for creative ways to enhance the effectiveness of their fintech software.

One of those effective ways and the crux of this article is the design of mechanisms that enable two software components to communicate with each other using a set of definitions and protocols, but before we give a detailed exposition of how APIs work and how to integrate them on various websites, let us briefly study the emergence, role and the development of M Pesa, a leading payment technology company in Kenya.

The M in M-Pesa stands for 'Mobile' while the Pesa means Money or payment in the Swahili language. This fintech unicorn was established by Safaricom, the largest mobile phone operator in Kenya, as a banking alternative for thousands of unbanked Kenyans who barely had access to financial services. Like most innovations, the M-Pesa encountered a slow adoption at its inception; most people considered this high-end innovation an unnecessary sophistication. Soon enough, it gained enough ground through a series of improvements made to its software.

One major driver for fintech innovations, like M-Pesa, is the need for financial inclusion, and the need for economic liberation spurs the desire for financial inclusion itself. Many African countries are underdeveloped in almost every facet of the functioning of the society- there was a high rate of underdevelopment in technology till recently when fintech and other aspects of technology began to gain ground. However, there is an enduring rate of poverty in the continent. Still, innovations like the M-Pesa have come to remain and ensure that financial transactions are conducted technologically advanced.

Financial inclusion is an initiative that seeks to include residents without access to banks or who can’t afford the required minimum deposits in the digital banking era. For this initiative to succeed, different sectors must collaborate in sharing data with each other and build a meaningful digital platform. Hence, there is a cross-communication strategy employed by M-Pesa to ensure the rapid development of sub-Saharan Africa; the telecommunication (Safaricom) and the banking sector sectors are working together to create mobile banking services for those who are significantly limited when it comes to access to traditional banking services.

How M-Pesa Works

M-Pesa is an online banking system that provides its banking services through a SIM card. To be eligible for this service, you must purchase a Safaricom sim card and insert it into your mobile device. SMS messages allow you to make payments and transfer money to vendors, friends, and family members. That simple!

Hence, this is suggestive that there is no need to experience all the regulatory bottlenecks that come with traditional banking for you actually to carry out banking transactions. Users with no bank accounts can access various outlets distributed across the country. The money that needs to be stored is given to the kiosk attendant of a particular outlet, who transfers the amount in digital form to the user’s M-Pesa account.


IntaSend provides an easier and faster way for businesses to automate M-Pesa payments on their applications. IntaSend M-Pesa API integration helps you reduce time to market; developers are able to add payments and go live without delays that might be caused by the daraja approval and onboarding processes. In addition to M-Pesa support, IntaSend also provides other payment options that are automatically available with a single integration. These payment methods include card payments (Visa and MasterCard), Bank payments for disbursements, Bitcoin payments among others. Learn more about how to accept payments with IntaSend here. Sign up today to get started.

Cover photo by Douglas Lopes on Unsplash

© 2023 IntaSend. All rights reserved.