PHPackages                             ivantoz/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. ivantoz/mpesa

ActivePackage

ivantoz/mpesa
=============

A PHP package for Mpesa API

1.1.1(7y ago)0361mitPHPPHP &gt;=5.3.0

Since Oct 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ivantoz/mpesa-php-sdk)[ Packagist](https://packagist.org/packages/ivantoz/mpesa)[ RSS](/packages/ivantoz-mpesa/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)DependenciesVersions (12)Used By (0)

**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 ivantoz/mpesa`

**Configuration**
At your project root, create a .env file and in it set the consumer key and consumer secret as follows
`MPESA_CONSUMER_KEY= [consumer key]`
`MPESA_CONSUMER_SECRET=[consumer secret]`
`MPESA_ENV=[live or sandbox]`
For Laravel users, open the Config/App.php file and add `\Ivantoz\Mpesa\MpesaServiceProvider::class` under providers and ` 'Mpesa'=> \Ivantoz\Mpesa\MpesaServiceProvider::class` under aliases.

*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 \Ivantoz\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)

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

`$balanceInquiry=$mpesa->accountBalance($CommandID, $Initiator, $SecurityCredential, $PartyA, $IdentifierType, $Remarks, $QueueTimeOutURL, $ResultURL);`

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

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

`$trasactionStatus=$mpesa->transactionStatus($Initiator, $SecurityCredential, $CommandID, $TransactionID, $PartyA, $IdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion);`

**C2B Payment Request**

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

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

`$b2bTransaction=$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 \Ivantoz\Mpesa\Mpesa();`

`$stkPushSimulation=$mpesa->STKPushSimulation($BusinessShortCode, $LipaNaMpesaPasskey, $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 \Ivantoz\Mpesa\Mpesa();`

`$STKPushRequestStatus=$mpesa->STKPushQuery($checkoutRequestID,$businessShortCode,$password,$timestamp);`

**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 \Ivantoz\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 \Ivantoz\Mpesa\Mpesa();`

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

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

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

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

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 78.3% 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

Every ~38 days

Recently: every ~12 days

Total

11

Last Release

2745d ago

### Community

---

Top Contributors

[![mossey](https://avatars.githubusercontent.com/u/5586471?v=4)](https://github.com/mossey "mossey (18 commits)")[![ialeke](https://avatars.githubusercontent.com/u/19324937?v=4)](https://github.com/ialeke "ialeke (1 commits)")[![NicholasKimuli](https://avatars.githubusercontent.com/u/7324617?v=4)](https://github.com/NicholasKimuli "NicholasKimuli (1 commits)")[![sadick254](https://avatars.githubusercontent.com/u/5238135?v=4)](https://github.com/sadick254 "sadick254 (1 commits)")[![urandu](https://avatars.githubusercontent.com/u/4688675?v=4)](https://github.com/urandu "urandu (1 commits)")[![wangai](https://avatars.githubusercontent.com/u/17968690?v=4)](https://github.com/wangai "wangai (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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