mtnmomoapi


Namemtnmomoapi JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/sikaili99/mtnmomoapi
SummaryAn easy to use Python wrapper for the MTN MoMo API.
upload_time2023-04-04 00:26:27
maintainer
docs_urlNone
authorMathews Musukuma
requires_python>=3.6
licenseMIT license
keywords momo api momo api python wrapper momo api python mtn zambia momo api python mtn mobile money api python
VCS
bugtrack_url
requirements requests
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MTN MoMo API Python Client</h1>

<strong>Power your apps with Python MTN MoMo API</strong>

# Usage

## 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+

# 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`. 

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:

 ```python
 config = {
    "MTN_ENVIRONMENT": os.environ.get("MTN_ENVIRONMENT"), 
    "BASE_URL": os.environ.get("BASE_URL"), 
    "CALLBACK_HOST": os.environ.get("CALLBACK_HOST"), # Mandatory. SANDBOX
    "CALLBACK_URL": os.environ.get("CALLBACK_URL"),
    "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:

```python
from mtnmomo.collection import Collection

client = Collection()
```

### 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.

### TODO: create this methode

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

### Sample Code

```python
from mtnmomo.collection import Collection

client = Collection()

response = client.requestToPay(amount="600", phone_number="0966456787", 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

```python
from mtnmomo.disbursement import Disbursement

client = Disbursement()
```

### 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.

2. `getBalance`: Get your account balance.

### TODO: create this methode

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

#### Sample Code

```python
from mtnmomo.disbursement import Disbursement

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

```

Keep coding!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sikaili99/mtnmomoapi",
    "name": "mtnmomoapi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "MoMo API,MoMo API Python Wrapper,MoMo API Python,MTN Zambia MoMO API Python,MTN Mobile Money API Python",
    "author": "Mathews Musukuma",
    "author_email": "sikaili99@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/70/16/cb438158d0f6728f45aa04d073a7ab2fd84dded402ebee326fd1c8e5f78f/mtnmomoapi-0.0.7.tar.gz",
    "platform": null,
    "description": "# MTN MoMo API Python Client</h1>\n\n<strong>Power your apps with Python MTN MoMo API</strong>\n\n# Usage\n\n## Installation\n\nAdd the latest version of the library to your project:\n\n```bash\n $ pip install mtnmomoapi\n```\n\nThis library supports Python 2.7+ or Python 3.4+\n\n# Sandbox Environment\n\n## Creating a sandbox environment API user \n\nNext, 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`. \n\nThese 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.\n\n## Configuration\n\nBefore we can fully utilize the library, we need to specify global configurations. The global configuration must contain the following:\n\n* `BASE_URL`: An optional base url to the MTN Momo API. By default the staging base url will be used\n* `ENVIRONMENT`: Optional environment, either \"sandbox\" or \"production\". Default is 'sandbox'\n* `CALLBACK_HOST`: The domain where you webhooks urls are hosted. This is mandatory.\n\nOnce 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. \n\nThe full list of configuration options can be seen in the example below:\n\n ```python\n config = {\n    \"MTN_ENVIRONMENT\": os.environ.get(\"MTN_ENVIRONMENT\"), \n    \"BASE_URL\": os.environ.get(\"BASE_URL\"), \n    \"CALLBACK_HOST\": os.environ.get(\"CALLBACK_HOST\"), # Mandatory. SANDBOX\n    \"CALLBACK_URL\": os.environ.get(\"CALLBACK_URL\"),\n    \"COLLECTION_PRIMARY_KEY\": os.environ.get(\"COLLECTION_PRIMARY_KEY\"), \n    \"COLLECTION_USER_ID\": os.environ.get(\"COLLECTION_USER_ID\"),\n    \"COLLECTION_API_SECRET\": os.environ.get(\"COLLECTION_API_SECRET\"),\n    \"REMITTANCE_USER_ID\": os.environ.get(\"REMITTANCE_USER_ID\"), \n    \"REMITTANCE_API_SECRET\": os.environ.get(\"REMITTANCE_API_SECRET\"),\n    \"REMITTANCE_PRIMARY_KEY\": os.envieon.get(\"REMITTANCE_PRIMARY_KEY\"),\n    \"DISBURSEMENT_USER_ID\": os.environ.get(\"DISBURSEMENT_USER_ID\"), \n    \"DISBURSEMENT_API_SECRET\": os.environ.get(\"DISBURSEMENTS_API_SECRET\"),\n    \"DISBURSEMENT_PRIMARY_KEY\": os.environ.get(\"DISBURSEMENT_PRIMARY_KEY\"), \n}\n```\n\nYou will only need to configure the variables for the product(s) you will be using.\n\n## Collections\n\nThe 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;\n\n* `COLLECTION_PRIMARY_KEY`: Primary Key for the `Collection` product on the developer portal.\n* `COLLECTION_USER_ID`: For sandbox, use the one generated with the `mtnmomo` command.\n* `COLLECTION_API_SECRET`: For sandbox, use the one generated with the `mtnmomo` command.\n\nYou can create a collection client with the following:\n\n```python\nfrom mtnmomo.collection import Collection\n\nclient = Collection()\n```\n\n### Methods\n\n1. `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`.\n\n2. `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. \n\n3. `getBalance`: Get the balance of the account.\n\n### TODO: create this methode\n\n`isPayerActive`: check if an account holder is registered and active in the system.\n\n### Sample Code\n\n```python\nfrom mtnmomo.collection import Collection\n\nclient = Collection()\n\nresponse = client.requestToPay(amount=\"600\", phone_number=\"0966456787\", external_id=\"123456789\", payee_note=\"dd\", payer_message=\"dd\", currency=\"EUR\")\n```\n\n## Disbursement\n\nThe 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;\n\n* `DISBURSEMENT_PRIMARY_KEY`: Primary Key for the `Disbursement` product on the developer portal.\n* `DISBURSEMENT_USER_ID`: For sandbox, use the one generated with the `mtnmomo` command.\n* `DISBURSEMENT_API_SECRET`: For sandbox, use the one generated with the `mtnmomo` command.\n\nYou can create a disbursements client with the following\n\n```python\nfrom mtnmomo.disbursement import Disbursement\n\nclient = Disbursement()\n```\n\n### Methods\n\n1. `transfer`: Used to transfer an amount from the owner\u2019s account to a payee account. Status of the transaction can be validated by using the `getTransactionStatus` method.\n\n2. `getTransactionStatus`: Retrieve transaction information using the `transactionId` returned by `transfer`. You can invoke it at intervals until the transaction fails or succeeds.\n\n2. `getBalance`: Get your account balance.\n\n### TODO: create this methode\n\n`isPayerActive`: This method is used to check if an account holder is registered and active in the system.\n\n#### Sample Code\n\n```python\nfrom mtnmomo.disbursement import Disbursement\n\nclient = Disbursement()\nresponse = client.transfer(amount=\"600\", phone_number=\"0966456787\", external_id=\"123456789\", payee_note=\"dd\",      payer_message=\"dd\", currency=\"EUR\")\n\n```\n\nKeep coding!\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "An easy to use Python wrapper for the MTN MoMo API.",
    "version": "0.0.7",
    "split_keywords": [
        "momo api",
        "momo api python wrapper",
        "momo api python",
        "mtn zambia momo api python",
        "mtn mobile money api python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7602d501fe946d16581704ab5594819ef9bcd69bc03c77cbbdb4e9e9f9f195f2",
                "md5": "d10dcdfef33894ad28de0fcdb34e2210",
                "sha256": "d5910083a855de55b1b357b31f41b2f46027f087965adb308aa4c68a18b2a0f1"
            },
            "downloads": -1,
            "filename": "mtnmomoapi-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d10dcdfef33894ad28de0fcdb34e2210",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6864,
            "upload_time": "2023-04-04T00:26:25",
            "upload_time_iso_8601": "2023-04-04T00:26:25.526618Z",
            "url": "https://files.pythonhosted.org/packages/76/02/d501fe946d16581704ab5594819ef9bcd69bc03c77cbbdb4e9e9f9f195f2/mtnmomoapi-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7016cb438158d0f6728f45aa04d073a7ab2fd84dded402ebee326fd1c8e5f78f",
                "md5": "68d1829ade4dca5b87aacc08c7c2e86e",
                "sha256": "083e2d0b9ce95e0c2cca1c6694c4de541a775ae28a8bcf4264ed8b34d0b40bc3"
            },
            "downloads": -1,
            "filename": "mtnmomoapi-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "68d1829ade4dca5b87aacc08c7c2e86e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7848,
            "upload_time": "2023-04-04T00:26:27",
            "upload_time_iso_8601": "2023-04-04T00:26:27.573953Z",
            "url": "https://files.pythonhosted.org/packages/70/16/cb438158d0f6728f45aa04d073a7ab2fd84dded402ebee326fd1c8e5f78f/mtnmomoapi-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-04 00:26:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "sikaili99",
    "github_project": "mtnmomoapi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.24.0"
                ]
            ]
        }
    ],
    "lcname": "mtnmomoapi"
}
        
Elapsed time: 0.06110s