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

ActiveLibrary[Payment Processing](/categories/payments)

tfs/mpesa
=========

Modern Laravel package for Safaricom M-Pesa Daraja API integration with comprehensive B2C, B2B, STK Push, and Balance inquiry support

v3.0.15(3mo ago)0238MITPHPPHP ^7.4|^8.0|^8.1|^8.2|^8.3

Since Aug 16Pushed 3mo agoCompare

[ Source](https://github.com/24sevendevs/mpesa)[ Packagist](https://packagist.org/packages/tfs/mpesa)[ Docs](https://github.com/24sevendevs/mpesa)[ RSS](/packages/tfs-mpesa/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (18)Used By (0)

Safaricom M-Pesa Daraja API Laravel Package
===========================================

[](#safaricom-m-pesa-daraja-api-laravel-package)

[![Issues](https://camo.githubusercontent.com/ea925dfa4b2660c02e2c40351c707eed91ac0a4a3344b48fa7db539e7c681878/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f3234736576656e646576732f6d706573613f7374796c653d666c61742d737175617265)](https://github.com/24sevendevs/mpesa/issues)[![Stars](https://camo.githubusercontent.com/8904904aeba133e665eab6cb29ba6521f7bb615c276a26cb7259d17e2669b740/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f3234736576656e646576732f6d706573613f7374796c653d666c61742d737175617265)](https://github.com/24sevendevs/mpesa/stargazers)

A modern Laravel package for Safaricom's M-Pesa Daraja API. Supports **PHP 7.4+** and **PHP 8.x** with a flexible API that works with both array parameters and named arguments.

Features
--------

[](#features)

- ✅ **STK Push (M-Pesa Express)** - Prompt customers to pay via M-Pesa
- ✅ **B2C Payments** - Send money to customers
- ✅ **B2B Payments** - PayBill, BuyGoods, PayToPochi
- ✅ **Account Balance** - Check your M-Pesa balance
- ✅ **C2B URL Registration** - Register validation/confirmation URLs
- ✅ **Dual API Style** - Arrays (PHP 7.4+) or Named Arguments (PHP 8.0+)
- ✅ **Token Caching** - Automatic access token management
- ✅ **Custom Auth** - Override credentials per transaction

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

[](#requirements)

PHP VersionSupportedRecommended Style7.4✅Array parameters8.0+✅Named argumentsInstallation
------------

[](#installation)

```
composer require tfs/mpesa:^3.0
```

Publish configuration:

```
php artisan vendor:publish --provider="TFS\Mpesa\MpesaServiceProvider"
```

Usage Styles
------------

[](#usage-styles)

This package supports **two parameter styles** for maximum compatibility:

### Style 1: Array Parameters (PHP 7.4+)

[](#style-1-array-parameters-php-74)

```
use TFS\Mpesa\Mpesa;

$response = Mpesa::stkPush([
    'phone' => '254712345678',
    'amount' => '100',
    'account_reference' => 'INV-12345',
    'transaction_desc' => 'Payment for order',
]);
```

### Style 2: Named Arguments (PHP 8.0+)

[](#style-2-named-arguments-php-80)

```
use TFS\Mpesa\Mpesa;

$response = Mpesa::stkPush(
    phone: '254712345678',
    amount: '100',
    accountReference: 'INV-12345',
    transactionDesc: 'Payment for order'
);
```

### Style 3: Positional Arguments (Both)

[](#style-3-positional-arguments-both)

```
$response = Mpesa::stkPush('254712345678', '100', 'INV-12345', 'Payment');
```

---

API Reference
-------------

[](#api-reference)

### STK Push (M-Pesa Express)

[](#stk-push-m-pesa-express)

Prompt a customer to enter their M-Pesa PIN:

```
// PHP 7.4+ (Array)
$response = Mpesa::stkPush([
    'phone' => '254712345678',
    'amount' => '100',
    'account_reference' => 'INV-12345',
    'transaction_desc' => 'Payment for order',
    'callback' => 'https://yourdomain.com/callback', // optional
]);

// PHP 8.0+ (Named Arguments)
$response = Mpesa::stkPush(
    phone: '254712345678',
    amount: '100',
    accountReference: 'INV-12345',
    transactionDesc: 'Payment for order',
    callback: 'https://yourdomain.com/callback'
);
```

#### Query STK Push Status

[](#query-stk-push-status)

```
// PHP 7.4+
$response = Mpesa::stkQuery(['checkout_request_id' => 'ws_CO_123456']);

// PHP 8.0+
$response = Mpesa::stkQuery(checkoutRequestId: 'ws_CO_123456');

// Positional
$response = Mpesa::stkQuery('ws_CO_123456');
```

---

### B2C (Business to Customer)

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

Send money to a customer:

```
// PHP 7.4+ (Array)
$response = Mpesa::b2c([
    'phone' => '254712345678',
    'amount' => '1000',
    'occasion' => 'Salary',
    'remarks' => 'Monthly salary payment',
    'command_id' => 'SalaryPayment', // SalaryPayment | BusinessPayment | PromotionPayment
]);

// PHP 8.0+ (Named Arguments)
$response = Mpesa::b2c(
    phone: '254712345678',
    amount: '1000',
    occasion: 'Salary',
    remarks: 'Monthly salary payment',
    commandId: 'SalaryPayment'
);
```

---

### B2B PayBill

[](#b2b-paybill)

Pay a bill to another business:

```
// PHP 7.4+
$response = Mpesa::b2bPayBill([
    'party_b' => '888880',
    'amount' => '1000',
    'account_reference' => 'ACC-12345',
    'remarks' => 'Payment for services',
    'requester' => '254712345678', // optional - on behalf of
]);

// PHP 8.0+
$response = Mpesa::b2bPayBill(
    partyB: '888880',
    amount: '1000',
    accountReference: 'ACC-12345',
    remarks: 'Payment for services'
);
```

---

### B2B BuyGoods

[](#b2b-buygoods)

Pay to a till number:

```
// PHP 7.4+
$response = Mpesa::b2bBuyGoods([
    'party_b' => '888880',
    'amount' => '500',
    'account_reference' => 'ORDER-789',
    'remarks' => 'Payment for goods',
]);

// PHP 8.0+
$response = Mpesa::b2bBuyGoods(
    partyB: '888880',
    amount: '500',
    accountReference: 'ORDER-789',
    remarks: 'Payment for goods'
);
```

---

### B2 Pochi (Business Wallet)

[](#b2-pochi-business-wallet)

Send to a business wallet:

```
// PHP 7.4+
$response = Mpesa::b2Pochi([
    'party_b' => '254712345678',
    'amount' => '1000',
    'occasion' => 'Payment',
    'remarks' => 'Business payment',
    'originator_conversation_id' => 'CONV-' . time(),
]);

// PHP 8.0+
$response = Mpesa::b2Pochi(
    partyB: '254712345678',
    amount: '1000',
    occasion: 'Payment',
    remarks: 'Business payment',
    originatorConversationId: 'CONV-' . time()
);
```

---

### Account Balance

[](#account-balance)

Check your M-Pesa balance:

```
// PHP 7.4+
$response = Mpesa::balance([
    'party_a' => '600000',
    'remarks' => 'Balance inquiry',
    'identifier_type' => 4, // 1=MSISDN, 2=Till, 4=Shortcode
]);

// PHP 8.0+
$response = Mpesa::balance(
    partyA: '600000',
    remarks: 'Balance inquiry',
    identifierType: 4
);
```

---

### C2B URL Registration

[](#c2b-url-registration)

Register validation and confirmation URLs:

```
// PHP 7.4+
$response = Mpesa::registerC2BUrl([
    'validation_url' => 'https://yourdomain.com/api/c2b/validation',
    'confirmation_url' => 'https://yourdomain.com/api/c2b/confirmation',
    'response_type' => 'Completed', // Completed | Canceled
]);

// PHP 8.0+
$response = Mpesa::registerC2BUrl(
    validationUrl: 'https://yourdomain.com/api/c2b/validation',
    confirmationUrl: 'https://yourdomain.com/api/c2b/confirmation',
    responseType: 'Completed'
);
```

---

Custom Authentication
---------------------

[](#custom-authentication)

Override credentials per request (useful for multi-tenant apps):

```
// PHP 7.4+ (include 'auth' key in array)
$response = Mpesa::stkPush([
    'phone' => '254712345678',
    'amount' => '100',
    'account_reference' => 'INV-123',
    'transaction_desc' => 'Payment',
    'auth' => [
        'consumer_key' => 'different_key',
        'consumer_secret' => 'different_secret',
        'shortcode' => '123456',
        'passkey' => 'different_passkey',
    ],
]);

// PHP 8.0+
$response = Mpesa::stkPush(
    phone: '254712345678',
    amount: '100',
    accountReference: 'INV-123',
    transactionDesc: 'Payment',
    auth: [
        'consumer_key' => 'different_key',
        'consumer_secret' => 'different_secret',
    ]
);
```

---

Parameter Reference
-------------------

[](#parameter-reference)

### Key Naming Convention

[](#key-naming-convention)

Both `camelCase` and `snake_case` keys are supported in arrays:

camelCasesnake\_caseDescription`accountReference``account_reference`Payment reference`transactionDesc``transaction_desc`Transaction description`checkoutRequestId``checkout_request_id`STK query ID`partyB``party_b`Recipient shortcode/phone`partyA``party_a`Sender shortcode`commandId``command_id`B2C command type`identifierType``identifier_type`Balance identifier`originatorConversationId``originator_conversation_id`Pochi conversation ID`validationUrl``validation_url`C2B validation URL`confirmationUrl``confirmation\_url

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance81

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 94.1% 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 ~124 days

Recently: every ~207 days

Total

17

Last Release

101d ago

Major Versions

v1.2.1 → v2.0.02021-09-05

v2.1.1 → v3.0.02026-01-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea539cedbbb0521cc64c7af7c70d36fa433afa46b7301abd676495dc33630049?d=identicon)[24sevendevs](/maintainers/24sevendevs)

---

Top Contributors

[![kelvinthiongo](https://avatars.githubusercontent.com/u/44053091?v=4)](https://github.com/kelvinthiongo "kelvinthiongo (32 commits)")[![24sevendevs](https://avatars.githubusercontent.com/u/52048470?v=4)](https://github.com/24sevendevs "24sevendevs (2 commits)")

---

Tags

laravelpaymentb2bpayment gatewaympesamobile-moneykenyaB2Csafaricomdarajastk-pushlipa-na-mpesa

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)[itsmurumba/laravel-mpesa

Laravel Package for Mpesa Daraja API

191.6k](/packages/itsmurumba-laravel-mpesa)

PHPackages © 2026

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