Metadata-Version: 2.1
Name: mobilemoney.py
Version: 0.1.2
Summary: A Python wrapper for the MoMo Open API
Home-page: https://rewriteapi.cm/momo
Author: rewriteapi
Author-email: <support@rewriteapi.cm>
License: MIT
Project-URL: Documentation, https://momopy.rewriteapi.cm
Project-URL: Website, https://rewriteapi.cm
Project-URL: Repository, https://github.com/rewriteapi/mobilemoney.py
Keywords: python,mobilemoney,MTN Money,rewriteapi,MTN API,mobilemoney-py
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.8.0
Description-Content-Type: text/markdown
License-File: LICENSE

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 ``async`` and ``await``.
- 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>`_

