Integrating MTN Cameroon Mobile money to PHP Application

Published 3 weeks ago by Malico
Share

So I recently published this plugin to ease MTN Cameroon Mobile Money payment in your PHP/Laravel application.

But through out this blog post, I'll focus on how to integrate it to your your vanilla PHP Application. Let's dive right in.

Installation

To Install the application, you will need to pull it in from composer with the following command.

composer require malico/momo
* Works only for Version 2+

With that, you'll need to create an account as a developer at developer.mtn.cm

Landing Page MTN Developer Page

Landing Page MTN Developer Page

Usage

Next. Within your PHP Code, you'll need to run an instance of the Momo Class. Something like this.

<?php

require 'composer/autoload.php';

use Malico\Momo\Momo;

$momo = new Momo('676956703', 100);

// The first parameter is the number with the country code [string|int] 
// the second parametr is the amount [int]

/**
 * Your can also do this.
 * 
 * $momo = (new Momo())
 *         ->amount(100)
 *         ->email('yourEmail@domain.com')
 *         ->tel(67777777);
 */

$momo->email('[email protected]');

$transaction = $momo->pay();

if($transaction->status){
    // Payment was successful
    // do something, save to Database or anyting
} else {
    // Failed Transaction
    // do something Display error message 
    // echo $transaction->desc;
}
* Make sure you include the email method

If you're working working on a laravel project, I've a way better blog post that will guide you. Click Here