PHPackages                             ongudidan/mpesa - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ongudidan/mpesa

ActiveLibrary[API Development](/categories/api)

ongudidan/mpesa
===============

This is a daraja API package used to connect all the services offered like C2B, B2C, B2B etc...

v1.0.0(1y ago)05PHP

Since Apr 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ongudidan/mpesa)[ Packagist](https://packagist.org/packages/ongudidan/mpesa)[ RSS](/packages/ongudidan-mpesa/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

mpesa
=====

[](#mpesa)

**Introduction**

This package seeks to help php developers implement the various Mpesa APIs without much hustle. It is based on the REST API whose documentation is available on .

**Installation using composer**
`composer require ongudidan/mpesa`

**Configuration**
At your project root, create a yii2.cfg file and in it set the consumer key and consumer secret as follows
`MPESA_CONSUMER_KEY= "consumer key"`
`MPESA_INITIATOR= "username for the user with the assigned permissions"`
`MPESA_INITIATOR_PASSWORD= "password for that user"`
`MPESA_CONSUMER_SECRET="consumer secret"`
`MPESA_BUSINESS_SHORTCODE=" enter business shortcode eg  174379"`
`LIPA_NA_MPESA_PASSKEY="enter lipa na mpesa passkey eg bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919"`

*Remember to edit the consumer\_key and consumer\_secret values appropriately when switching between sandbox and live*

**Usage**

**Confirmation and validation urls**

**B2C Payment Request**

This creates transaction between an M-Pesa short code to a phone number registered on M-Pesa.

`$mpesa= new \Mpesa\Mpesa();`

`$b2cTransaction=$mpesa->b2c($InitiatorName, $SecurityCredential, $CommandID, $Amount, $PartyA, $PartyB, $Remarks, $QueueTimeOutURL, $ResultURL, $Occasion);`

**Account Balance Request**

This is used to enquire the balance on an M-Pesa BuyGoods (Till Number or Pay Bill)

`$mpesa= new \Mpesa\Mpesa();`

`$balanceInquiry=$mpesa->accountBalance($IdentifierType, $QueueTimeOutURL, $ResultURL);`

**Transaction Status Request**This is used to check the status of transaction.

`$mpesa= new \Mpesa\Mpesa();`

`$trasactionStatus=$mpesa->transactionStatus($TransactionID, $IdentifierType, $ResultURL, $QueueTimeOutURL);`

**B2B Payment Request**

This is used to transfer funds between two companies.

`$mpesa= new \Mpesa\Mpesa();`

`$b2bTransaction=$mpesa->b2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );`

**C2B Payment Request**

This is used to Simulate transfer of funds between a customer and business.

`$mpesa= new \Mpesa\Mpesa();`

`$c2bTransaction=$mpesa->c2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );`

*Also important to note is that you should have registered validation and confirmation urls where the callback responses will be sent.*

**STK Push Simulation**

This is used to initiate online payment on behalf of a customer.

`$mpesa= new \Mpesa\Mpesa();`

`$stkPushSimulation = $mpesa->STKPushSimulation($TransactionType, $Amount, $PartyA, $PartyB, $PhoneNumber, $CallBackURL, $AccountReference, $TransactionDesc, $Remarks);`

**STK Push Status Query**

This is used to check the status of a Lipa Na M-Pesa Online Payment.

`$mpesa= new \Mpesa\Mpesa();`

`$STKPushRequestStatus = $mpesa->STKPushQuery($checkoutRequestID);`

**Callback Routes**M-Pesa APIs are asynchronous. When a valid M-Pesa API request is received by the API Gateway, it is sent to M-Pesa where it is added to a queue. M-Pesa then processes the requests in the queue and sends a response to the API Gateway which then forwards the response to the URL registered in the CallBackURL or ResultURL request parameter. Whenever M-Pesa receives more requests than the queue can handle, M-Pesa responds by rejecting any more requests and the API Gateway sends a queue timeout response to the URL registered in the QueueTimeOutURL request parameter.

**Obtaining post data from callbacks**This is used to get post data from callback in json format. The data can be decoded and stored in a database.

`$mpesa= new \Mpesa\Mpesa();`

`$callbackData=$mpesa->getDataFromCallback();`

**Finishing a transaction**After obtaining the Post data from the callbacks, use this at the end of your callback routes to complete the transaction

`$mpesa= new \Mpesa\Mpesa();`

`$callbackData=$mpesa->finishTransaction();`

If validation fails, pass `false` to `finishTransaction()`

`$mpesa= new \Mpesa\Mpesa();`

`$callbackData=$mpesa->finishTransaction(false);`

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance46

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

411d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/43ad5b4ed785d15200922c40f836a6b8661e274cf57ad50c53a8cb1552beb86f?d=identicon)[ongudidan](/maintainers/ongudidan)

---

Top Contributors

[![ongudidan](https://avatars.githubusercontent.com/u/153520866?v=4)](https://github.com/ongudidan "ongudidan (12 commits)")

### Embed Badge

![Health badge](/badges/ongudidan-mpesa/health.svg)

```
[![Health](https://phpackages.com/badges/ongudidan-mpesa/health.svg)](https://phpackages.com/packages/ongudidan-mpesa)
```

###  Alternatives

[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

640431.7k4](/packages/netflie-whatsapp-cloud-api)[showdoc/showdoc

ShowDoc is a tool greatly applicable for an IT team to share documents online

12.8k7.0k](/packages/showdoc-showdoc)[wrav/oembed

A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.

36205.0k3](/packages/wrav-oembed)[lucianotonet/groq-php

A powerful PHP library for seamless integration with the GroqCloud API

83124.5k6](/packages/lucianotonet-groq-php)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[unicodeveloper/jusibe-php-lib

Jusibe PHP Library

3417.4k1](/packages/unicodeveloper-jusibe-php-lib)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
