PHPackages                             wanzoou/momoapicollection - 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. wanzoou/momoapicollection

ActiveLibrary[API Development](/categories/api)

wanzoou/momoapicollection
=========================

This repository provides a PHP class, MomoAPI, to facilitate integration with the MTN Mobile Money (MoMo) API for collection services. This class allows you to create API users, generate API keys, obtain access tokens, and make payment requests to the MTN MoMo platform.

v0.0.1(1y ago)015↓100%MITPHPPHP &gt;=7.0

Since Jun 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/leskaiser/MTN_MoMo_API_COLLECTION_INTEGRATION_PHP)[ Packagist](https://packagist.org/packages/wanzoou/momoapicollection)[ RSS](/packages/wanzoou-momoapicollection/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

MTN MoMo API Collection Integration PHP
=======================================

[](#mtn-momo-api-collection-integration-php)

Introduction
------------

[](#introduction)

This repository provides a PHP class, `MomoAPI`, to facilitate integration with the MTN Mobile Money (MoMo) API for collection services. This class allows you to create API users, generate API keys, obtain access tokens, and make payment requests to the MTN MoMo platform.

Features
--------

[](#features)

- **Create API User:** Automatically create an API user for MTN MoMo integration.
- **Generate API Key:** Securely generate an API key for the created API user.
- **Obtain Access Token:** Generate an access token for authorization.
- **Request to Pay:** Initiate payment requests to the MoMo API.
- **Check Transaction Status:** Retrieve the status of a payment request.

Requirements
------------

[](#requirements)

- `PHP 7.0` or higher
- `cURL` extension for PHP

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

[](#installation)

You can install the library via Composer. Run the following command:

```
composer require wanzoou/momoapicollection
```

Include the `MomoAPI` class in your project:

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

use Wanzoou\Momoapicollection\MomoAPI;
```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

Instantiate the MomoAPI class:

```
$momo = new MomoAPI();
```

### Configuration

[](#configuration)

Set the required parameters:

```
$momo->setMomoPayHost('sandbox.momodeveloper.mtn.com'); // Set MoMo API host
$momo->setPrimaryKey('your_primary_key'); // Set your primary key
$momo->setProviderCallbackHost('your_callback_host'); // Set your provider callback host
$momo->setTargetEnvironment('sandbox'); // Set the target environment (sandbox or live)
```

### Request to Pay

[](#request-to-pay)

Initiate a payment request:

```
$phone = '237679465319'; // Payer's phone number
$amount = 100; // Amount to be paid
$currency = 'EUR'; // Currency

$responseCode = $momo->requestToPay($phone, $amount, $currency);

if ($responseCode == 202) {
    echo "Payment request initiated successfully.";
} else {
    echo "Failed to initiate payment request.";
}
```

### Check Transaction Status

[](#check-transaction-status)

Retrieve the status of a payment request:

```
$status = $momo->requestToPayTransactionStatus();
echo "Transaction Status: " . json_encode($status);
```

Methods
-------

[](#methods)

### `setMomoPayHost($momo_pay_host)`

[](#setmomopayhostmomo_pay_host)

Set the MoMo API host.

### `setProviderCallbackHost($providerCallbackHost)`

[](#setprovidercallbackhostprovidercallbackhost)

Set the provider callback host.

### `setPrimaryKey($primary_key)`

[](#setprimarykeyprimary_key)

Set the primary key.

### `setTargetEnvironment($targetEnvironment)`

[](#settargetenvironmenttargetenvironment)

Set the target environment (sandbox or live).

### `requestToPay($phone, $amount, $currency)`

[](#requesttopayphone-amount-currency)

Initiate a payment request.

### `requestToPayTransactionStatus()`

[](#requesttopaytransactionstatus)

Retrieve the status of a payment request.

Example
-------

[](#example)

Here is an example of using the MomoAPI class in a PHP script:

```
