Download the PHP package linlak/momoapi without Composer

On this page you can find all versions of the php package linlak/momoapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package momoapi

Momo PHP Api Version 1.0

This is a php library that has been designed to help developers to easily integrate the momo api into their system.

Solution

After finding out that most developers were having trouble integrating the momoapi into there system. We came up with this simple php library to make the integration easy and fast.

Prerequisites

Before you start using this library we assume that you have good knowledge of php, composer and namespace autoloading. And have installed all the required software to enable run the examples provided here.

You must also have an account on the Momo Developer Portal https://momodeveloper.mtn.com/

Software

The following software is require for better results:-

Features

Installation

Use composer to manage your dependencies and download Momo Api Library:

composer require linlak/momoapi

Examples

Creating ApiUser https://momodeveloper.mtn.com/docs/services/sandbox-provisioning-api

The following code snippet will help to create an apiUser this supports all products these include:

Note:

Whenever we show text in curry brackets ("{text}") please replace that text with the required data without brackets.

Let's start by bootstrapping our momo library in the code snippet bellow.

Note: The apiUser is generated automatically

momo_bootstrap.php

<?php
    set_time_limit(500);
    require '{path-to-vendor}/vendor/autoload.php';

    use Momo\MomoApp\Bootstraper;
    $momoBootstrap=new Bootstraper('{dbHost}','{dbName}','{dbUser}','{dbPass}','{environment}');

We are going to perform the following tasks here:

momo_collections.php

<?php
    require_once "momo_bootstrap.php}";

    $callBackUrl="{callbackurl}";
    $collection=$momoBootstrap->initCollection("{collection primaryKey}",{collection secondaryKey},$callbackUrl);

momo_remittances.php

<?php
    require_once "momo_bootstrap.php}";
    $callBackUrl="{callbackurl}";
    $remittances=$momoBootstrap->initRemittances("{remittances primaryKey}",{remittances secondaryKey},$callBackUrl);

momo_disbursements.php

<?php
    require_once "momo_bootstrap.php}";
    $callBackUrl="{callbackurl}";
    $disbursements=$momoBootstrap->initDisbursements("{disbursements primaryKey}",{disbursements secondaryKey},$callBackUrl);

collection_balance.php

<?php
    require_once "momo_collections.php";

    //instanceof BalanceResponse
    $result=$collection->requestBalance();

    //let's print the result

    if($result->isFound()){
        $availableBalance=$result->getAvailableBalance();
        $currency=$result->getCurrency();
        echo('availableBalance: '.$availableBalance.'\n\r');
        echo('currency: '.$currency.'\n\r');
    }

remittances_balance.php

<?php
    require_once "momo_remittances.php";

    //instanceof BalanceResponse
    $result=$remittances->requestBalance();

    //let's print the result

    if($result->isFound()){
        $availableBalance=$result->getAvailableBalance();
        $currency=$result->getCurrency();
        echo('availableBalance: '.$availableBalance.'\n\r');
        echo('currency: '.$currency.'\n\r');
    }

disbursements_balance.php

<?php
    require_once "momo_disbursements.php";

    //instanceof BalanceResponse
    $result=$disbursements->requestBalance();

    //let's print the result

    if($result->isFound()){
        $availableBalance=$result->getAvailableBalance();
        $currency=$result->getCurrency();
        echo('availableBalance: '.$availableBalance.'\n\r');
        echo('currency: '.$currency.'\n\r');
    }

Let's verify account holder

collections_accountholder.php

<?php
    require_once "momo_collections.php";

    $acoutHolderId="{acoutHolderId}";
    $acoutHolderIdType="{acoutHolderIdType}";

    //array
    $result=$collection->acountHolder($accountHolderIdType,$accountHolderId);

    //let's print the result

    echo "<pre>";
    print_r($result);

remittances_accountholder.php

