foris-master / mtn-mobile-money-sdk
This is a php sdk for MTN operator mobile money api.
Installs: 2 183
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0|^7.4 | ^8.0.2
- ext-json: *
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^9
This package is not auto-updated.
Last update: 2024-12-13 22:06:20 UTC
README
php sdk for MTN MNO Mobile Money API
Note: mtn-mobile-money-sdk
.
This is a php sdk for mtn operator mobile money api.
Install
Via Composer
$ composer require foris-master/mtn-mobile-money-sdk
Global Config
-
MOMO_CURRENCY
Setup the currencyvalue
: EUR -
MOMO_SDK_ENV
Configures the value of the SDK environmentvalue
: sandbox or prod -
MOMO_ENV
variable to specify the application environmentvalue
: mtncameroon -
MOMO_CALLBACK_HOST
Sets the callback host for MTN API notificationsvalue
:https://example.com -
MOMO_CALLBACK_URL
URL of the callback for MTN API notificationsvalue
: https://myawesome.callback.com -
enviroment variable ( .env file if using dotenv)
Quick Usage
use Foris\MoMoSdk\Disbursement; use Foris\MoMoSdk\Collection; putenv('MOMO_CALLBACK_URL=https://myawesome.callback.com'); putenv('MOMO_CALLBACK_HOST=azz.com'); putenv('MOMO_ENV=mtncameroon'); putenv('MOMO_SDK_ENV=prod'); putenv('MOMO_CURRENCY=XAF'); Exemple Disbursement $disbursement = new Disbursement(); $disbursement->getAccessToken(); $disbursement->transfer(100, '0123456789'); $transferData = $disbursement->transfer(100, '0123456789'); $transactionData = $disbursement->getTransaction('transaction_id'); $balance = $disbursement->getBalance(); $accountValidation = $disbursement->isAccountValid('0123456789'); Exemple Collection $collection = new Collection(); $collection->getAccessToken(); $collection->requestToPay(100, '0123456789'); $collection-> getTransaction($id); $collection->getBalance(); $collection->isAccountValid("0123456789")
Config Disbursement
Disbursement is used for transferring money from the provider account to a customer Read more about Momo Disbursement.
MOMO_DISBURSEMENT_PRIMARY_KEY
Primary Key for the Disbursement product on the developer portalvalue
: your primary key hereMOMO_DISBURSEMENT_API_USER
User for the Disbursement APIvalue
: Your appuserMOMO_DISBURSEMENT_APP_KEY
application key for the Disbursement productvalue
: your app key
Disbursement Usage
- Get token
getAccessToken()
This method allows you to obtain an access token to perform disbursement operations.
use Foris\MoMoSdk\Disbursement; $disbursement = new Disbursement(); $accessToken = $disbursement->getAccessToken();
- transfer
transfer($amount, $tel, $options = array())
This method allows you to perform a funds transfer.
use Foris\MoMoSdk\Disbursement; $disbursement = new Disbursement(); $transferData = $disbursement->transfer(100, '0123456789');
- getTransaction
getTransaction('transaction_id')
This method allows you to retrieve the details of a disbursement transaction.
use Foris\MoMoSdk\Disbursement; $disbursement = new Disbursement(); $transactionData = $disbursement->getTransaction('transaction_id');
- getBalance
getBalance()
This method allows you to get the balance of the disbursement account.
use Foris\MoMoSdk\Disbursement; $disbursement = new Disbursement(); $balance = $disbursement->getBalance();
- isAccountValid
isAccountValid('0123456789')
This method allows you to check if a phone number is associated with a valid account.
use Foris\MoMoSdk\Disbursement; $disbursement = new Disbursement(); $accountValidation = $disbursement->isAccountValid('0123456789');
Config Collection
Collections is used for requesting a payment from a customer and checking status of transactions Read more about Momo Collection.
MOMO_COLLECTION_PRIMARY_KEY
Primary Key for the Collection product on the developer portalvalue
: your primary key hereMOMO_COLLECTION_API_USER
User for the Collection APIvalue
: Your appuserMOMO_COLLECTION_APP_KEY
application key for the Collection productvalue
: your app key
Collection Usage
Collections is used for requesting a payment from a customer and checking status of transactions.
- Get token
getAccessToken()
This method allows you to obtain an access token to perform collection operations.
use Foris\MoMoSdk\Collection; $collection = new Collection(); $accessToken = $collection->getAccessToken();
- requestToPay
requestToPay(100, '0123456789')
This method Initiates a payment request for a specific amount to the given phone number
use Foris\MoMoSdk\CollectionCollection; $collection = new CollectionCollection(); $requesPay = $collection->requestToPay(100, '0123456789');
- getTransaction
getTransaction($id)
This method allows you to retrieve the details of a transaction.
use Foris\MoMoSdk\CollectionCollection; $collection = new CollectionCollection(); $showTransaction = $collection->getTransaction($id);
- getBalance
getBalance()
Retrieves the balance of the collection account
use Foris\MoMoSdk\CollectionCollection; $collection = new CollectionCollection(); $balance = $collection->getBalance();
- isAccountValid
isAccountValid()
Checks if the given phone number is associated with a valid collection account
use Foris\MoMoSdk\Collection; $collection = new Collection(); $accountValidation = $collection->isAccountValid('0123456789');
Note
The status could take one of the following values: INITIATED; PENDING; EXPIRED; SUCCESS; FAILED
- INITIATED waiting for user entry
- PENDING user has clicked on “Confirmer”, transaction is in progress on Mtn side
- EXPIRED user has clicked on “Confirmer” too late (after token’s validity)
- SUCCESS payment is done
- FAILED payment has failed
Production
For production your need to set your target country code in COUNTRY enviroment variable ( .env file if using dotenv)
example: COUNTRY = mtncameroon
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.