A Python wrapper for the MoMo Open API
Project description
mobilemoney.py
A modern, easy to use, feature-rich, and async ready API wrapper for MobileMoney written in Python. Use method and function simplified for the MOMO OPEN API
Key Features
- Modern Pythonic API using
asyncandawait. - Optimised in both speed and memory.
Installing
Python 3.8 or higher is required
To install the library, you can just run the following command:
.. code:: sh
# Linux/macOS
python3 -m pip install -U mobilemoney.py
# Windows
py -3 -m pip install -U mobilemoney.py
To install from github repository, do the following:
.. code:: sh
$ git clone https://github.com/rewriteapi/mobilemoney.py
$ cd mobilemoney.py
$ python3 -m pip install -U .
Quick Example
.. code:: py
import mobilemoney
import asyncio
#NOTICE : the library is working in both side (Production and Sandbox),
#for Production environement don't use the is_sandbox() method and
#make sure to replace credential correctly
async def main():
subsciption_key = 'COLLECTION_OR_DISBURSEMENT_CREDENTIAL_MAKE_SURE_TO_REPLACE_IT_CORRECTLY'
user = mobilemoney.Client()
#switchh to sandbox env
user.is_sandbox()
#Creating user and getting Key in sandbox env using Collection credential
uuid = user.get_reference_id()
print(uuid)
api_user = await user.create_api_user(uuid, subsciption_key)
print('-------- creating api user----------')
print(api_user)
resp, api_user_details = await user.get_api_user(uuid, subsciption_key)
print('-----------getting api user------------')
print(api_user_details)
resp, api_key = await user.create_api_key(uuid, subsciption_key)
print('---------api key-----------')
print(type(api_key))
print(api_key)
basic_auth = user.basic_token(uuid, api_key["apiKey"])
print('------------Basic auth---------')
print(basic_auth)
#Initialising Collection product
collect = user.collection(subsciption_key)
#creating access token
resp, access_token = await collect.create_access_token(basic_auth)
print('---------creating access token-----------')
print(access_token)
#convert it to bearer token
bearer_token = user.bearer_token(access_token['access_token'])
#request to pay
body = {
"amount": "5",
"currency": "EUR",
"externalId": "45464546454",
"payer": {
"partyIdType": "MSISDN",
"partyId": "87937389"
},
"payerMessage": "BUY THING",
"payeeNote": "THANKS"
}
resp, req_to_pay = await collect.request_to_pay(bearer_token, user.get_reference_id(), api_user_details['targetEnvironment'], body)
print('-----------------Request to pay-----------------')
print(resp)
print(req_to_pay)
if resp:
print('Successfull')
else:
print('Not worked')
#withdraw
resp, with_req = await collect.withdraw(bearer_token, user.get_reference_id(), api_user_details['targetEnvironment'], body)
print('--------------req to withdraw------------------------')
print(resp)
print(with_req)
asyncio.run(main())
Links
Documentation <https://momopy.rewriteapi.cm>_Official Discord Server <https://discord.gg/8hS3tvkfrF>_Website <https://rewriteapi.cm>_
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mobilemoney.py-0.1.2.tar.gz.
File metadata
- Download URL: mobilemoney.py-0.1.2.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b74fee9ad1a78c6b34a9496cccdec08f91d7407c37cb946b7276e0e639a0c59
|
|
| MD5 |
7f977678924ca6698603d3e7436fa547
|
|
| BLAKE2b-256 |
8cf6988182b53c0122a65c94e16350cc5ef38c58ffa281943c59805a0e892c2e
|
File details
Details for the file mobilemoney.py-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mobilemoney.py-0.1.2-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f738d7e7d66a4f53aa68c94cf0eef9cef924dcf58e7bbbac2e3c1a78e02bffb
|
|
| MD5 |
a4d1f05f8d56afc1a30bd0d1cac7f3b4
|
|
| BLAKE2b-256 |
bf240bd61d1cded115eeb83e13592116b414b93e20fe4e4ae44665933145a828
|