PHPackages                             mxgel/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. [Payment Processing](/categories/payments)
4. /
5. mxgel/mpesa

ActiveLibrary[Payment Processing](/categories/payments)

mxgel/mpesa
===========

Safaricom M-Pesa integration

v1.13(8y ago)6621MITPHPPHP &gt;=5.6

Since May 11Pushed 7y ago2 watchersCompare

[ Source](https://github.com/murwa/mpesa)[ Packagist](https://packagist.org/packages/mxgel/mpesa)[ RSS](/packages/mxgel-mpesa/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (16)Used By (0)

README
======

[](#readme)

This is a non-official implementation of Safaricom's Mpesa G2 API

### How do I get set up?

[](#how-do-i-get-set-up)

The preferred way is installation via composer:-

`composer require mxgel/mpesa`

That's all.

#### Auth

[](#auth)

To communicate with the daraja APIs, you'll always require an access token. This has been simplified for you in this library. All you have to do is provide an instance of `Mxgel\MPesa\Auth\Auth` to the execute method. A piece of code like:-

```
    /**
     * @var Auth
     */
    private $auth;

    /**
     * @return \Mxgel\MPesa\Auth\Auth
     */
    public function getAuth(): Auth
    {
        if (!$this->auth) {
            return $this->auth = new Mxgel\MPesa\Auth\Auth([
                'key'    => config('key'),
                'secret' => config('secret'),
            ]);
        }

        return $this->auth;
    }

```

#### MPESA Express

[](#mpesa-express)

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

#### Example

[](#example)

Sample code (in Laravel) to initiate the payment can be something like this (use `Mxgel\MPesa\Requests\LNMO`).

```
$request = LNMO::make($amount, $phoneNumber, $shortCode, 'Wallet top up');
$request->setPassKey(config('LNMO_passkey'))
    ->setBusinessShortCode(config('LNMO_short_code'))
    ->setCallBackURL($callback);

$resp = $request->execute($this->getAuth());
Log::info('STk data', $request->toArray());

//NOTE: For a real application, save this details in a data store
```

We now need to write a callback that will receive data from safaricom upon request completion by the customer. **Remember to save request details above in a data store**

Here is a sample of the callback in laravel.

For easy handling of the received data, we use `Mxgel\MPesa\Responses\LNMOCallbackResponse` class. This strips away unnecessary data and just give us the juice.

```
// Assuming u have an Express model, u can have this.

Log::debug('LNMO Data', $this->request->all());
$resp = new LNMOCallbackResponse($this->request->get('Body'));
Express::whereMerchantRequestId($resp->getMerchantRequestID())
    ->whereCheckoutRequestId($resp->getCheckoutRequestID())
    ->whereConfirmed(false)                 // Ensure it's yet to be updated
    ->update([
        'receipt_number' => $resp->getMpesaReceiptNumber(),
        'confirmed'      => $resp->completed(),
    ]);
```

Sometimes you might want to write a cron job to update un-confirmed transactions. Luckily, we can use the status check api, and it's a breeze. Use `Mxgel\MPesa\Requests\LNMQ` class like so

```
$request = new LNMQ([
    'businessShortCode' => $business_short_code,
    'checkoutRequestID' => $checkout_request_id,
    'passKey'           => config('LNMO_passkey'),
]);

// Remember our auth object? Yes, we need it.
$resp = $request->execute($this->getAuth());
Log::info("Execute status with data: ", $request->toArray());
Log::info("Executed status check with response", $resp->toArray());
if ($resp->completed()) {
    // Your code here...
}
```

At this point, your STK should be fine.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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 ~0 days

Total

14

Last Release

2968d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4976870?v=4)[Peter Murwa](/maintainers/Murwa)[@murwa](https://github.com/murwa)

---

Top Contributors

[![murwa](https://avatars.githubusercontent.com/u/4976870?v=4)](https://github.com/murwa "murwa (54 commits)")

---

Tags

laravel-mpesampesa-apimpesa-api-laravelsafaricomsafaricom-daraja-laravelsafaricom-daraja-phpsafaricom-mpesa

### Embed Badge

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

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.0k](/packages/craftcms-cms)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M129](/packages/laravel-pulse)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M341](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M125](/packages/roots-acorn)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4851.0k](/packages/sebdesign-laravel-viva-payments)

PHPackages © 2026

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