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

ActiveLibrary[API Development](/categories/api)

nyanumba-codes/mpesa
====================

MPESA Integration into Laravel and other php frameworks

1.2.0(9mo ago)1389MITPHPPHP &gt;=8.0

Since Jan 20Pushed 9mo agoCompare

[ Source](https://github.com/NyanumbaCodes/M-Pesa)[ Packagist](https://packagist.org/packages/nyanumba-codes/mpesa)[ RSS](/packages/nyanumba-codes-mpesa/feed)WikiDiscussions master Synced today

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

M-Pesa Integration for Laravel
==============================

[](#m-pesa-integration-for-laravel)

A robust PHP library for integrating Safaricom's M-Pesa API with Laravel applications. This package simplifies payments, QR code generation, and transaction management.

Features
--------

[](#features)

- Dynamic QR Code Generation
- STK Push (Customer Payment)
- C2B Simulations
- B2C Transactions
- Transaction Status Checks
- Account Balance Inquiry
- Reversals
- Secure Authentication

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

[](#installation)

Install via Composer:

```
composer require nyanumba-codes/mpesa
```

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

[](#configuration)

First Run the Installation:

```
php artisan mpesa:install {environment}
```

The Environment value can either be left blank, or written `sandbox` for The Sandbox Certificate file to be downloaded into the public folder or `production` for the Production Certificate to be downloaded.

```
# For Sandbox

php artisan mpesa:install

# or

php artisan mpesa:install sandbox
```

```
# For Production

php artisan mpesa:install production
```

Ensure the Safaricom public certificate (cert.cer) is stored securely under `public/mpesa`.

After this you may proceed to update your .env file. This one is rather longer this time round because all the MPESA APIs have been covered by this application. I have even separated all the Callbacks, Timeouts and Result URL to allow for development maleability.

```
# Environment (sandbox or production)
MPESA_ENV=sandbox

# Consumer credentials
MPESA_CONSUMER_KEY=your_consumer_key_here
MPESA_CONSUMER_SECRET=your_consumer_secret_here

# Security credential
MPESA_USERNAME=your_username_here
MPESA_SECURITY_CREDENTIAL=your_security_credential_here

# Shortcode and passkey
MPESA_SHORTCODE=your_shortcode_here
MPESA_PASSKEY=your_passkey_here

# C2B (Customer to Business) URLs
MPESA_C2B_CONFIRMATION=https://yourdomain.com/api/c2b/confirmation
MPESA_C2B_VALIDATION=https://yourdomain.com/api/c2b/validation

# Transaction status callback URLs
MPESA_TRANSACTION_RESULT=https://yourdomain.com/api/transaction/result
MPESA_TRANSACTION_TIMEOUT=https://yourdomain.com/api/transaction/timeout

# B2C (Business to Customer) URLs
MPESA_B2C_RESULT=https://yourdomain.com/api/b2c/result
MPESA_B2C_TIMEOUT=https://yourdomain.com/api/b2c/timeout

# B2C Top-Up URLs
MPESA_B2C_TOPUP_RESULT=https://yourdomain.com/api/b2c/topup/result
MPESA_B2C_TOPUP_TIMEOUT=https://yourdomain.com/api/b2c/topup/timeout

# Account balance inquiry URLs
MPESA_BALANCE_RESULT=https://yourdomain.com/api/balance/result
MPESA_BALANCE_TIMEOUT=https://yourdomain.com/api/balance/timeout

# Reversal request URLs
MPESA_REVERSAL_RESULT=https://yourdomain.com/api/reversal/result
MPESA_REVERSAL_TIMEOUT=https://yourdomain.com/api/reversal/timeout

# Tax inquiry URLs
MPESA_TAX_RESULT=https://yourdomain.com/api/tax/result
MPESA_TAX_TIMEOUT=https://yourdomain.com/api/tax/timeout

# Ratiba callback URL (if applicable)
MPESA_RATIBA_CALLBACK=https://yourdomain.com/api/ratiba/callback
```

Usage
-----

[](#usage)

Initialize the class where you wish to use it:

```
use NyanumbaCodes\Mpesa\Mpesa;

$mpesa = new Mpesa();
```

### 1. Generate Dynamic QR Code

[](#1-generate-dynamic-qr-code)

```
$response = $mpesa->dynamicQr('MerchantName', 'Ref123');
```

### 2. Process STK Push (MPESA Express Simulate)

[](#2-process-stk-push-mpesa-express-simulate)

```
$response = $mpesa->stkPush(100, '254700000000', 'AccountRef', 'TransactionDesc');
```

### 3. Process STK Push (MPESA Express Simulate)

[](#3-process-stk-push-mpesa-express-simulate)

```
$response = $mpesa->transactionStatus('TransactionID', 'originatorConversationID');
```

### 4. Perform C2B Simulation

[](#4-perform-c2b-simulation)

```
$response = $mpesa->c2bSimulate(100, '254700000000', 'Ref123');
```

### 5. Handle Reversals

[](#5-handle-reversals)

```
$response = $mpesa->reversal('TransactionID', 100);
```

License
-------

[](#license)

This package is open-source and licensed under the MIT License.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance56

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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

Total

2

Last Release

291d ago

### Community

Maintainers

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

### Embed Badge

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

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

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

725172.4k14](/packages/tallstackui-tallstackui)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k90.5k1](/packages/mike-bronner-laravel-model-caching)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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