PHPackages                             linlak/laravel-momo-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. linlak/laravel-momo-sdk

ActiveLibrary[API Development](/categories/api)

linlak/laravel-momo-sdk
=======================

This is a simple php library that has been designed to help laravel developers to easily integrate the mtn momo api into their laravel projects with great ease.

v1.0.1(5y ago)4541[1 issues](https://github.com/linlak/laravel-momo-sdk/issues)MITPHPPHP &gt;=7.1.3

Since Jun 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/linlak/laravel-momo-sdk)[ Packagist](https://packagist.org/packages/linlak/laravel-momo-sdk)[ Docs](https://github.com/linlak/laravel-momo-sdk)[ RSS](/packages/linlak-laravel-momo-sdk/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel MTN MOMO SDK
====================

[](#laravel-mtn-momo-sdk)

This laravel library has been designed to to enable **Laravel Developers** to easily integrate the MTN open Api into their systems.

Prerequisites
-------------

[](#prerequisites)

Before you continue, we assume you have the following in place.

- XAMPP or LAMPP installation with latest php version i.e PHP&gt;=7.1
- Composer package to install the required php packages.
- We also recommend installation of Redis or Memchached drivers to store cache and running queues
- You must also have an account on the MTN Developer portal and Subscribe to the api products.
- We also assume you already have a running laravel app or project.

Installation
------------

[](#installation)

The installation of this **laravel-momo-sdk** is straight forward. Simply run the command bellow in terminal or cmd.

```
composer require linlak/laravel-momo-sdk

```

Configuration
-------------

[](#configuration)

For laravel versions that support auto discover, you can skip this step while for versions prior to 5.5, add the following code in your **config/app.php** in the **proveders** array

```
'providers' => [
	/*
	*......add this code at the end of the providers array
	*/
	LaMomo\Providers\MomoProvider::class,
],

```

Still in the same file locate that **aliases** array

```
'aliases'=>[
	//appended at the end of aliases array
	'Remittances' => LaMomo\Facades\Remittances::class,
    'RequestToPay' => LaMomo\Facades\RequestToPay::class,
    'Disbursements' => LaMomo\Facades\Disbursements::class,
],

```

Now we have set-up the require files registered our provider.

This step should be performed by all users. In your terminal or cmd run the following artisan command

```
php artisan vendor:publish --provider=LaMomo\\Providers\\MomoProvider

```

The command above will publish the **momosdk.php** in the config directory.

Environment variables (.env)
----------------------------

[](#environment-variables-env)

In the **.env** file add the follow code for each api product

```
MOMO_BASE=https://sandbox.momodeveloper.mtn.com/
MOMO_API_VERSION=v1_0
MOMO_ENVIRONMENT=sandbox
DISABLE_TAGS=false

MOMO_HOST=example.com

```

**Collection product**

```
COLLECTIONS_PRIMARY=your collections primary key
COLLECTIONS_SECONDARY=your collections secondary key
COLLECTIONS_API_USER=uuid for apiuser
COLLECTIONS_API_KEY=api key here
COLLECTIONS_CALLBACK_URL=your collections callback url "optional"

```

**Disbursements product**

```
REMITTANCES_PRIMARY=
REMITTANCES_SECONDARY=
REMITTANCES_API_USER=
REMITTANCES_API_KEY=
REMITTANCES_CALLBACK_URL=

```

**Remittances product**

```
DISBURSEMENTS_PRIMARY=
DISBURSEMENTS_SECONDARY=
DISBURSEMENTS_API_USER=
DISBURSEMENTS_API_KEY=
DISBURSEMENTS_CALLBACK_URL=

```

If all of the code snippets above are bundled up our **.env** file must have the following code appended at the end.

```
MOMO_BASE=https://sandbox.momodeveloper.mtn.com/
MOMO_API_VERSION=v1_0
MOMO_ENVIRONMENT=sandbox
DISABLE_TAGS=false
MOMO_HOST=example.com
COLLECTIONS_PRIMARY=
COLLECTIONS_SECONDARY=
COLLECTIONS_API_USER=
COLLECTIONS_API_KEY=
COLLECTIONS_CALLBACK_URL=
REMITTANCES_PRIMARY=
REMITTANCES_SECONDARY=
REMITTANCES_API_USER=
REMITTANCES_API_KEY=
REMITTANCES_CALLBACK_URL=
DISBURSEMENTS_PRIMARY=
DISBURSEMENTS_SECONDARY=
DISBURSEMENTS_API_USER=
DISBURSEMENTS_API_KEY=
DISBURSEMENTS_CALLBACK_URL=

```

Definitions
-----------

[](#definitions)

**MOMO\_BASE:** This is the base\_uri for the wallet system. We have designed this library to be flexible with api changes. After finding differences between sandbox and live endpoints, this environment variable will help you to set right endpoint e.g for collections request to pay, the link is

> [https://sandbox.momodeveloper.mtn.com/collection/v1\_0/requesttopay](https://sandbox.momodeveloper.mtn.com/collection/v1_0/requesttopay)

In the link above you find that we are sending our request to the **** endpoint.

**MOMO\_API\_VERSION:** This is self explanatory. It the version of the api endpoint. By default its value is **v1\_0**.

**MOMO\_ENVIRONMENT:** This is either sandbox or live

**DISABLE\_TAGS:** This library is cache based. Laravel has made caching as simple as possible. Caching drivers like Redis and Memcached support component tagging but for drivers such as file and database do not support tagging. If you are using file or database as your default cache driver, set the environment variable to **true** .

```
DISABLE_TAGS=true

```

**MOMO\_HOST:** This is the callback host as stated in the documentation.

**COLLECTIONS\_\_PRIMARY:** This primary\_key for the collections product, can be found on your profile on the developers portal. Other products are prefixed with their respective product names

i.e

REMITTANCES\_PRIMARY

DISBURSEMENTS\_PRIMARY

**COLLECTIONS\_SECONDARY:** This secondary\_key for the collections product, can be found on your profile on the developers portal. Other products are prefixed with their respective product names

i.e

REMITTANCES\_SECONDARY

DISBURSEMENTS\_SECONDARY

**COLLECTIONS\_ API\_USER :** This is the apiUser for collections product.

**COLLECTIONS\_API\_KEY:** This the apiKey for the collections product.

**COLLECTIONS\_CALLBACK\_URL:** This is default callback url for the collections product. This is optional.

Function Definitions
--------------------

[](#function-definitions)

**Collections**

- createApiUser() //sandbox only
- getApiUser() //sandbox only
- getApikey() //sandbox only
- acountHolder($accountHolderIdType, $accountHolderId)
- requestToPay(DataModel $dataModel, $callback\_url)
- requestToPayStatus($referenceId)

**Remittances**

- createApiUser() //sandbox only
- getApiUser() //sandbox only
- getApikey() //sandbox only
- acountHolder($accountHolderIdType, $accountHolderId)
- transferFunds(DataModel $dataModel, $callback\_url)
- transferStatus($referenceId)

**Disbursements**

- createApiUser() //sandbox only
- getApiUser() //sandbox only
- getApikey() //sandbox only
- acountHolder($accountHolderIdType, $accountHolderId)
- transferFunds(DataModel $dataModel, $callback\_url)
- transferStatus($referenceId)

Examples
--------

[](#examples)

We are going to consider an e-commerse store selling different products.

The product has the following attributes

- pdt\_name
- price
- pdt\_no

The Order Model

Let us first create our controllers and models

These first steps are for sandbox users.

After every step remember to clear the configuration cache so that changes can take effect. Run

```
php artisan conf:cache

```

**Creating apiUser (Collections)**

```
