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

ActiveLibrary[Payment Processing](/categories/payments)

itsmurumba/laravel-mpesa
========================

Laravel Package for Mpesa Daraja API

v1.0.8(6mo ago)2011.1k↑403.6%4MITPHPPHP ^7.1|^8.0|^8.1|^8.2|^8.3|^8.4CI passing

Since Nov 2Pushed 5mo ago4 watchersCompare

[ Source](https://github.com/ItsMurumba/laravel-mpesa)[ Packagist](https://packagist.org/packages/itsmurumba/laravel-mpesa)[ RSS](/packages/itsmurumba-laravel-mpesa/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (4)Versions (15)Used By (0)

Introduction
============

[](#introduction)

This is a Laravel package for Safaricom Mpesa Daraja API. It includes all public available endpoints:

- Consumer to Business (C2B) payments
- Business to Consumer (B2C) payments
- Mpesa Express Payment (Lipa Na Mpesa Online)
- Transaction Status
- Account Balance
- Reversal
- Business to Business (B2B) payments

Installation
============

[](#installation)

Run the following command to install Laravel Mpesa package in your Laravel project:

```
composer require itsmurumba/laravel-mpesa

```

If you are using **Laravel 5.5** and above, skip to the [**Configurations**](https://github.com/ItsMurumba/laravel-mpesa#configurations) step.

After running the composer require above, you should add a service provider and alias of the package in config/app.php file.(For Laravel 5.4 and below)

```
Itsmurumba\Mpesa\MpesaServiceProvider::class

```

Configurations
==============

[](#configurations)

After installing the package, run the following command to install `mpesa.php` configuartion file in the `config` folder:

```
php artisan mpesa:install

```

or

```
php artisan vendor:publish

```

Add and define the following variables in your `.env` file

```
MPESA_CONSUMER_KEY=
MPESA_CONSUMER_SECRET=
MPESA_CALLBACK_URL=
MPESA_BASE_URL=https://sandbox.safaricom.co.ke
MPESA_PAYBILL_NUMBER=600978
LIPA_NA_MPESA_SHORTCODE=174379
LIPA_NA_MPESA_CALLBACK_URL=
LIPA_NA_MPESA_PASSKEY=
MPESA_CONFIRMATION_URL=
MPESA_VALIDATION_URL=
MPESA_INITIATOR_USERNAME=
MPESA_INITIATOR_PASSWORD=
MPESA_ENVIRONMENT=sandbox
MPESA_QUEUE_TIMEOUT_URL=
MPESA_RESULT_URL=

```

Usage
=====

[](#usage)

Add the following constructor inside your controller:

```
protected $mpesa;

public function __construct(){
    $this->mpesa = new Mpesa();
}

```

**1. Mpesa Express Payment (Lipa Na Mpesa Online)**

```
$this->mpesa->expressPayment($amount, $phoneNumber, $accountReference = 'CompanyXLTD', $transactionDescription = 'Payment of X');

```

- $phoneNumber = 254XXXXXXXXX
- $accountReference = Account Reference (maximum 12 characters)
- transactionDescription = Transaction Description (1-13 characters)

**2. Mpesa Express Payment Query (Lipa Na Mpesa Online)**

```
$this->mpesa->expressPaymentQuery($checkoutRequestId);

```

**3. C2B Register URLs**

```
$this->mpesa->c2bRegisterURLs();

```

**4. Consumer to Business (C2B) payments**

```
$this->mpesa->c2bPaymentc2bPayment($commandId, $amount, $phoneNumber, $billRefNumber);

```

- $commandId = can only be set to **CustomerPayBillOnline** or **CustomerBuyGoodsOnline**
- $billRefNumber = used on CustomerPayBillOnline option only e.g an Account Number. Set the value to `''` when commandId is **CustomerBuyGoodsOnline**

**5. Business to Consumer (B2C) payments**

```
$this->mpesa->b2cPayment($commandId, $amount, $phoneNumber, $remarks, $occassion = '');

```

**6. Transaction Status**

```
$this->mpesa->transactionStatus($transactionId, $identifierType, $remarks, $occassion = '');

```

**7. Account Balance**

```
$this->mpesa->accountBalance($identifierType, $remarks);

```

**8. Reversal**

```
$this->mpesa->reversals($transactionId, $amount, $receiverParty, $receiverIdentifierType, $remarks, $occasion = '');

```

**9. Business to Business Payment(B2B)**

```
$this->mpesa->b2bPayment($commandId, $amount, $receiverShortcode, $accountReference, $remarks);

```

Contribution
============

[](#contribution)

This is a community package and thus welcome anyone intrested to contribute in improving the package. Kindly go through the [Contribution.md](Contribution.md) before starting to contribute. Keep those PRs and Issues coming.

Buy Me Coffee
=============

[](#buy-me-coffee)

Give this repo a star and i will have my super powers recharged. You can also follow me on twitter [@ItsMurumba](https://twitter.com/ItsMurumba)

License
=======

[](#license)

This package is licensed under the MIT License. Please review the [License](LICENSE.md) file for details

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance69

Regular maintenance activity

Popularity37

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

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

Recently: every ~294 days

Total

9

Last Release

203d ago

PHP version history (4 changes)v1.0.5PHP ^7.1|^8.0

v1.0.6PHP ^7.1|^8.0|^8.1

v1.0.7PHP ^7.1|^8.0|^8.1|^8.2

v1.0.8PHP ^7.1|^8.0|^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/53953afbbecd70ed72b7b0f564e1ef0c44f55b4a1c81535402bc7de8dc3ad078?d=identicon)[ItsMurumba](/maintainers/ItsMurumba)

---

Top Contributors

[![ItsMurumba](https://avatars.githubusercontent.com/u/16638199?v=4)](https://github.com/ItsMurumba "ItsMurumba (132 commits)")

---

Tags

daraja-apidaraja-mpesadaraja-mpesa-laravelhacktoberfestlaravel-mpesampesa-apimpesa-sdkpayment-integrationlaravellaravel 6laravel 7laravel 8laravel 9laravel 10laravel 11laravel 12paymentslaravel 5mpesadarajaitsmurumba

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[salmanzafar/laravel-mqtt

A simple Laravel Library to connect/publish/subscribe to MQTT broker

102158.3k1](/packages/salmanzafar-laravel-mqtt)[ip2location/ip2proxy-laravel

Allows user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.

1072.9k](/packages/ip2location-ip2proxy-laravel)[prevailexcel/laravel-nowpayments

A Laravel Package for NOWPayments

1421.1k](/packages/prevailexcel-laravel-nowpayments)

PHPackages © 2026

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