fannypack / momo
MTN MOMO api implementation
Installs: 639
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 5
Forks: 11
Open Issues: 0
Requires
- guzzlehttp/guzzle: ^6.3
- ramsey/uuid: ^3.8
This package is auto-updated.
Last update: 2024-12-10 00:44:15 UTC
README
Momo is a simple library in PHP for the MTN Mobile Money Open API.
Product support
- Collections
- Disbursements
- Remittances
Getting Started
- Signup For An Account
- Subscribe To Products
Signup For An Account
Follow this link to the developer portal and signup for an account.
Subscribe To Products
On the Products page on developer portal you should see items you can subscribe to:
- Collections
- Disbursements
- Remittances
Installation
The recommended way to install Momo is through composer.
Just create a composer.json file for your project and require it:
composer require fannypack/momo
Now you can add the autoloader, and you will have access to the library:
<?php require 'vendor/autoload.php';
Usage
Creating a product instance
<?php use FannyPack\Momo\Products\Collection; use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; $options = [ // 'callbackHost' => '', //(optional) default is http://localhost:8000 // 'callbackUrl' => '', //(optional) default is http://localhost:8000/callback // 'environment' => '', //(optional) default is sandbox // 'accountHolderIdType' => '', //(optional) default is msisdn 'subscriptionKey' => '', //Product Subscription key 'xReferenceId' => '', //Api user reference id (in UUID format) 'apiKey' => '', // Api user key (Supply this after generating it at 'Create API Key') //'preApproval' => '', //(optional) default is false //'accessToken' => '' //Required for transactions ]; // Using collection $collection = Collection::create($options); // Using disbursement $disbursement = Disbursement::create($options); // Using remittance $remittance = Remittance::create($options);
Sandbox User Provisioning
Create API User
<?php use FannyPack\Momo\Products\Collection; use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using collection $product = Collection::create($options); // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $product->createApiUser(); //{"statusCode": 201}
GET API User Details
<?php use FannyPack\Momo\Products\Collection; use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using collection $product = Collection::create($options); // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $apiUser = $product->getApiUser(); $apiUser->getProviderCallbackHost(); //http://localhost:8000 $apiUser->getTargetEnvironment(); //sandbox
Create API Key
<?php use FannyPack\Momo\Products\Collection; use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using collection $product = Collection::create($options); // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $apiKey = $product->createApiKey(); $apiKey->getApiKey(); //apiKey
Oauth 2.0
Get token
<?php use FannyPack\Momo\Products\Collection; use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using collection $product = Collection::create($options); // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $token = $product->getToken(); $token->getAccessToken(); //accessToken $token->getTokenType(); //tokenType $token->getExpiresIn(); //expiry in seconds
Transactions
Get account balance
<?php use FannyPack\Momo\Products\Collection; use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using collection $product = Collection::create($options); // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $balance = $product->getAccountBalance(); $balance->getAvailableBalance(); //accountBalance $balance->getCurrency(); //currency
Get account holder status
<?php use FannyPack\Momo\Products\Collection; use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using collection $product = Collection::create($options); // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $product->getAccountHolderInfo($accountHolderId); //{"statusCode": 201}
Collections
Request to pay
<?php use FannyPack\Momo\Products\Collection; // Using collection $product = Collection::create($options); $product->requestToPay($externalId, $partyId, $amount, $currency, $payerMessage = '', $payeeNote = ''); // {"statusCode": 200, "financialTransactionId": "8f3077a6-ce43-4584-a425-589c50cfcbe4"}
Request to pay status
<?php use FannyPack\Momo\Products\Collection; // Using collection $product = Collection::create($options); $transactionStatus = $product->getRequestToPayStatus($financialTransactionId); $transactionStatus->getAmount(); //amount $transactionStatus->getCurrency(); //currency $transactionStatus->getExternalId(); //externalId $transactionStatus->getPayer(); //payer object $transactionStatus->getStatus(); //status
Disbursements and Remittances
Transfer
<?php use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $product->transfer($externalId, $partyId, $amount, $currency, $payerMessage = '', $payeeNote = '');// {"statusCode": 200, "financialTransactionId": "8f3077a6-ce43-4584-a425-589c50cfcbe4"}
Transfer status
<?php use FannyPack\Momo\Products\Disbursement; use FannyPack\Momo\Products\Remittance; // Using disbursement $product = Disbursement::create($options); // Using remittance $product = Remittance::create($options); $transactionStatus = $product->transferStatus($financialTransactionId); $transactionStatus->getAmount(); //amount $transactionStatus->getCurrency(); //currency $transactionStatus->getExternalId(); //externalId $transactionStatus->getPayer(); //payer object $transactionStatus->getStatus(); //status
Bugs
For any bugs found, please email me at andrewmvp007@gmail.com or register an issue at issues