Giter Site home page Giter Site logo

momopay's Introduction

MOMOPAY

Packagist License Packagist Version (including pre-releases) Packagist Downloads

Description

A packages for mobile money payment in Cameroun.
Only Mtn Cameroon is supported

๐Ÿ›‘ please wait for the first stable release before use this package

Installation

composer require nkaurelien/momopay

(optional) Add the service provider in config\app.php

    providers' => [
        #...
        \Nkaurelien\Momopay\Providers\MomopayServiceProvider::class,
    ]

(optional) Add the service facade in config\app.php

    aliases' => [
        #...
        'MomoPay' => \Nkaurelien\Momopay\Facades\MomoPay::class
    ]

Configuration

Add config to config/services.php


    'mtn' => [
        'currency' => env('MTN_MOMO_CURRENCY', 'XAF'),
        'go_live' => env('MTN_MOMO_GO_LIVE',false),
        'api_key' => env('MTN_MOMO_USER_API_KEY'),
        'reference_id' => env('MTN_MOMO_ID'),
        'subscription_key' => env('MTN_MOMO_KEY'),
        'payment_callback_route' => env('MTN_MOMO_CALLBACK_URL','payment.momo.callback'),
        'payment_callback_host' => env('MTN_MOMO_CALLBACK_HOST'),
        'notification_email' => env('MTN_MOMO_NOTIFICATION_EMAIL'),
    ],

Configuration description

  • reference_id : is the user id
  • subscription_key : is the Ocp-Apim-Subscription-Key
  • target_environment : can be sanbox or mtncameroon (when you go live)

Don't forget to cache the configurations again with the command php artisan config:cache

Add routes

Route::any('/payment/momo/callback', 'PaymentMomoController@callback')->name('payment.momo.callback');
Route::get('/payment/momo/transaction/{id}', 'PaymentMomoController@getPayment')->name('payment.momo.gettransaction');

Use in controller

First inject the repository class

    private $paymentMomoRepository;
    public function __construct(PaymentMomoRepository $paymentMomoRepository){ #...   

Then consume repository instance to implement your payment logic

    $momoRequestToPayDto = new \Nkaurelien\Momopay\Fluent\MomoRequestToPayDto;
    $momoRequestToPayDto->amount = 100;
    $momoRequestToPayDto->payeeNote = '';
    $momoRequestToPayDto->payerMessage = '';
    $momoRequestToPayDto->externalId = 'my_product_id';
    $momoRequestToPayDto->payer->telephone = '2376XXXXXXXX';
    
    # optional
    $momoRequestToPayDto->currency = 'XAF'; // Use EUR when you are in sandbox mode

    $refId = \Ramsey\Uuid\Uuid::uuid4()->toString();

    $requestToPayResult = $this->paymentMomoRepository->requestToPay($momoRequestToPayDto, $refId);

If your prefer the facade instead of injection

    #...
    $requestToPayResult = \Nkaurelien\Momopay\Facades\MomoPay::requestToPay($momoRequestToPayDto, $refId);

Capture events

You can listen to :

  • Nkaurelien\Momopay\Events\PaymentAccepted is fired after the success of request to pay

Todo

  • Create payment exceptions class
  • Create payment events
  • Email notification on payment success
  • Add orange money payment method

Useful links

momopay's People

Contributors

nkaurelien avatar shlife avatar simo97 avatar

Stargazers

Roman avatar

Watchers

James Cloos 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.