<?php
    require_once "momo_remittances.php";

    $acoutHolderId="{acoutHolderId}";
    $acoutHolderIdType="{acoutHolderIdType}";

    //array
    $result=$remittances->acountHolder($accountHolderIdType,$accountHolderId);

    //let's print the result

    echo "<pre>";
    print_r($result);

disbursements_accountholder.php

<?php
    require_once "momo_disbursements.php";

    $acoutHolderId="{acoutHolderId}";
    $acoutHolderIdType="{acoutHolderIdType}";

    //array
    $result=$disbursements->acountHolder($accountHolderIdType,$accountHolderId);

    //let's print the result

    echo "<pre>";
    print_r($result);

We are now going to perform a requestToPay and requestToPayStatus.

Note: These apply to Collection product only.

request_topay.php

<?php
    require_once "momo_collections.php";
    use Momo\MomoApp\Models\RequestToPay;

    //requestToPay object

    $requestToPay=new RequestToPay("{externalId}","{amount}","{partyId}","{partyIdType}","{payeeNote}","{payerMessage}");

    //to set the currency

    $requestToPay->setCurrency("{curency}");// read docs for more info on supported currencies.

    $callbackUrl="{url to your webhook}";

    //array
    $result=$collection->requestToPay($requestToPay,$callbackUrl);
    //let's print the result

    echo "<pre>";
    print_r($result);

request_status.php

<?php
    require_once "momo_collections.php";

    $referenceId="{referenceId  returned in request_topay.php}";

    //array
    $result=$collection->requestToPayStatus($referenceId);
    //let's print the result

    echo "<pre>";
    print_r($result);

We are now going to perform a transfer and tranferStatus.

Note: These apply to Remittances and Disbursements products only.

transfer.php

<?php
    require_once "momo_remittances.php";
    use Momo\MomoApp\Models\RequestToPay;

    //for Disbursements replace $remittances with $disbursements

    //requestToPay object

    $requestToPay=new RequestToPay("{externalId}","{amount}","{partyId}","{partyIdType}","{payeeNote}","{payerMessage}");

    //to set the currency

    $requestToPay->setCurrency("{curency}");// read docs for more info on supported currencies.

    $callbackUrl="{url to your webhook}";

    //array

    $result=$remittances->transfer($requestToPay,$callbackUrl);

    //let's print the result

    echo "<pre>";
    print_r($result);

transfer_status.php

<?php
    require_once "momo_remittances.php";

    //for Disbursements replace remittances with disbursements

    $referenceId="{referenceId  returned in transer.php}";

    //array

    $result=$remittances->transferStatus($referenceId);

    //let's print the result

    echo "<pre>";
    print_r($result);

sample result for the following files

The image above show the result for the files listed above. You are required to compare the results with your payments table to confirm if the request was created,successful,timed out or rejected.

For request_topay.php status is PENDING for the rest it can be either PENDING, SUCCESSFUL, FAILED. If status is FAILED you should check the reason to see if it was rejected or timed out.

Note: If the result is not as in the image shown above then request was not successful, or resource was not found in these cases the result is false therefore it is better you wrap it in an IF statement.****

As you all know that Programming is an Art. You can now manipulate the result to meet your desired outcome.

If you are successful up to this step, Congratulations you have managed to integrate the momo api into your system. Though there is still more yet to come keep checking in for updates and I strongly recommend you to use Composer for your php dependency management,it will help you to easily update libraries in a single command.

composer update

With the above command you will have all your dependencies updated.

Up Next

Setting Webhooks these will help you to write code for the callbackUrl. For more info contact me at the email provided bellow.

Check in for updates.

Acknowledgements

Every good work is always appreciated and for this reason I should acknowledge appreciations from some of the users who found this tool valuable.

1. APPSCORE INSTITUTE OF DIGITAL TECHNOLOGY - I thank APPSCORE for the Certificate

Nice coding

Regards

Linus Nowomukama

mailto:[email protected]

tel:+256783198167

tel:+256751921465


All versions of momoapi with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
guzzlehttp/guzzle Version ^6.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package linlak/momoapi contains the following files

Loading the files please wait ....