Python Package For MTN Zambia Momo API. This package can also be used by MTN momo in other countries.

Overview

MTN MoMo API Lite Python Client

Power your apps with Lite-Python MTN MoMo API

Usage

Installation

Add the latest version of the library to your project:

 $ git clone https://github.com/Mathewsmusukuma/lite-python-mtnmomo-api.git

This library supports Python 2.7+ or Python 3.4+

Sandbox Environment

Creating a sandbox environment API user

Next, we need to get the User ID and User Secret and to do this we shall need to use the Primary Key for the Product to which we are subscribed, as well as specify a host. The library ships with a commandline application that helps to create sandbox credentials. It assumes you have created an account on https://momodeveloper.mtn.com and have your Ocp-Apim-Subscription-Key.

## within the project, on the command line. In this example, our domain is akabbo.ug
$ mtnmomo
$ providerCallBackHost: https://akabbo.ug
$ Ocp-Apim-Subscription-Key: f83xx8d8xx6749f19a26e2265aeadbcdeg

The providerCallBackHost is your callback host and Ocp-Apim-Subscription-Key is your API key for the specific product to which you are subscribed. The API Key is unique to the product and you will need an API Key for each product you use. You should get a response similar to the following:

Here is your User Id and API secret : {'apiKey': 'b0431db58a9b41faa8f5860230xxxxxx', 'UserId': '053c6dea-dd68-xxxx-xxxx-c830dac9f401'}

These are the credentials we shall use for the sandbox environment. In production, these credentials are provided for you on the MTN OVA management dashboard after KYC requirements are met.

Configuration

Before we can fully utilize the library, we need to specify global configurations. The global configuration must contain the following:

  • BASE_URL: An optional base url to the MTN Momo API. By default the staging base url will be used
  • ENVIRONMENT: Optional environment, either "sandbox" or "production". Default is 'sandbox'
  • CALLBACK_HOST: The domain where you webhooks urls are hosted. This is mandatory.

Once you have specified the global variables, you can now provide the product-specific variables. Each MoMo API product requires its own authentication details i.e its own Subscription Key, User ID and User Secret, also sometimes refered to as the API Secret. As such, we have to configure subscription keys for each product you will be using.

The full list of configuration options can be seen in the example below:

config = {
   "ENVIRONMENT": os.environ.get("ENVIRONMENT"), 
   "BASE_URL": os.environ.get("BASE_URL"), 
   "CALLBACK_HOST": os.environ.get("CALLBACK_HOST"), # Mandatory.
   "COLLECTION_PRIMARY_KEY": os.environ.get("COLLECTION_PRIMARY_KEY"), 
   "COLLECTION_USER_ID": os.environ.get("COLLECTION_USER_ID"),
   "COLLECTION_API_SECRET": os.environ.get("COLLECTION_API_SECRET"),
   "REMITTANCE_USER_ID": os.environ.get("REMITTANCE_USER_ID"), 
   "REMITTANCE_API_SECRET": os.environ.get("REMITTANCE_API_SECRET"),
   "REMITTANCE_PRIMARY_KEY": os.envieon.get("REMITTANCE_PRIMARY_KEY"),
   "DISBURSEMENT_USER_ID": os.environ.get("DISBURSEMENT_USER_ID"), 
   "DISBURSEMENT_API_SECRET": os.environ.get("DISBURSEMENTS_API_SECRET"),
   "DISBURSEMENT_PRIMARY_KEY": os.environ.get("DISBURSEMENT_PRIMARY_KEY"), 
}

You will only need to configure the variables for the product(s) you will be using.

Collections

The collections client can be created with the following paramaters. Note that the COLLECTION_USER_ID and COLLECTION_API_SECRET for production are provided on the MTN OVA dashboard;

  • COLLECTION_PRIMARY_KEY: Primary Key for the Collection product on the developer portal.
  • COLLECTION_USER_ID: For sandbox, use the one generated with the mtnmomo command.
  • COLLECTION_API_SECRET: For sandbox, use the one generated with the mtnmomo command.

You can create a collection client with the following:

