PHPackages                             patricpoba/mtn-momo-api-php - 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. patricpoba/mtn-momo-api-php

ActiveLibrary[Payment Processing](/categories/payments)

patricpoba/mtn-momo-api-php
===========================

Php wrapper for MTN Momo API - https://momodeveloper.mtn.com

v0.2.3(2y ago)574.7k↑25%32[1 PRs](https://github.com/patricpoba/mtn-momo-api-php/pulls)MITPHPPHP ^7.0|^8.0CI failing

Since Feb 17Pushed 8mo ago4 watchersCompare

[ Source](https://github.com/patricpoba/mtn-momo-api-php)[ Packagist](https://packagist.org/packages/patricpoba/mtn-momo-api-php)[ Docs](https://github.com/patricpoba/mtn-momo-api-php)[ RSS](/packages/patricpoba-mtn-momo-api-php/feed)WikiDiscussions master Synced 1mo ago

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

MTN MoMo API
============

[](#mtn-momo-api)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a28e10f2736e05d319e89fa8f6f443f654ec39d83486bb2715a69fce8cf1e86d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706174726963706f62612f6d746e2d6d6f6d6f2d6170692d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/patricpoba/mtn-momo-api-php)[![GitHub license](https://camo.githubusercontent.com/59049f55ce9793dc20140f399afe72db164023b7815489c4320ae7433a34040b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706174726963706f62612f6d746e2d6d6f6d6f2d6170692d7068703f7374796c653d666c61742d737175617265)](https://github.com/patricpoba/mtn-momo-api-php/blob/master/LICENSE.md)[![Build Status](https://camo.githubusercontent.com/9a50844bc0b05dbc345865796ef4d3aaeeb2601ccb8bada6895cca26e1dd7856/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f706174726963706f62612f6d746e2d6d6f6d6f2d6170692d7068702f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/patricpoba/mtn-momo-api-php)[![Quality Score](https://camo.githubusercontent.com/75edb116a1677bb96c0a6e6be8d82f3db381293f054ddfe293c6e116cea43329/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f706174726963706f62612f6d746e2d6d6f6d6f2d6170692d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/patricpoba/mtn-momo-api-php)[![Total Downloads](https://camo.githubusercontent.com/a2925a365c6366e155f662cce48290edc6e2f4029add6c1ad9b89618b1edf757/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706174726963706f62612f6d746e2d6d6f6d6f2d6170692d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/patricpoba/mtn-momo-api-php)

This package helps you integrate the [MTN MOMO API](https://momodeveloper.mtn.com) into your Php or Laravel application. Its wrapper around the MTN Open API to provide you with a much simpler API to work with.

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

[](#installation)

You are required to have PHP 7.0 or later. You can install the package via composer:

```
composer require patricpoba/mtn-momo-api-php
```

Usage
=====

[](#usage)

In production, the needed credentials are provided for you on the MTN OVA management dashboard after KYC requirements are met. But in a testing environment, a sanbox user would have to be created by you using the API, which this package can do for you.

Creating a sandbox environment API user
---------------------------------------

[](#creating-a-sandbox-environment-api-user)

We need to get the `User ID` and `User Secret` and to do this we shall need to use the Primary Key for the Product to which we are subscribed, as well as specify a host. The library ships with a commandline application that helps to create sandbox credentials. It assumes you have created an account on `https://momodeveloper.mtn.com` and have your `Ocp-Apim-Subscription-Key` (primaryKey) located at `https://momodeveloper.mtn.com/developer`.

```
## On the command line, at the root of your project, run
$ php ./vendor/patricpoba/mtn-momo-api-php/src/SandboxUserProvision.php -k '9cc70894a5d24dba8a8a50fcecbc0568' -c 'https://yourdomain.com'
```

The option `c` is your callback host and the option `k` is the primary key or `Ocp-Apim-Subscription-Key` for the specific product to which you are subscribed. The `API Key` is unique to the product and you will need an `API Key` for each product you use. You should get a response similar to the following:

```
Your Sandbox credentials :
Ocp-Apim-Subscription-Key: f1d075127844476fa3c4636593e60cf8
UserId (X-Reference-Id)  : 89ce5960-3f68-4da4-bd69-0584073870b8
ApiKey (ApiSecret)       : 46b9302a8ae444c8a7a956bb4c7f2c05
Callback host            : https://yourdomain.com
```

Configuration
-------------

[](#configuration)

We have to setup up the package to utilise the our momodeveloper credentials by creating an instance of the `MtnConfig`and pass it to the constructor of the class of the product (collection, disbursement or remittance) we want to use as demonstrated below. The configuration can be overriden a product instance by calling the `->setConfig($config)` method and passing the new config instance.

```
use PatricPoba\MtnMomo\MtnConfig;

$config = new MtnConfig([
    // mandatory credentials
    'baseUrl'               => 'https://sandbox.momodeveloper.mtn.com',
    'currency'              => 'EUR',
    'targetEnvironment'     => 'sandbox',

    // product specific blocks
    "collectionApiSecret"   => '3463953c31064e6e8ae634cd94f13c8c',
    "collectionPrimaryKey"  => 'aadb6f286e95415db9024c7a4e2c6025',
    "collectionUserId"      => 'b4d4019f-8617-4843-a4b8-ed90941747a3',

    "disbursementApiSecret" => '3463953c31064e6e8ae634cd94f13c8c',
    "disbursementPrimaryKey"=> 'aadb6f286e95415db9024c7a4e2c6025',
    "disbursementUserId"    => 'b4d4019f-8617-4843-a4b8-ed90941747a3',

    "remittanceApiSecret"   => '3463953c31064e6e8ae634cd94f13c8c',
    "remittancePrimaryKey"  => 'aadb6f286e95415db9024c7a4e2c6025',
    "remittanceUserId"      => 'b4d4019f-8617-4843-a4b8-ed90941747a3'
]);
```

Collection
----------

[](#collection)

Collections is used for requesting a payment from a customer (Payer) and checking status of transactions. [Read more on Momo Collection](https://momodeveloper.mtn.com/docs/services/collection/operations/requesttopay-POST)

- `collectionPrimaryKey`: Primary Key for the `Collection` product on the developer portal.
- `collectionUserId` : For development environment, use the sandbox credentials else use the one on the `developer portal`.
- `collectionApiSecret` : For development environment, use the sandbox credentials else use the one on the `developer portal`.

```
use PatricPoba\MtnMomo\MtnConfig;

$config = new MtnConfig([
    // mandatory credentials
    'baseUrl'               => 'https://sandbox.momodeveloper.mtn.com',
    'currency'              => 'EUR',
    'targetEnvironment'     => 'sandbox',

    // collection credentials
    "collectionApiSecret"   => '3463953c31064e6e8ae634cd94f13c8c',
    "collectionPrimaryKey"  => 'aadb6f286e95415db9024c7a4e2c6025',
    "collectionUserId"      => 'b4d4019f-8617-4843-a4b8-ed90941747a3'
]);

$collection = new MtnCollection($config);

$params = [
    "mobileNumber"      => '233540000000',
    "amount"            => '100',
    "externalId"        => '774747234',
    "payerMessage"      => 'some note',
    "payeeNote"         => '1212'
];

$transactionId = $collection->requestToPay($params);

$transaction = $collection->getTransaction($transactionId);
```

### Collection Methods

[](#collection-methods)

1. `requestToPay`: This operation is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system. Status of the transaction can be validated by checking the `status` field on the result of `getTransaction()` method.

```
   $transactionId = $collection->requestToPay($params);
```

2. `getTransaction`: Retrieve transaction information using the `transactionId` returned by `requestToPay`. You can invoke it at intervals until the transaction fails or succeeds.

```
   $transaction = $collection->getTransaction($transactionId);
```

3. `getBalance`: Get the balance of the account.

```
   $transaction = $collection->getBalance();
```

4. `accountHolderActive`: check if an account holder is registered and active in the system.

```
   $transaction = $collection->accountHolderActive($mobileNumber);
```

Disbursement
------------

[](#disbursement)

Disbursement is used for transferring money from the provider account to a customer. [Read more on Momo Disbursement](https://momodeveloper.mtn.com/docs/services/disbursement/operations/token-POST)

- `disbursementPrimaryKey`: Primary Key for the `Disbursement` product on the developer portal.
- `disbursementUserId` : For development environment, use the sandbox credentials else use the one on the `developer portal`.
- `disbursementApiSecret` : For development environment, use the sandbox credentials else use the one on the `developer portal`.

```
use PatricPoba\MtnMomo\MtnConfig;
use PatricPoba\MtnMomo\MtnDisbursement;

$config = new MtnConfig([
    // mandatory credentials
    'baseUrl'               => 'https://sandbox.momodeveloper.mtn.com',
    'currency'              => 'EUR',
    'targetEnvironment'     => 'sandbox',

    // disbursement credentials
    "disbursementApiSecret"   => '3463953c31064e6e8ae634cd94f13c8c',
    "disbursementPrimaryKey"  => 'aadb6f286e95415db9024c7a4e2c6025',
    "disbursementUserId"      => 'b4d4019f-8617-4843-a4b8-ed90941747a3'
]);

/**
 * setup disbursement config
 */
$disbursement = new MtnDisbursement($config);

$params = [
    "mobileNumber"      => '233540000000',
    "amount"            => '100',
    "externalId"        => '774747234',
    "payerMessage"      => 'some note',
    "payeeNote"         => '1212'
];

/**
 * Transfer() is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system.
 */
$transactionId = $disbursement->transfer($params);

/**
 * Status of the transaction can be validated by checking the `status`
 * field on the result of `getTransaction()` method.
 */
$transaction = $disbursement->getTransaction($transactionId);
```

### Disbursement Methods

[](#disbursement-methods)

1. `transfer`: This operation is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system. Status of the transaction can be validated by checking the `status` field on the result of `getTransaction()` method.

```
   $transactionId = $disbursement->transfer($params);
```

2. `getTransaction`: Retrieve transaction information using the `transactionId` returned by `requestToPay`. You can invoke it at intervals until the transaction fails or succeeds.

```
   $transaction = $disbursement->getTransaction($transactionId);
```

3. `getBalance`: Get the balance of your disbursement account.

```
   $transaction = $disbursement->getBalance();
```

4. `accountHolderActive`: check if an account holder is registered and active in the system.

```
   $transaction = $disbursement->accountHolderActive($mobileNumber);
```

Remittance
----------

[](#remittance)

Transfer operation is used to transfer an amount from the own account to a payee account.

- `disbursementPrimaryKey`: Primary Key for the `Disbursement` product on the developer portal.
- `disbursementUserId` : For development environment, use the sandbox credentials else use the one on the `developer portal`.
- `disbursementApiSecret` : For development environment, use the sandbox credentials else use the one on the `developer portal`.

```
use PatricPoba\MtnMomo\MtnConfig;
use PatricPoba\MtnMomo\MtnRemittance;

$config = new MtnConfig([
    // mandatory credentials
    'baseUrl'               => 'https://sandbox.momodeveloper.mtn.com',
    'currency'              => 'EUR',
    'targetEnvironment'     => 'sandbox',

    // disbursement credentials
    "remittanceApiSecret"   => '3463953c31064e6e8ae634cd94f13c8c',
    "remittancePrimaryKey"  => 'aadb6f286e95415db9024c7a4e2c6025',
    "remittanceUserId"      => 'b4d4019f-8617-4843-a4b8-ed90941747a3'
]);

/**
 * setup remittance config
 */
$remittance = new MtnRemittance($config);

$params = [
    "mobileNumber"      => '233540000000',
    "amount"            => '100',
    "externalId"        => '774747234',
    "payerMessage"      => 'some note',
    "payeeNote"         => '1212'
];

/**
 * Transfer operation is used to transfer an amount from the own account to a payee account.
 * Status of the transaction can validated by using the GET /transfer/{referenceId}
 */
$transactionId = $remittance->transfer($params);

/**
 * This operation is used to get the status of a transfer. X-Reference-Id
 * that was passed in the post is used as reference to the request.
 */
$transaction = $remittance->getTransaction($transactionId);

/**
 * Get the balance of your disbursement account.
 */
$transaction = $disbursement->getBalance();

/**
 * Operation is used to check if an account holder is registered and active in the system.
 */
$transaction = $disbursement->accountHolderActive($mobileNumber);
```

### Api Responses

[](#api-responses)

All api calls return the PatricPoba\\MtnMomo\\Http\\ApiResponse object which is described below:

```
/**
* Data in api response can also be accessed directly from the object.
*/
$response->description // 'description' is in api response.

/**
* Get array format of api response
* @return array
*/
$response->toArray()

/**
* Get json format of api response
* @return string
*/
$response->toJson()

/**
* Get the status code of the response
* @return numeric
*/
$response->getStatusCode()

/**
* Get the headers the response
*/
$response->getHeaders()

/**
* Checks if api call was successful ie 200, 201 etc
* return bool
*/
$response->isSuccess()
```

### Testing

[](#testing)

```
./vendor/bin/phpunit
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Patric Poba](https://github.com/patricpoba)
- [All Contributors](../../contributors)
- [PHP Package Boilerplate](https://laravelpackageboilerplate.com).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance42

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Total

5

Last Release

1068d ago

PHP version history (2 changes)v0.1PHP ^7.0

v0.2.3PHP ^7.0|^8.0

### Community

Maintainers

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

---

Top Contributors

[![patricpoba](https://avatars.githubusercontent.com/u/4930107?v=4)](https://github.com/patricpoba "patricpoba (47 commits)")

---

Tags

packagepatricpobamtn-momo-api-php

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/patricpoba-mtn-momo-api-php/health.svg)

```
[![Health](https://phpackages.com/badges/patricpoba-mtn-momo-api-php/health.svg)](https://phpackages.com/packages/patricpoba-mtn-momo-api-php)
```

###  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)
