This package helps you integrate the MTN MOMO API into your Laravel application. It provides a wrapper around the core MTN MOMO API services, leaving you to worry about other parts of your application.
To get started, install the package via the Composer package manager:
Laravel | Package | Installation |
---|---|---|
5.3 | 1.3 | composer require bmatovu/laravel-mtn-momo 1.3.* |
5.4 | 1.4 | composer require bmatovu/laravel-mtn-momo 1.4.* |
5.5 | 1.5 | composer require bmatovu/laravel-mtn-momo 1.5.* |
5.6 | 1.6 | composer require bmatovu/laravel-mtn-momo 1.6.* |
5.7 | 1.7 | composer require bmatovu/laravel-mtn-momo 1.7.* |
5.8 | 1.8 | composer require bmatovu/laravel-mtn-momo 1.8.* |
6.0 | 2.0 | composer require bmatovu/laravel-mtn-momo ^2.0 |
7.0 | master | composer require bmatovu/laravel-mtn-momo |
The service provider will be auto-discovered for Laravel 5.5 and above. You may manually register the service provider in your configuration config/app.php
file:
'providers' => array(
// ...
Bmatovu\MtnMomo\MtnMomoServiceProvider::class,
),
Configuration customization
If you wish to customize the default configurations, you may export the default configuration using
php artisan vendor:publish --provider="Bmatovu\MtnMomo\MtnMomoServiceProvider" --tag="config"
Database Migration
The package service provider registers it's own database migrations with the framework, so you should migrate your database after installation. The migration will create a tokens tables your application needs to store access tokens from MTN MOMO API.
php artisan migrate
You will need the following to get started with you integration...
- Create a developer account with MTN MOMO.
- Subscribe to a product/service that you wish to consume.
If you already subscribed to a product, the subscription key can be found in your profile.
Register you client details.
php artisan mtn-momo:init
Next you need to register your client app ID.
php artisan mtn-momo:register-id
You may want to verify your client ID at this stage
php artisan mtn-momo:validate-id
Then request for a client secret (key).
php artisan mtn-momo:request-secret
use Bmatovu\MtnMomo\Products\Collection;
$collection = new Collection();
$momoTransactionId = $collection->requestToPay('transactionId', '07XXXXXXXX', 100);
See test numbers
Exception handling
use Bmatovu\MtnMomo\Products\Collection;
use Bmatovu\MtnMomo\Exceptions\CollectionRequestException;
try {
$collection = new Collection();
$momoTransactionId = $collection->requestToPay('transactionId', '07XXXXXXXX', 100);
} catch(CollectionRequestException $e) {
do {
printf("\n\r%s:%d %s (%d) [%s]\n\r",
$e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode(), get_class($e));
} while($e = $e->getPrevious());
}
Collection
-
$collection->requestToPay($transactionId, $partyId, $amount)
-
$collection->getTransactionStatus($momoTransactionId)
-
$collection->getAccountBalance()
-
$collection->isActive($partyId)
-
$collection->getToken()
Disbursement
-
$disbursement->transfer($transactionId, $partyId, $amount)
-
$disbursement->getTransactionStatus($momoTransactionId)
-
$disbursement->getAccountBalance()
-
$disbursement->isActive($partyId)
-
$disbursement->getToken()
Remittance
-
$remittance->transfer($transactionId, $partyId, $amount)
-
$remittance->getTransactionStatus($momoTransactionId)
-
$remittance->getAccountBalance()
-
$remittance->isActive($partyId)
-
$remittance->getToken()
You will need to make some changes to your setup before going live. Read more.
If you've stumbled across a bug, please help us by leaving as much information about the bug as possible, e.g.
- Steps to reproduce
- Expected result
- Actual result
This will help us to fix the bug as quickly as possible, and if you wish to fix it yourself feel free to fork the package and submit a pull request!