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

ActiveLibrary[API Development](/categories/api)

joemuigai/laravel-mpesa
=======================

A Laravel Mpesa integration package

0.2.9(7mo ago)3406[2 PRs](https://github.com/Joemuigai/laravel-mpesa/pulls)MITPHPPHP ^8.4CI passing

Since Nov 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Joemuigai/laravel-mpesa)[ Packagist](https://packagist.org/packages/joemuigai/laravel-mpesa)[ Docs](https://github.com/joemuigai/laravel-mpesa)[ GitHub Sponsors](https://github.com/Joemuigai)[ RSS](/packages/joemuigai-laravel-mpesa/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (13)Versions (16)Used By (0)

Laravel M-Pesa
==============

[](#laravel-m-pesa)

```
 _                               _   __  __       ____
| |                             | | |  \/  |     |  _ \
| |     __ _ _ __ __ ___   _____| | | \  / |_____| |_) | ___  ___  __ _
| |    / _` | '__/ _` \ \ / / _ \ | | |\/| |_____|  __/ / _ \/ __|/ _` |
| |___| (_| | | | (_| |\ V /  __/ | | |  | |     | |   |  __/\__ \ (_| |
|______\__,_|_|  \__,_| \_/ \___|_| |_|  |_|     |_|    \___||___/\__,_|

                              by Joemuigai

```

[![Latest Version on Packagist](https://camo.githubusercontent.com/16518e192d6bcb69ab06db668557fcc127268f272ad36922abf5c9f8d25df389/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f656d75696761692f6c61726176656c2d6d706573612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/joemuigai/laravel-mpesa)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ce6874274ccc5119e8fda15fd7e59246296d39c9be0f14a86d9967ff3c74534b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6f656d75696761692f6c61726176656c2d6d706573612f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/joemuigai/laravel-mpesa/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/0e2ae47468b6f3167490c3f8425845a6c95b5db2a1020b2c0ac625633e0370f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f656d75696761692f6c61726176656c2d6d706573612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/joemuigai/laravel-mpesa)

A comprehensive, production-ready Laravel package for integrating with Safaricom's M-Pesa Daraja API. Built for both single-merchant applications and multi-tenant SaaS platforms.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Multi-Tenant Usage](#multi-tenant-usage)
- [Production Checklist](#production-checklist)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#features)

✨ **Complete API Coverage** - 11 M-Pesa APIs supported
🏢 **Multi-Tenant Ready** - Database-driven account management
💪 **Production Optimized** - HTTP retries, caching, and failsafe mechanisms
🎯 **Flexible** - Paybill &amp; Till Number (Buy Goods) support
🔧 **Developer Friendly** - Interactive installation, IDE autocomplete
🧪 **Well Tested** - Comprehensive test suite
📚 **Type Safe** - Full PHPDoc annotations

👉 **[View Full Features Guide](FEATURES.md)** for detailed capabilities.

Requirements
------------

[](#requirements)

- PHP 8.4+
- Laravel 11.0+ or 12.0+

Installation
------------

[](#installation)

Install via Composer:

```
composer require joemuigai/laravel-mpesa
```

Run the interactive installation command to set up configuration and migrations:

```
php artisan laravel-mpesa:install
```

The wizard will guide you through:

1. **Scenario Selection** (Single vs Multi-tenant)
2. **API Selection** (STK, C2B, B2C, etc.)
3. **Environment Setup**

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

[](#configuration)

### Environment Variables

[](#environment-variables)

After installation, add your credentials to `.env`:

```
# Core Credentials
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret
MPESA_ENVIRONMENT=sandbox  # or production

# STK Push
MPESA_STK_SHORTCODE=174379
MPESA_STK_PASSKEY=your_passkey
MPESA_STK_CALLBACK_URL=https://yourdomain.com/mpesa/callback
```

See `config/mpesa.php` for all available options.

Usage
-----

[](#usage)

For detailed code examples, payloads, and callback handling, please refer to the **[USAGE.md](USAGE.md)** file.

### Quick Example: STK Push

[](#quick-example-stk-push)

```
use Joemuigai\LaravelMpesa\Facades\LaravelMpesa;

try {
    $response = LaravelMpesa::stkPush(
        amount: 100,
        phoneNumber: '254712345678',
        reference: 'INV-001',
        description: 'Payment'
    );
} catch (\Exception $e) {
    // Handle error
}
```

### Supported APIs

[](#supported-apis)

- [STK Push (Lipa Na M-Pesa Online)](USAGE.md#1-stk-push-lipa-na-m-pesa-online)
- [STK Push Query](USAGE.md#2-stk-push-query)
- [C2B (Customer to Business)](USAGE.md#3-c2b-customer-to-business)
- [B2C (Business to Customer)](USAGE.md#4-b2c-business-to-customer)
- [B2B (Business to Business)](USAGE.md#5-b2b-business-to-business)
- [Transaction Status](USAGE.md#6-transaction-status)
- [Account Balance](USAGE.md#7-account-balance)
- [Reversal](USAGE.md#8-reversal)
- [Dynamic QR Code](USAGE.md#9-dynamic-qr-code)
- [Pull Transaction](USAGE.md#10-pull-transaction)

Multi-Tenant Usage
------------------

[](#multi-tenant-usage)

For SaaS platforms, you can switch accounts dynamically:

```
// Switch by Tenant ID
LaravelMpesa::forAccount('tenant-123')->stkPush(100, '254712345678');

// Switch by Model
$account = MpesaAccount::find(1);
LaravelMpesa::withAccount($account)->stkPush(100, '254712345678');
```

See the [Multi-Tenant Guide](USAGE.md#11-multi-tenant-usage) for database setup and more examples.

Production Checklist
--------------------

[](#production-checklist)

Before going live, ensure you have:

- Set `MPESA_ENVIRONMENT=production` in `.env`
- Updated `MPESA_CONSUMER_KEY` and `MPESA_CONSUMER_SECRET` with production credentials
- Enabled SSL verification (`MPESA_HTTP_VERIFY=true`)
- Configured **HTTPS** callback URLs (M-Pesa requires valid SSL)
- Set up logging to monitor `laravel-mpesa` channel or default logs
- Implemented `try-catch` blocks around all API calls
- Configured queue workers if processing callbacks asynchronously

Testing
-------

[](#testing)

Run the package test suite:

```
composer test
```

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

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover a security vulnerability, please email .

Credits
-------

[](#credits)

- [Joemuigai](https://github.com/joemuigai)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/joemuigai/laravel-mpesa/issues)
- **Email**:

---

Made with ❤️ in Kenya 🇰🇪

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance77

Regular maintenance activity

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.2% 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 ~1 days

Total

11

Last Release

214d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c3798ae23dea2e880c4625719e04818e5c002f8d117afa101c4582525e9fd128?d=identicon)[Joemuigai](/maintainers/Joemuigai)

---

Top Contributors

[![Joemuigai](https://avatars.githubusercontent.com/u/39778761?v=4)](https://github.com/Joemuigai "Joemuigai (75 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

daraja-apilaravellaravel-packagempesaphplaravellaravel mpesaJoemuigai

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)

PHPackages © 2026

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