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

ActiveLibrary[Payment Processing](/categories/payments)

keenops/laravel-mpesa
=====================

Laravel wrapper for the Vodacom M-Pesa API, providing a seamless integration experience for Laravel applications

v0.0.1-beta.2(1y ago)09MITPHPPHP ^7.4|^8.0

Since Nov 16Pushed 1y ago1 watchersCompare

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

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

Vodacom M-Pesa API package for Laravel
======================================

[](#vodacom-m-pesa-api-package-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/af019b228e80acfde283fbc27c23c2a2e179929e5ce0270cb6116db3e37af173/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b65656e6f70732f6c61726176656c2d6d706573612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/keenops/laravel-mpesa)[![Total Downloads](https://camo.githubusercontent.com/d2dc4e4833ddc2015822cb6d19168bdc84004ab73e2edc2baa43ae10466db019/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b65656e6f70732f6c61726176656c2d6d706573612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/keenops/laravel-mpesa)

Engineered for seamless integration with the Vodacom M-Pesa OpenApi, it offers Laravel developers a streamlined pathway to execute customer-to-business transactions with ease and efficiency.

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

[](#installation)

You can install the package via composer:

```
composer require keenops/laravel-mpesa:v0.0.1-beta.2
```

Runing the above command should also publish in a config directory a file named laravel-mpesa.php. If so didnt happen, publish the configuration files by running the command:

```
php artisan vendor:publish --tag=laravel-mpesa
```

Usage
-----

[](#usage)

Add Vodacom M-Pesa API credentials to a .env file. The credentials can be obtained [here](https://openapiportal.m-pesa.com/)

```
    MPESA_API_KEY= // get this from your mpesa developer/bussiness account
    MPESA_PUBLIC_KEY= // get this from your mpesa developer/bussiness account
    MPESA_ENVIROMENT= // options are: sandbox, openapi
    MPESA_MARKET_COUNTRY= // options are: TZN, GHA, LES, DRC
    MPESA_MARKET_CURRENCY= // options are: TZS, GHS, SLS, USD
```

### Customer to Business Transaction

[](#customer-to-business-transaction)

In your controller use like this

```
namespace App\Http\Controllers;

use Keenops\Mpesa\Mpesa;

class CheckoutController extends Controller
{
    public function checkout()
    {
        return Mpesa::c2b(
            amount: '1000',
            customerNumber:'255746277553',
            serviceCode: '000000',
            reference: 'T12344Z',
            description: 'Three items',
            conversationId: '1e9b774d1da34af78412a498cbc28f43e'
        );

        //this returns json response from M-Pesa API. Refer the link https://openapiportal.m-pesa.com/ for error and success codes
    }
}
```

### Business to Customer Transaction

[](#business-to-customer-transaction)

In your controller:

```
namespace App\Http\Controllers;

use Keenops\Mpesa\Mpesa;

class PayoutController extends Controller
{
    public function sendMoney()
    {
        return Mpesa::b2c(
            amount: '1000',
            customerNumber: '255746277553',
            serviceCode: '000000',
            reference: 'REF123456',
            description: 'Payment for services',
            conversationId: 'b2c12345678xyz'
        );

        // Returns JSON response from M-Pesa API.
    }
}
```

### Business to Business Transaction

[](#business-to-business-transaction)

In your controller:

```
namespace App\Http\Controllers;

use Keenops\Mpesa\Mpesa;

class TransferController extends Controller
{
    public function transfer()
    {
        return Mpesa::b2b(
            senderCode: '000001',
            receiverCode: '000002',
            amount: '50000',
            reference: 'B2BRef001',
            description: 'Supplier payment',
            conversationId: 'b2bconv112233'
        );

        // Returns JSON response from M-Pesa API.
    }
}
```

### Reverse a Transaction

[](#reverse-a-transaction)

In your controller:

```
namespace App\Http\Controllers;

use Keenops\Mpesa\Mpesa;

class ReversalController extends Controller
{
    public function reverseTransaction()
    {
        return Mpesa::reverse(
            amount: '1000',
            serviceProviderCode: '000000',
            conversationId: 'revConv778899',
            transactionId: 'Trans123456789'
        );

        // Returns JSON response from M-Pesa API.
    }
}
```

### Query Transaction Status

[](#query-transaction-status)

In your controller:

```
namespace App\Http\Controllers;

use Keenops\Mpesa\Mpesa;

class StatusController extends Controller
{
    public function checkStatus()
    {
        return Mpesa::transactionStatus(
            queryReference: 'REF123456',
            serviceProviderCode: '000000',
            conversationId: 'statusConv456789'
        );

        // Returns JSON response from M-Pesa API.
    }
}
```

### Errors

[](#errors)

Specific error codes may be displayed within parenthesis when send or receive operations fail. The most common of these error codes are specified in API documetation found on [openapiportal.m-pesa.com](https://openapiportal.m-pesa.com)

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

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

### Security

[](#security)

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

Credits
-------

[](#credits)

- [Kee Nops](https://github.com/keenops)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance46

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

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

Total

2

Last Release

414d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/979e7b5ad115c575c452f36f2316011ad49f9bb01cf45c5eb68d069af01ed64e?d=identicon)[kimwalu](/maintainers/kimwalu)

---

Top Contributors

[![keenops](https://avatars.githubusercontent.com/u/37520787?v=4)](https://github.com/keenops "keenops (7 commits)")

---

Tags

laravel mpesakeenops

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[amzn/amazon-pay-api-sdk-php

Amazon Pay API SDK (PHP)

505.1M9](/packages/amzn-amazon-pay-api-sdk-php)[amzn/amazon-pay-magento-2-module

Official Magento2 Plugin to integrate with Amazon Pay

109501.7k1](/packages/amzn-amazon-pay-magento-2-module)[sylius/paypal-plugin

PayPal plugin for Sylius.

451.4M4](/packages/sylius-paypal-plugin)[tpay-com/tpay-php

Tpay.com library

25260.3k9](/packages/tpay-com-tpay-php)[litle/payments-sdk

The Vantiv eCommerce PHP SDK is a PHP implementation of the \[Vantiv eCommerce\](https://developer.vantiv.com/community/ecommerce). XML API. This SDK was created to make it as easy as possible to connect process your payments with Vantiv eCommerce

19139.3k1](/packages/litle-payments-sdk)[saleh7/php-zatca-xml

An unofficial PHP library for generating ZATCA Fatoora e-invoices. This library facilitates the creation of compliant e-invoices, QR Codes, and certificates, as well as the submission of e-invoices to ZATCA's servers. It provides developers with an easy-to-use, customizable, and robust toolkit to integrate and automate ZATCA e-invoicing processes in PHP applications.

5112.5k](/packages/saleh7-php-zatca-xml)

PHPackages © 2026

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