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

ActiveLibrary[Payment Processing](/categories/payments)

paymentsds/mpesa
================

PHP client library for MPesa API

1.0.1(3y ago)392.9k26[4 PRs](https://github.com/paymentsds/mpesa-php-sdk/pulls)Apache-2.0PHPPHP &gt;=7.2

Since Jun 30Pushed 2y ago7 watchersCompare

[ Source](https://github.com/paymentsds/mpesa-php-sdk)[ Packagist](https://packagist.org/packages/paymentsds/mpesa)[ RSS](/packages/paymentsds-mpesa/feed)WikiDiscussions develop Synced 1mo ago

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

PHP M-Pesa SDK
==============

[](#php-m-pesa-sdk)

[![Total Downloads](https://camo.githubusercontent.com/7447d628cbefdff442ee980062546b548b3489e5ff195899b5ccdd0e97b0feae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7061796d656e747364732f6d70657361)](https://github.com/paymentsds/mpesa-php-sdk)[![Latest Stable Version](https://camo.githubusercontent.com/e8bd23d2db4a6151dd7c4406edba5ecc5441b7434c904001fc5540c8382f1294/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7061796d656e747364732f6d706573612d7068702d73646b3f696e636c7564655f70726572656c6561736573)](https://packagist.org/packages/paymentsds/mpesa)[![License](https://camo.githubusercontent.com/5b60841bea9e11d9d0b0950d690c9bc554e06385634056a7d5d62a15d1a4eabe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4170616368655f322e302d626c75652e737667)](https://opensource.org/licenses/Apache-2.0)

This is a library willing to help you to integrate the [Vodacom M-Pesa](https://developer.mpesa.vm.co.mz) operations to your application.

### Features

[](#features)

Using this library, you can implement the following operations:

- Receive money from a mobile account to a business account (C2B)
- Send money from a business account to a mobile account (B2C)
- Send money from a business account to another business account (B2B)
- Revert any of the transactions above mentioned
- Query the status of a transaction

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

[](#requirements)

- [PHP 7.2+](https://php.net/downloads)
- [Composer](https://getcomposer.org)
- Valid credentials obtained from the [Mpesa Developer](https://developer.mpesa.vm.co.mz) portal
- Port 18352 open on your server (usually open on local env)

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

[](#installation)

### Using Composer

[](#using-composer)

```
composer require paymentsds/mpesa
```

### Manual Installation

[](#manual-installation)

```
git clone https://github.com/paymentsds/mpesa-php-sdk mpesa-php-sdk
cd mpesa-php-sdk
composer install
```

Usage
-----

[](#usage)

Using this SDK is very simple and fast, let us see some examples:

#### C2B Transaction (Receive money from mobile account)

[](#c2b-transaction-receive-money-from-mobile-account)

```
use Paymentsds\MPesa\Client;
use Paymentsds\MPesa\Environment;

$client = new Client([
   'apiKey' => '',             // API Key
   'publicKey' => '',          // Public Key
   'serviceProviderCode' => '' // Service Provider Code
   'environment' =>  Environment::SANDBOX // Environment. Use Environment::PRODUCTION  for production
]);

$paymentData = [
   'from' => '841234567',       // Customer MSISDN
   'reference' => '11114',      // Third Party Reference
   'transaction' => 'T12344CC', // Transaction Reference
   'amount' => '10'             // Amount
];

$result = $client->receive($paymentData);

if ($result->success) {
   // Handle success
} else {
   // Handle failure
}
```

#### B2C Transaction (Sending money to mobile account)

[](#b2c-transaction-sending-money-to-mobile-account)

```
use Paymentsds\MPesa\Client;

$client = new Client([
   'apiKey' => '',             // API Key
   'publicKey' => '',          // Public Key
   'serviceProviderCode' => '' // Service Provider Code
]);

$paymentData = [
   'to' => '841234567',       // Customer MSISDN
   'reference' => '11114',      // Third Party Reference
   'transaction' => 'T12344CC', // Transaction Reference
   'amount' => '10'             // Amount
];

$result = $client->send($paymentData);

if ($result->success) {
   // Handle success scenario
} else {
   // Handle failure scenario
}
```

#### B2B Transaction (Sending money to business account)

[](#b2b-transaction-sending-money-to-business-account)

```
$client = new Client([
   'apiKey' => '',             // API Key
   'publicKey' => '',          // Public Key
   'serviceProviderCode' => '' // Service Provider Code
]);

$paymentData = [
   'from' => '979797',       // Receiver Party Code
   'reference' => '11114',      // Third Party Reference
   'transaction' => 'T12344CC', // Transaction Reference
   'amount' => '10'             // Amount
];

$result = $client->send($paymentData)

if ($result->success) {
   // Handle success scenario
} else {
   // Handle failure scenario
}
```

#### Transaction Reversal

[](#transaction-reversal)

```
use Paymentsds\MPesa\Client;

$client = new Client([
   'apiKey' => '',             // API Key
   'publicKey' => '',          // Public Key
   'serviceProviderCode' => '', // Service Provider Code
   'initiatorIdentifier' => '', // Initiator Identifier
   'securityIdentifier' => ''  // Security Credential
]);

$paymentData = [
   'reference' => '11114',      // Third Party Reference
   'transaction' => 'T12344CC', // Transaction Reference
   'amount' => '10'             // Amount
];

$result = $client->revert($paymentData);

if ($result->success) {
   // Handle success scenario
} else {
   // Handle failure scenario
}
```

#### Query the transaction status

[](#query-the-transaction-status)

```
use Paymentsds\MPesa\Client;

$client = new Client([
   'apiKey' => '',             // API Key
   'publicKey' => '',          // Public Key
   'serviceProviderCode' => '' // Service Provider Code
]);

$paymentData = [
   'subject' => '11114',      // Query Reference
   'transaction' => 'T12344CC', // Transaction Reference
];

$result = $client->query($paymentData);

if ($result->success) {
   // Handle success scenario
} else {
   // Handle failure scenario
}
```

Friends
-------

[](#friends)

- [M-Pesa SDK for Javascript](https://github.com/paymentsds/mpesa-js-sdk)
- [M-Pesa SDK for Python](https://github.com/paymentsds/mpesa-python-sdk)
- [M-Pesa SDK for Java](https://github.com/paymentsds/mpesa-java-sdk)
- [M-Pesa SDK for Ruby](https://github.com/paymentsds/mpesa-ruby-sdk)

Authors
-------------------------------------------

[](#authors-)

- [Anísio Mandlate](https://github.com/AnisioMandlate)
- [Edson Michaque](https://github.com/edsonmichaque)
- [Elton Laice](https://github.com/eltonlaice)
- [Nélio Macombo](https://github.com/neliomacombo)

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

[](#contributing)

Thank you for considering contributing to this package. If you wish to do it, email us at  and we will get back to you as soon as possible.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability, please email us at  and we will address the issue with the needed urgency.

License
-------

[](#license)

Copyright 2020 © The PaymentsDS Team

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.5% 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 ~247 days

Total

3

Last Release

1288d ago

Major Versions

0.1.0-alpha12 → 1.0.02022-06-30

PHP version history (2 changes)0.1.0-alpha12PHP &gt;= 7.2

1.0.0PHP &gt;=7.2

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/16c01129952361138fcb621af51ba76f087512dcbb8f12a37cc5151e33aa8569?d=identicon)[eltonlaice](/maintainers/eltonlaice)

---

Top Contributors

[![edsonmichaque](https://avatars.githubusercontent.com/u/6823987?v=4)](https://github.com/edsonmichaque "edsonmichaque (49 commits)")[![eltonlaice](https://avatars.githubusercontent.com/u/8969075?v=4)](https://github.com/eltonlaice "eltonlaice (9 commits)")[![karson](https://avatars.githubusercontent.com/u/755840?v=4)](https://github.com/karson "karson (9 commits)")[![Dnhatsave](https://avatars.githubusercontent.com/u/43370602?v=4)](https://github.com/Dnhatsave "Dnhatsave (3 commits)")[![alexcrisbrito](https://avatars.githubusercontent.com/u/75732812?v=4)](https://github.com/alexcrisbrito "alexcrisbrito (2 commits)")[![AnisioMandlate](https://avatars.githubusercontent.com/u/48864686?v=4)](https://github.com/AnisioMandlate "AnisioMandlate (2 commits)")[![joseseie](https://avatars.githubusercontent.com/u/18400142?v=4)](https://github.com/joseseie "joseseie (1 commits)")[![tantofaznem](https://avatars.githubusercontent.com/u/6969148?v=4)](https://github.com/tantofaznem "tantofaznem (1 commits)")

---

Tags

m-pesa

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[chargebee/chargebee-php

ChargeBee API client implementation for PHP

768.0M9](/packages/chargebee-chargebee-php)[imdhemy/google-play-billing

Google Play Billing

491.3M5](/packages/imdhemy-google-play-billing)[bitpay/sdk

Complete version of the PHP library for the new cryptographically secure BitPay API

42337.5k4](/packages/bitpay-sdk)[buckaroo/sdk

Buckaroo payment SDK

12189.1k9](/packages/buckaroo-sdk)[contica/facturador-electronico-cr

Un facturador de código libre para integrar facturación electrónica en Costa Rica a un proyecto PHP

2128.8k](/packages/contica-facturador-electronico-cr)[karson/mpesa-php-sdk

172.2k](/packages/karson-mpesa-php-sdk)

PHPackages © 2026

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