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.

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/wanzoou/momoapicollection

v0.0.1 2024-06-19 10:03 UTC

This package is auto-updated.

Last update: 2025-12-29 04:01:58 UTC


README

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

  • 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

  • PHP 7.0 or higher
  • cURL extension for PHP

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

Initialization

Instantiate the MomoAPI class:

$momo = new MomoAPI();

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

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

Retrieve the status of a payment request:

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

Methods

setMomoPayHost($momo_pay_host)

Set the MoMo API host.

setProviderCallbackHost($providerCallbackHost)

Set the provider callback host.

setPrimaryKey($primary_key)

Set the primary key.

setTargetEnvironment($targetEnvironment)

Set the target environment (sandbox or live).

requestToPay($phone, $amount, $currency)

Initiate a payment request.

requestToPayTransactionStatus()

Retrieve the status of a payment request.

Example

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

<?php
require_once 'vendor/autoload.php';

use Wanzoou\Momoapicollection\MomoAPI;

$momo = new MomoAPI();
$momo->setMomoPayHost('sandbox.momodeveloper.mtn.com');
$momo->setPrimaryKey('your_primary_key');
$momo->setProviderCallbackHost('your_callback_host');
$momo->setTargetEnvironment('sandbox');

$phone = '237679465319';
$amount = 100;
$currency = 'EUR';

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

if ($responseCode == 202) {
    echo "Payment request initiated successfully.\n";
    $status = $momo->requestToPayTransactionStatus();
    echo "Transaction Status: " . json_encode($status);
} else {
    echo "Failed to initiate payment request.\n";
}
?>

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

Contact

For any inquiries, please contact wanzoou@gmail.com.