PHPackages                             codeonweekends/mpesa-php-sdk - 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. codeonweekends/mpesa-php-sdk

ActivePackage[Payment Processing](/categories/payments)

codeonweekends/mpesa-php-sdk
============================

(Unofficial) PHP SDK for the MPesa payment gateway by Vodacom Mozambique

v1.1.3(4y ago)92682[2 PRs](https://github.com/codeonweekends/mpesa-php-sdk/pulls)MITPHPPHP ^7.2 || ^8.0

Since Jan 6Pushed 3y ago3 watchersCompare

[ Source](https://github.com/codeonweekends/mpesa-php-sdk)[ Packagist](https://packagist.org/packages/codeonweekends/mpesa-php-sdk)[ RSS](/packages/codeonweekends-mpesa-php-sdk/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (4)Versions (6)Used By (0)

Install using Composer
======================

[](#install-using-composer)

`composer require codeonweekends/mpesa-php-sdk`

Usage
=====

[](#usage)

The easiest way to use the API is by calling `Codeonweekends\Mpesa\Mpesa` and accessing the available transaction methods.

- Create an instance of `Codeonweekends\Mpesa\Mpesa`
- Get the api context using the `getApiContext()` method
- Set the public key and the api key on the context using `setPublicKey(YOUR_PUBLIC_KEY)` and `setApiKey(YOUR_API_KEY)` respectively

**Example:**

```
$mpesa = new Codeonweekends\Mpesa\Mpesa();
$context = $mpesa->getApiContext();

$context->setPublicKey(YOUR_PUBLIC_KEY);
$context->setApiKey(YOUR_API_KEY);
```

Create a C2B Transaction
------------------------

[](#create-a-c2b-transaction)

```
$c2b = $mpesa->c2b($thirdPartyReference, $amount, $customerMSISDN, $serviceProviderCode, $transactionReference);
```

View a Transaction Status
-------------------------

[](#view-a-transaction-status)

```
$status = $mpesa->transactionStatus($queryReference, $serviceProviderCode, $securityCredential, $initiatorIdentifier);
```

Transaction Reversal
--------------------

[](#transaction-reversal)

```
$reversal = $mpesa->transactionReversal($amount, $serviceProviderCode, $transactionID, $securityCredential, $initiatorIdentifier);
```

Running Test Suite
==================

[](#running-test-suite)

2. Open the file `phpunit.xml` and fill the `` values with appropriate information
3. Run `vendor/bin/phpunit`

**e.g.**

```

```

Further Improvements
====================

[](#further-improvements)

- Documentation
- Laravel support

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity69

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

Total

3

Last Release

1769d ago

PHP version history (3 changes)1.1.0PHP &gt;=7.2

v1.1.2PHP ^7.2

v1.1.3PHP ^7.2 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![amandio](https://avatars.githubusercontent.com/u/4216265?v=4)](https://github.com/amandio "amandio (36 commits)")

---

Tags

mpesampesa-apimpesa-backendmpesa-phpmpesa-php-sdkmpesa-restmpesa-sdkvodacom

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codeonweekends-mpesa-php-sdk/health.svg)

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

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k96.9M674](/packages/laravel-socialite)[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4845.9k](/packages/sebdesign-laravel-viva-payments)[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)[karson/mpesa-php-sdk

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

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

245.2k](/packages/aedart-athenaeum)[henryejemuta/laravel-monnify

A laravel package to seamlessly integrate monnify api within your laravel application

132.1k](/packages/henryejemuta-laravel-monnify)

PHPackages © 2026

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