Logo Lanfrica

sikaili99/mtnmomoapi

Domain:

digital infrastructure

Record type:

software
Creator:
sik
Host:
Python Package For MTN Zambia Momo API. This package can also be used by MTN momo in other countries. # MTN MoMo API Python Client Power your apps with Python MTN MoMo API ## Installation Add the latest version of the library to your project: ```bash pip install mtnmomoapi ``` This library supports Python 2.7+ or Python 3.4+ ## Configuration Before using the API, set up your environment variables: ```bash # Base Configuration export MTN_ENVIRONMENT="sandbox" # or "mtnzambia" for production in Zambia export BASE_URL="proxy.momoapi.mtn.com" # Production URL export CALLBACK_HOST="your-domain.com" export CURRENCY="ZMW" # "EUR" for sandbox, "ZMW" for Zambia production # Collection API Keys export COLLECTION_PRIMARY_KEY="your-primary-key" export COLLECTION_USER_ID="your-user-id" export COLLECTION_API_SECRET="your-api-secret" # Disbursement API Keys export DISBURSEMENT_PRIMARY_KEY="your-primary-key" export DISBURSEMENT_USER_ID="your-user-id" export DISBURSEMENT_API_SECRET="your-api-secret" ``` ## Basic Usage Examples ### 1. Simple Collection Request ```python from mtnmomoapi.collection import Collection # Initialize the collection client collection = Collection() # Request payment try: response = collection.requestToPay( amount="100", phone_number="260966456787", external_id="order-123", payee_note="Payment for Order #123", payer_message="Please pay for your order" ) print(f"Transaction Reference: {response['transaction_ref']}") except Exception as e: print(f"Error: {str(e)}") ``` ### 2. Simple Disbursement ```python from mtnmomoapi.disbursement import Disbursement # Initialize the disbursement client disbursement = Disbursement() # Transfer money try: response = disbursement.transfer( amount="50", phone_number="260966456787", external_id="payout-123", payee_note="Refund for Order #123", payer_message="Your refund has been processed" ) print(f"Transaction Reference: {response['transaction_ref']}") except Exception as e: print(f"Error: {str(e)}") ``` ## Real-World Integration Examples ### 1. E-commerce Payment Processing ```python fr …