PHPackages                             tumainimosha/laravel-mpesa-push - 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. tumainimosha/laravel-mpesa-push

ActiveLibrary[API Development](/categories/api)

tumainimosha/laravel-mpesa-push
===============================

Laravel package for TZ Mpesa USSD Push integration

0.3.1(2y ago)10694↓75%4MITPHPPHP &gt;=7.1.3CI failing

Since Apr 12Pushed 2y ago3 watchersCompare

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

READMEChangelogDependencies (7)Versions (6)Used By (0)

Mpesa (Tz) Push API - Laravel Package
=====================================

[](#mpesa-tz-push-api---laravel-package)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)![Travis](https://camo.githubusercontent.com/1b25d480b3978d9108b26cc6ebe41e15bc508e2bfa698ee972c64b86eaeb747e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f74756d61696e696d6f7368612f6c61726176656c2d6d706573612d707573682e7376673f7374796c653d666c61742d737175617265)[![Total Downloads](https://camo.githubusercontent.com/f1d48cbb50e9597078972938bfbd22fbecead6f70e4d184560c1d0dc2126c04a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74756d61696e696d6f7368612f6c61726176656c2d6d706573612d707573682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tumainimosha/laravel-mpesa-push)

Install
-------

[](#install)

Install via composer

```
composer require tumainimosha/laravel-mpesa-push
```

### Publish Configuration File

[](#publish-configuration-file)

Publish config file to customize the default package config.

```
php artisan vendor:publish --provider="Tumainimosha\MpesaPush\MpesaPushServiceProvider" --tag="config"
```

### Publish Migrations

[](#publish-migrations)

```
php artisan vendor:publish --provider="Tumainimosha\MpesaPush\MpesaPushServiceProvider" --tag="migrations"
php artisan migrate
```

Configuration
-------------

[](#configuration)

### Authentication

[](#authentication)

Configure your api username and password in `.env` file as follows

```
TZ_MPESA_PUSH_SSL_CERT_PASSWORD=secret
TZ_MPESA_PUSH_USERNAME=123123
TZ_MPESA_PUSH_PASSWORD=VeryStrongPasswd
TZ_MPESA_PUSH_BUSINESS_NAME=FooCompany
TZ_MPESA_PUSH_BUSINESS_NUMBER=123123
```

Other configuration can be found in the config file published by this package. The options are well commented 😊

Usage
-----

[](#usage)

```
use Tumainimosha\MpesaPush\MpesaPush;

...

public function testPush() {

    // Resolve service object
    $push = MpesaPush::instance();

    $customerMsisdn = '';
    $amount = 250;
    $txnId = str_random('20');

    $responseCode = $push->postRequest($customerMsisdn, $amount, $txnId);

    // Check for response code
    // Valid response codes
    //  '0' - Success (note: response code is string '0' not numeric 0)
    //  'Duplicate' - Duplicate transaction ID
    //   Others - fail

}

```

### Handling callback

[](#handling-callback)

Out of the box, this package stores transactions in table `mpesa_push_transactions`, and updates their status on receiving callback.

However, you may need to do further actions on your app after receiving callback, by listening to event `MpesaCallbackReceived::class` fired at callback.

You need to implement your own event listener to listen for this event and do any additional steps after receiving callback.

The event has public attribute `$transaction` which contains the transaction parameters including status

```
// EventServiceProvider.php

protected $listen = [
    ...
    \Tumainimosha\MpesaPush\Events\MpesaCallbackReceived::class => [
        \App\Listeners\MpesaCallbackReceivedHandler::class,
    ],
];

// MpesaCallbackReceivedHandler.php

public function handle(MpesaCallbackReceived $event)
{
    $transaction = $event->transaction;

    // do your custom logic here
}
```

### Customize config values at runtime

[](#customize-config-values-at-runtime)

The service offers fluent setters to change config values at runtime if your use case requires.

Such a use case could be when you have multiple accounts on the same project, and you fetch your config values from DB.

```
// $account here could be a Model fetched from db with account attributes
$pushService = MpesaPush::instance();

$pushService->setUsername($account->username)
    ->setPassword($account->password)
    ->setBusinessName($account->business_name)
    ->setBusinessNumber($account->business_number)
    ->setCommand($account->command);

$pushService->postRequest($customerMsisdn, $amount, $txnId);
```

Testing
-------

[](#testing)

Run the tests with:

```
vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### TODO

[](#todo)

- Login
- Push Transaction request
- Callback processing
- More documentation and examples
- Unit testing

\*\* Help needed with improving documentation and unit testing. Pull Requests are welcome.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](/LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Every ~542 days

Total

4

Last Release

967d ago

PHP version history (2 changes)0.1.0PHP ^7.1.3

0.3.0PHP &gt;=7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bbce5f012137c58d5dfeeba9820bf091177baf88a0c3366258a0838315d3621?d=identicon)[tumainimosha](/maintainers/tumainimosha)

---

Top Contributors

[![tumainimosha](https://avatars.githubusercontent.com/u/7481490?v=4)](https://github.com/tumainimosha "tumainimosha (17 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/tumainimosha-laravel-mpesa-push/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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