PHPackages                             abdulmueid/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. [API Development](/categories/api)
4. /
5. abdulmueid/mpesa

ActiveLibrary[API Development](/categories/api)

abdulmueid/mpesa
================

PHP SDK for M-Pesa Mozambique API

v2.0.0(6y ago)471.6k29[4 issues](https://github.com/abdulmueid/mpesa-php-api/issues)[3 PRs](https://github.com/abdulmueid/mpesa-php-api/pulls)1MITPHPPHP ^7.2

Since Dec 29Pushed 2y ago9 watchersCompare

[ Source](https://github.com/abdulmueid/mpesa-php-api)[ Packagist](https://packagist.org/packages/abdulmueid/mpesa)[ RSS](/packages/abdulmueid-mpesa/feed)WikiDiscussions master Synced today

READMEChangelog (3)DependenciesVersions (4)Used By (1)

Welcome to M-Pesa PHP API
=========================

[](#welcome-to-m-pesa-php-api)

This project aims to provide an easy-to-use and up-to-date PHP wrapper for the M-Pesa Mozambique API.

Target version of M-Pesa API: **v1x**

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

[](#installation)

Install using composer:

```
composer require abdulmueid/mpesa

```

Usage
-----

[](#usage)

1. Load the configuration from file.

    ```
    $config = \abdulmueid\mpesa\Config::loadFromFile('/path/to/config.php');
    ```

    See sample configuration file in examples folder.
2. Create a Transaction using the configuration.

    ```
    $transaction = new \abdulmueid\mpesa\Transaction($config);
    ```
3. Execute API operations and pass appropriate parameters.

    1. Initiate a C2B payment collection.

        ```
        $c2b = $transaction->c2b(
            float $amount,
            string $msisdn,
            string $reference,
            string $third_party_reference
        );
        ```
    2. Initiate a B2C payment.

        ```
        $b2c = $transaction->b2c(
            float $amount,
            string $msisdn,
            string $reference,
            string $third_party_reference
        );
        ```
    3. Initiate a B2B payment.

        ```
        $b2b = $transaction->b2b(
             float $amount,
             string $receiver_party_code,
             string $reference,
             string $third_party_reference
        );
        ```
    4. Initiate a reversal.

        ```
        $reversal = $transaction->reversal(
            float $amount,
            string $transaction_id,
            string $third_party_reference
        );
        ```
    5. Query a transaction.

        ```
        $query = $transaction->query(
            string $query_reference,
            string $third_party_reference
        );
        ```
4. Check Response

    All transactions return the `TransactionResponse` object. The object has the following public methods:

    1. `getCode()` - Returns the response code i.e. `INS-0`
    2. `getDescription()` - Returns the description.
    3. `getTransactionID()` - Returns the transaction ID.
    4. `getConversationID()` - Returns the conversation ID.
    5. `getTransactionStatus()` - Returns the transaction status. Only populated when calling the `query()` transaction.
    6. `getResponse()` - Returns the full response JSON object as received from M-Pesa servers. Good for debugging any issues or undocumented behaviors of the M-Pesa API.

In a typical scenario, code to check for successful transactions should be as follows:

```
$c2b = $transaction->c2b(...);

if($c2b->getCode() === 'INS-0') {
    // Transaction Successful, Do something here
}
```

Testing
-------

[](#testing)

This repo provides Unit Tests to validate the objects and their interaction with M-Pesa.

To run tests,

1. Open the `phpunit.xml` file and add the require credentials/parameters as supplied by M-Pesa.
2. Run `phpunit`
3. Check the handset for USSD prompts to approve test transactions.

All tests use 1MT as the test amount.

License
-------

[](#license)

This library is release under the MIT License. See LICENSE file for details.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.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 ~252 days

Total

3

Last Release

2235d ago

Major Versions

1.0.0 → v2.0.0-beta12020-02-15

PHP version history (2 changes)1.0.0PHP ^7.0

v2.0.0-beta1PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/06fba16ee1d3c6e1dd35b224e6852906d1290300c26bfce65caef1818fa310c8?d=identicon)[abdulmueid](/maintainers/abdulmueid)

---

Top Contributors

[![abdulmueid](https://avatars.githubusercontent.com/u/705308?v=4)](https://github.com/abdulmueid "abdulmueid (19 commits)")[![kishannareshpal](https://avatars.githubusercontent.com/u/25407841?v=4)](https://github.com/kishannareshpal "kishannareshpal (2 commits)")

---

Tags

apilibrarympesaphpphp-libraryphp7

### Embed Badge

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

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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