import os
from mtnmomo.collection import Collection

client = Collection({
        "COLLECTION_USER_ID": os.environ.get("COLLECTION_USER_ID"),
        "COLLECTION_API_SECRET": os.environ.get("COLLECTION_API_SECRET"),
        "COLLECTION_PRIMARY_KEY": os.environ.get("COLLECTION_PRIMARY_KEY"),
    })

Methods

  1. requestToPay: This operation is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system. Status of the transaction can be validated by using getTransactionStatus.

  2. getTransactionStatus: Retrieve transaction information using the transactionId returned by requestToPay. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.

  3. getBalance: Get the balance of the account.

  4. isPayerActive: check if an account holder is registered and active in the system.

Sample Code

import os
from mtnmomo.collection import Collection

client = Collection({
    "COLLECTION_USER_ID": os.environ.get("COLLECTION_USER_ID"),
    "COLLECTION_API_SECRET": os.environ.get("COLLECTION_API_SECRET"),
    "COLLECTION_PRIMARY_KEY": os.environ.get("COLLECTION_PRIMARY_KEY"),
})

client.requestToPay(
    mobile="0966456787", amount="600", external_id="123456789", payee_note="dd", payer_message="dd", currency="EUR")

Disbursement

The Disbursements client can be created with the following paramaters. Note that the DISBURSEMENT_USER_ID and DISBURSEMENT_API_SECRET for production are provided on the MTN OVA dashboard;

  • DISBURSEMENT_PRIMARY_KEY: Primary Key for the Disbursement product on the developer portal.
  • DISBURSEMENT_USER_ID: For sandbox, use the one generated with the mtnmomo command.
  • DISBURSEMENT_API_SECRET: For sandbox, use the one generated with the mtnmomo command.

You can create a disbursements client with the following

import os
from mtnmomo.disbursement import Disbursement

client = Disbursement({
    "DISBURSEMENT_USER_ID": os.environ.get("DISBURSEMENT_USER_ID"),
    "DISBURSEMENT_API_SECRET": os.environ.get("DISBURSEMENT_API_SECRET"),
    "DISBURSEMENT_PRIMARY_KEY": os.environ.get("DISBURSEMENT_PRIMARY_KEY"),
})

Methods

  1. transfer: Used to transfer an amount from the owner’s account to a payee account. Status of the transaction can be validated by using the getTransactionStatus method.

  2. getTransactionStatus: Retrieve transaction information using the transactionId returned by transfer. You can invoke it at intervals until the transaction fails or succeeds.

  3. getBalance: Get your account balance.

  4. isPayerActive: This method is used to check if an account holder is registered and active in the system.

Sample Code

import os
from mtnmomo.disbursement import Disbursement

client = Disbursement({
    "DISBURSEMENT_USER_ID": os.environ.get("DISBURSEMENT_USER_ID"),
    "DISBURSEMENT_API_SECRET": os.environ.get("DISBURSEMENT_API_SECRET"),
    "DISBURSEMENT_PRIMARY_KEY": os.environ.get("DISBURSEMENT_PRIMARY_KEY"),
})

client.transfer(amount="600", mobile="0966456787", external_id="123456789", payee_note="dd",      payer_message="dd", currency="EUR")

Credit

This repo was forked Sparkplug and modified to work well for MTN Zambia and MTN momo in other countries.

Thank you.

Owner
Mathews Musukuma
Python | JavaScript Developer
Mathews Musukuma
DSAIL repos - DSAIL Repository Template

