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

ActiveLibrary[API Development](/categories/api)

nelson-flores/mpesa
===================

PHP SDK for M-Pesa Mozambique API

v1.0.0(1y ago)061↓50%MITPHPPHP ^7.2 || ^8.0

Since May 6Pushed 1y agoCompare

[ Source](https://github.com/nelson-flores/mpesa-php-api)[ Packagist](https://packagist.org/packages/nelson-flores/mpesa)[ RSS](/packages/nelson-flores-mpesa/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

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 nelson-flores/mpesa

```

Usage
-----

[](#usage)

1. Load the configuration from file.

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

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

    ```
    $transaction = new \Flores\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

30

—

LowBetter than 64% of packages

Maintenance49

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.6% 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

Unknown

Total

1

Last Release

369d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a92c90aeaf8cf54c36e5c7fdf5c329a5f7be5a9fbd8d995fb8a50f2be939c4f4?d=identicon)[nelsonflores\_mz](/maintainers/nelsonflores_mz)

---

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)")[![nelson-flores](https://avatars.githubusercontent.com/u/34948807?v=4)](https://github.com/nelson-flores "nelson-flores (2 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M479](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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