Code Monkey home page Code Monkey logo

laravel-mtn-momo's Introduction

Laravel MTM MOMO API Integration

Total Downloads Latest Stable Version License Code Quality Code Coverage Tests Documentation

Introduction

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
^6.0 2.0 composer require bmatovu/laravel-mtn-momo ^2.0
^7.0 3.0 composer require bmatovu/laravel-mtn-momo ^3.0
^8.0 ... ^10.0 master composer require bmatovu/laravel-mtn-momo

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

Prerequisites

You will need the following to get started with you integration...

  1. Create a developer account with MTN MOMO.
  2. 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.

Getting started (Sandbox)

Register your 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

Usage

use Bmatovu\MtnMomo\Products\Collection;

$collection = new Collection();

$momoTransactionId = $collection->requestToPay('transactionId', '46733123454', 100);

See test numbers

Exception handling

use Bmatovu\MtnMomo\Products\Collection;
use Bmatovu\MtnMomo\Exceptions\CollectionRequestException;

try {
    $collection = new Collection();
    
    $momoTransactionId = $collection->requestToPay('transactionId', '46733123453', 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

  1. Collect money

    $collection->requestToPay($transactionId, $partyId, $amount)
  2. Check transaction status

    $collection->getTransactionStatus($momoTransactionId)
  3. Check account balance

    $collection->getAccountBalance()
  4. Check account status

    $collection->isActive($partyId)
  5. Get OAuth token

    $collection->getToken()
  6. Get Account Holder Info

    $collection->getAccountHolderBasicInfo($partyId)

Disbursement

  1. Disburse money

    $disbursement->transfer($transactionId, $partyId, $amount)
  2. Check transaction status

    $disbursement->getTransactionStatus($momoTransactionId)
  3. Check account balance

    $disbursement->getAccountBalance()
  4. Check account status

    $disbursement->isActive($partyId)
  5. Get OAuth token

    $disbursement->getToken()
  6. Get Account Holder Info

    $disbursement->getAccountHolderBasicInfo($partyId)

Remittance

  1. Remit money

    $remittance->transfer($transactionId, $partyId, $amount)
  2. Check transaction status

    $remittance->getTransactionStatus($momoTransactionId)
  3. Check account balance

    $remittance->getAccountBalance()
  4. Check account status

    $remittance->isActive($partyId)
  5. Get OAuth token

    $remittance->getToken()
  6. Get Account Holder Info

    $remittance->getAccountHolderBasicInfo($partyId)

Go live

You will need to make some changes to your setup before going live. Read more.

Reporting bugs

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!

laravel-mtn-momo's People

Contributors

mtvbrianking avatar hamzamugabo avatar stevebaros avatar alhaji-aki avatar yondifon avatar muluhgodson avatar spekulatius avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.