DSAIL Repository Template DSAIL @ KAIST . ├── configs ('--F', help='for configur

yunhak 2 Feb 14, 2022
A play store search telegram bot

Play-Store-Bot A play store search telegram bot Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.c

Fayas Noushad 17 Oct 28, 2022
A Twitter Bot that retweets and likes tweets with the hashtag #girlscriptwoc and #girlscript, and also follows the user.

GirlScript Winter of Contributing Twitter Bot A Twitter Bot that retweets and likes tweets with the hashtag #girlscriptwoc and #girlscript, and also f

Pranay Gupta 9 Dec 15, 2022
Trabalho N1 para a materia Tecnicas de Progamação da Anhembi Morumbi

Projeto da Anhembi Morumbi - Tecnicas de Programação. RPG de Console (CMD) Trabalho proposto pelo professor André Santana, na materia Tecnicas de Prog

Leonardo Silva M de Barros 3 Sep 12, 2021
❤️A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules

Natsuki Based on Python Telegram Bot Contributors Video Tutorial: Complete guide on deploying @TheNatsukiBot's clone on Heroku. ☆ Video by Sadew Jayas

Pawan Theekshana 8 Oct 06, 2022
🧑‍💼 Python wrapper for the Seek API

seek-com-au-api 🧑‍💼 Python wrapper for the seek.com.au API (unofficial) Installation Using Python = 3.6: pip install -e git+https://github.com/tomq

Tom Quirk 1 Oct 24, 2021
CloudFormation Drift Remediation - Use Cloud Control API to remediate drift that was detected on a CloudFormation stack

CloudFormation Drift Remediation - Use Cloud Control API to remediate drift that was detected on a CloudFormation stack

Cloudar 36 Dec 11, 2022
⚡ Yuriko Robot ⚡ - A Powerful, Smart And Simple Group Manager Written with AioGram , Pyrogram and Telethon

⚡ Yuriko Robot ⚡ - A Powerful, Smart And Simple Group Manager Written with AioGram , Pyrogram and Telethon

Øғғɪᴄɪᴀʟ Ⱡᴏɢ [₳ғᴋ] 1 Apr 01, 2022
Script to post multiple status(posts) on twitter

Script to post multiple status on twitter (i.e. TWITTER STORM) This program can post upto maximum limit of twitter(around 300 tweets) within seconds.

Sandeep Kumar 4 Sep 09, 2021
100d002 - Simple program to calculate the tip amount and split the bill between all guests

Day 2 - Tip Calculator Simple program to calculate the tip amount and split the

Andre Schickhoff 1 Jan 24, 2022
Asynchronous RDP/VNC client for Python (GUI)

🚩 This is the public repository of aardwolf, for latest version and updates please consider supporting us through https://porchetta.industries/ AARDW

29 Dec 15, 2022
Baota-docker - Deploying baota panel via docker

baota-docker Deploying baota panel via docker. 通过docker一键部署宝塔面板。 一、前言 好像很多人对这个感兴

Mr. Cat 15 Dec 12, 2022
Telegram forwarder

Telegram Forwarder Quick Start This application using docker, docker-compose to run. So I suppose that you can install these two things. Prepare essen

10 Dec 20, 2022
Automatically copy the Discord Status of a Friend you share a server with (conditions have to be satisfied to work)

CopyDiscordStatusOfUser-SelfBot Basic Function Automatically copy the Discord Status of a friend User whom you share a server with (These conditions h

Certified Baller 5 Aug 05, 2022
Braintree Python library

Braintree Python library The Braintree Python library provides integration access to the Braintree Gateway. TLS 1.2 required The Payment Card Industry

Braintree 230 Dec 18, 2022
Discord bot to display private leaderboards for Advent of Code.

Advent Of Code Discord Bot Discord bot for displaying Advent of Code private leardboards, as well as custom leaderboards where participants can set th

The Future Gadgets Lab 6 Nov 29, 2022
ESOLinuxAddonManager - Very simple addon manager for Elder Scrolls Online running on Linux.

ESOLinuxAddonManager Very simple addon manager for Elder Scrolls Online running on Linux. Well, more a downloader for now. Currently it's quite ugly b

Akseli 25 Aug 28, 2022
Yes, it's true :heartbeat: This repository has 337 stars.

Yes, it's true! Inspired by a similar repository from @RealPeha, but implemented using a webhook on AWS Lambda and API Gateway, so it's serverless! If

512 Jan 01, 2023
📷 Instagram Bot - Tool for automated Instagram interactions

InstaPy Tooling that automates your social media interactions to “farm” Likes, Comments, and Followers on Instagram Implemented in Python using the Se

Tim Großmann 13.5k Dec 01, 2021