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

ActiveLibrary[API Development](/categories/api)

sparkplug/momoapi-php
=====================

MTN momo bindings to PHP

2139418[12 issues](https://github.com/sparkplug/momoapi-php/issues)[1 PRs](https://github.com/sparkplug/momoapi-php/pulls)PHPCI failing

Since Feb 25Pushed 11mo ago9 watchersCompare

[ Source](https://github.com/sparkplug/momoapi-php)[ Packagist](https://packagist.org/packages/sparkplug/momoapi-php)[ RSS](/packages/sparkplug-momoapi-php/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (2)Used By (0)

MTN MoMo API PHP Client
=======================

[](#mtn-momo-api-php-client)

**🛑 This repository is no longer actively maintained.**

As of July 14, 2025, this project is no longer under active development. This means:

- No new features will be added.
- Bugs will not be fixed.
- Pull requests will not be reviewed or merged.
- Issues will not be addressed.

We appreciate your interest and contributions. **Thank you.**

---

**Power your apps with our MTN MoMo API**

 Join our active, engaged community:
 [Website](https://momodeveloper.mtn.com/)  |  [Spectrum](https://spectrum.chat/momo-api-developers/)

[![Build Status](https://camo.githubusercontent.com/5c1a3228bc495962f984e0e8ee5a06d201380da8fca51da046229fb8387c5f20/68747470733a2f2f7472617669732d63692e636f6d2f737061726b706c75672f6d6f6d6f6170692d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/sparkplug/momoapi-php)[![Latest Stable Version](https://camo.githubusercontent.com/ba1978e100274916450c08ddd843c8f68bae86d6ffa01357b9ea14aa5f2f062e/68747470733a2f2f706f7365722e707567782e6f72672f737061726b706c75672f6d6f6d6f6170692d7068702f762f737461626c652e737667)](https://packagist.org/packages/sparkplug/momoapi-php)[![Total Downloads](https://camo.githubusercontent.com/36e1a6e486405edbb958bbbd59f1e847a1b3fa7b88f35015a90a3f79deadd258/68747470733a2f2f706f7365722e707567782e6f72672f737061726b706c75672f6d6f6d6f6170692d7068702f646f776e6c6f6164732e737667)](https://packagist.org/packages/sparkplug/momoapi-php)[![License](https://camo.githubusercontent.com/e2ba468b6e4652920a5332340c7c46eaefc4e23158f4452f579e5ff9926c12f1/68747470733a2f2f706f7365722e707567782e6f72672f737061726b706c75672f6d6f6d6f6170692d7068702f6c6963656e73652e737667)](https://packagist.org/packages/sparkplug/momoapi-php)[![Coverage Status](https://camo.githubusercontent.com/5dff0705bfa9f08f1b0f6b40315dd8966c9835270038c003b39fb52a48ac5487/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f737061726b706c75672f6d6f6d6f6170692d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/sparkplug/momoapi-php?branch=master)[![Join the community on Spectrum](https://camo.githubusercontent.com/f5ded7dabee269d0b1964e3491de6817cdf63a5f9d11bb570ca2cafdc1c2c582/68747470733a2f2f77697468737065637472756d2e6769746875622e696f2f62616467652f62616467652e737667)](https://spectrum.chat/momo-api-developers/)

Installation
============

[](#installation)

You are required to have PHP 5.4.0 and later.

Composer
--------

[](#composer)

You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:

```
composer require sparkplug/momoapi-php
```

To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):

```
require_once('vendor/autoload.php');
```

Manual Installation
-------------------

[](#manual-installation)

If you do not wish to use Composer, you can download the [latest release](https://github.com/sparkplug/momoapi-php/releases). Then, to use the bindings, include the `init.php` file.

```
require_once('/path/to/momoapi-php/init.php');
```

Dependencies
------------

[](#dependencies)

The bindings require the following extensions in order to work properly:

- [`curl`](https://secure.php.net/manual/en/book.curl.php), although you can use your own non-cURL client if you prefer
- [`json`](https://secure.php.net/manual/en/book.json.php)
- [`mbstring`](https://secure.php.net/manual/en/book.mbstring.php) (Multibyte String)

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

Sandbox Environment
===================

[](#sandbox-environment)

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

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

Next, 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`.

```
## within the project, on the command line. In this example, our domain is akabbo.ug
$ php vendor/sparkplug/momoapi-php/lib/Provision.php
$ providerCallBackHost: https://akabbo.ug
$ Ocp-Apim-Subscription-Key: f83xx8d8xx6749f19a26e2265aeadbcdeg
```

The `providerCallBackHost` is your callback host and `Ocp-Apim-Subscription-Key` is your API 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:

```
Here is your User Id and API secret : {'apiKey': 'b0431db58a9b41faa8f5860230xxxxxx', 'UserId': '053c6dea-dd68-xxxx-xxxx-c830dac9f401'}
```

These are the credentials we shall use for the sandbox environment. In production, these credentials are provided for you on the MTN OVA management dashboard after KYC requirements are met.

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

[](#configuration)

Before we can fully utilize the library, we need to specify global configurations. The global configuration using the requestOpts builder. By default, these are picked from environment variables, but can be overidden using the MomoApi builder

- `BASE_URL`: An optional base url to the MTN Momo API. By default the staging base url will be used
- `ENVIRONMENT`: Optional enviroment, either "sandbox" or "production". Default is 'sandbox'
- `CURRENCY`: currency by default its EUR
- `CALLBACK_HOST`: The domain where you webhooks urls are hosted. This is mandatory.
- `COLLECTION_PRIMARY_KEY`: The collections API primary key,
- `COLLECTION_USER_ID`: The collection User Id
- `COLLECTION_API_SECRET`: The Collection API secret
- `REMITTANCE_USER_ID`: The Remittance User ID
- `REMITTANCE_API_SECRET`: The Remittance API Secret
- `REMITTANCE_PRIMARY_KEY`: The Remittance Subscription Key
- `DISBURSEMENT_USER_ID`: The Disbursement User ID
- `DISBURSEMENT_API_SECRET`: The Disbursement API Secret
- `DISBURSEMENT_PRIMARY_KEY`: The Disbursement Primary Key

Once you have specified the global variables, you can now provide the product-specific variables. Each MoMo API product requires its own authentication details i.e its own `Subscription Key`, `User ID` and `User Secret`, also sometimes refered to as the `API Secret`. As such, we have to configure subscription keys for each product you will be using.

You will only need to configure the variables for the product(s) you will be using.

you can also use the MomoApi to globally set the different variables.

```
MomoApi::setBaseUrl('base');

MomoApi::setTargetEnvironment("targetenv");

MomoApi::setCurrency("UGX");

MomoApi::setCollectionApiSecret("collection_api_secret");

MomoApi::setCollectionPrimaryKey("collection_primary_key");

MomoApi::setCollectionUserId("collection_user_id");

MomoApi::setRemittanceApiSecret("remittance_api_secret");

MomoApi::setRemittancePrimaryKey("remittance_primary_key");

MomoApi::setRemittanceUserId("remittance_user_id" );

MomoApi::setDisbursementApiSecret("disbursement_api_secret");

MomoApi::setDisbursementPrimaryKey("disbursement_primary_key");

MomoApi::setDisbursementUserId("disbursement_user_id");
```

Collections
-----------

[](#collections)

The collections client can be created with the following paramaters. Note that the `COLLECTION_USER_ID` and `COLLECTION_API_SECRET` for production are provided on the MTN OVA dashboard;

- `COLLECTION_PRIMARY_KEY`: Primary Key for the `Collection` product on the developer portal.
- `COLLECTION_USER_ID`: For sandbox, use the one generated with the `mtnmomo` command.
- `COLLECTION_API_SECRET`: For sandbox, use the one generated with the `mtnmomo` command.

You can create a collection client with the following:

```
$client = Collection();
```

### Methods

[](#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 using `getTransactionStatus`.
2. `getTransaction`: Retrieve transaction information using the `transactionId` returned by `requestToPay`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.
3. `getBalance`: Get the balance of the account.
4. `isPayerActive`: check if an account holder is registered and active in the system.

### Sample Code

[](#sample-code)

```
        $coll = new Collection($currency = "c..", $baseUrl = "url..", $targetEnvironment = "u...", $collectionApiSecret = "u...", $collectionPrimaryKey = "u...", $collectionUserId = "u..."]);

        $params = ['mobile' => "256782181656", 'payee_note' => "34", 'payer_message' => "12", 'external_id' => "ref", 'currency' => "EUR", 'amount' => "500"];

        $t = $coll->requestToPay($params);

        $transaction = $coll->getTransaction($t);
```

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

[](#disbursement)

The Disbursements client can be created with the following paramaters. Note that the `DISBURSEMENT_USER_ID` and `DISBURSEMENT_API_SECRET` for production are provided on the MTN OVA dashboard;

- `DISBURSEMENT_PRIMARY_KEY`: Primary Key for the `Disbursement` product on the developer portal.
- `DISBURSEMENT_USER_ID`: For sandbox, use the one generated with the `mtnmomo` command.
- `DISBURSEMENT_API_SECRET`: For sandbox, use the one generated with the `mtnmomo` command.

You can create a disbursements client with the following

```
        $disbursement = new Disbursement();

        $params = ['mobile' => "256782181656", 'payee_note' => "34", 'payer_message' => "12", 'external_id' => "ref", 'currency' => "EUR", 'amount' => "500"];

        $t = $disbursement->requestToPay($params);

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

### Methods

[](#methods-1)

1. `transfer`: Used to transfer an amount from the owner’s account to a payee account. Status of the transaction can be validated by using the `getTransactionStatus` method.
2. `getTransactionStatus`: Retrieve transaction information using the `transactionId` returned by `transfer`. You can invoke it at intervals until the transaction fails or succeeds.
3. `getBalance`: Get your account balance.
4. `isPayerActive`: This method is used to check if an account holder is registered and active in the system.

#### Sample Code

[](#sample-code-1)

```
```

Custom Request Timeouts
-----------------------

[](#custom-request-timeouts)

*NOTE:* We do not recommend decreasing the timeout for non-read-only calls , since even if you locally timeout, the request can still complete.

To modify request timeouts (connect or total, in seconds) you'll need to tell the API client to use a CurlClient other than its default. You'll set the timeouts in that CurlClient.

```
// set up your tweaked Curl client
$curl = new \MomoApi\HttpClient\CurlClient();
$curl->setTimeout(10); // default is \MomoApi\HttpClient\CurlClient::DEFAULT_TIMEOUT
$curl->setConnectTimeout(5); // default is \MomoApi\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT

echo $curl->getTimeout(); // 10
echo $curl->getConnectTimeout(); // 5

// tell MomoApi to use the tweaked client
\MomoApi\ApiRequest::setHttpClient($curl);

// use the Momo API client as you normally would
```

Custom cURL Options (e.g. proxies)
----------------------------------

[](#custom-curl-options-eg-proxies)

Need to set a proxy for your requests? Pass in the requisite `CURLOPT_*` array to the CurlClient constructor, using the same syntax as `curl_stopt_array()`. This will set the default cURL options for each HTTP request made by the SDK, though many more common options (e.g. timeouts; see above on how to set those) will be overridden by the client even if set here.

```
// set up your tweaked Curl client
$curl = new \MomoApi\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
// tell MomoApi to use the tweaked client
\MomoApi\ApiRequest::setHttpClient($curl);
```

Alternately, a callable can be passed to the CurlClient constructor that returns the above array based on request inputs. See `testDefaultOptions()` in `tests/CurlClientTest.php` for an example of this behavior. Note that the callable is called at the beginning of every API request, before the request is sent.

### Configuring a Logger

[](#configuring-a-logger)

The library does minimal logging, but it can be configured with a [`PSR-3` compatible logger](http://www.php-fig.org/psr/psr-3/) so that messages end up there instead of `error_log`:

```
\MomoApi\MomoApi::setLogger($logger);
```

### Configuring Automatic Retries

[](#configuring-automatic-retries)

The library can be configured to automatically retry requests that fail due to an intermittent network problem:

```
\MomoApi\MomoApi::setMaxNetworkRetries(2);
```

Development
-----------

[](#development)

Get [Composer](https://getcomposer.org/). For example, on Mac OS:

```
brew install composer
```

Install dependencies:

```
composer install
```

Install dependencies as mentioned above (which will resolve [PHPUnit](http://packagist.org/packages/phpunit/phpunit)), then you can run the test suite:

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

Or to run an individual test file:

```
./vendor/bin/phpunit tests/UtilTest.php
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/82f7094e3d468d411f82ec60753948b94f201393c2ab1d2db1b74a5d64dfb613?d=identicon)[sparkplugea](/maintainers/sparkplugea)

---

Top Contributors

[![mossplix](https://avatars.githubusercontent.com/u/128935?v=4)](https://github.com/mossplix "mossplix (25 commits)")[![bqevin](https://avatars.githubusercontent.com/u/12267112?v=4)](https://github.com/bqevin "bqevin (8 commits)")[![raybesiga](https://avatars.githubusercontent.com/u/405697?v=4)](https://github.com/raybesiga "raybesiga (6 commits)")[![mwakaambrose](https://avatars.githubusercontent.com/u/8328295?v=4)](https://github.com/mwakaambrose "mwakaambrose (1 commits)")

### Embed Badge

![Health badge](/badges/sparkplug-momoapi-php/health.svg)

```
[![Health](https://phpackages.com/badges/sparkplug-momoapi-php/health.svg)](https://phpackages.com/packages/sparkplug-momoapi-php)
```

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