{"id":20130005,"url":"https://github.com/tralahm/pytekmomoapi","last_synced_at":"2025-04-09T16:13:08.654Z","repository":{"id":62583979,"uuid":"303624101","full_name":"TralahM/pytekmomoapi","owner":"TralahM","description":"An Opinionated Python SDK for the for the MTN Mobile Money API. The goal of this SDK library is to enable python developers implement MTN Mobile Money APIs in a flexible, yet consistent manner.","archived":false,"fork":false,"pushed_at":"2024-11-02T15:43:34.000Z","size":77,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T16:12:58.418Z","etag":null,"topics":["api-client","finance","mobilemoney","momoapi","mtnmobilemoney","sdk-python","tralahm","tralahtek"],"latest_commit_sha":null,"homepage":"https://pytekmomoapi.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TralahM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.rst","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"TralahM","patreon":"TralahM","custom":"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=WFKVHBRCYEE6S\u0026source=url"}},"created_at":"2020-10-13T07:34:16.000Z","updated_at":"2025-01-27T19:39:22.000Z","dependencies_parsed_at":"2024-11-13T20:49:41.003Z","dependency_job_id":null,"html_url":"https://github.com/TralahM/pytekmomoapi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TralahM%2Fpytekmomoapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TralahM%2Fpytekmomoapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TralahM%2Fpytekmomoapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TralahM%2Fpytekmomoapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TralahM","download_url":"https://codeload.github.com/TralahM/pytekmomoapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065282,"owners_count":21041872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","finance","mobilemoney","momoapi","mtnmobilemoney","sdk-python","tralahm","tralahtek"],"created_at":"2024-11-13T20:37:04.484Z","updated_at":"2025-04-09T16:13:08.628Z","avatar_url":"https://github.com/TralahM.png","language":"Python","funding_links":["https://github.com/sponsors/TralahM","https://patreon.com/TralahM","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=WFKVHBRCYEE6S\u0026source=url"],"categories":[],"sub_categories":[],"readme":"\n[![Build Status](https://travis-ci.com/TralahM/pytekmomoapi.svg?branch=master)](https://travis-ci.com/TralahM/pytekmomoapi)\n[![Build status](https://ci.appveyor.com/api/projects/status/yvvmq5hyf7hj743a/branch/master?svg=true)](https://ci.appveyor.com/project/TralahM/pytekmomoapi/branch/master)\n[![Documentation Status](https://readthedocs.org/projects/pytekmomoapi/badge/?version=latest)](https://pytekmomoapi.readthedocs.io/en/latest/?badge=latest)\n[![License: GPLv3](https://img.shields.io/badge/License-GPLV2-green.svg)](https://opensource.org/licenses/GPLV2)\n[![Organization](https://img.shields.io/badge/Org-TralahTek-blue.svg)](https://github.com/TralahTek)\n[![Views](http://hits.dwyl.io/TralahM/pytekmomoapi.svg)](http://dwyl.io/TralahM/pytekmomoapi)\n[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square)](https://github.com/TralahM/pytekmomoapi/pull/)\n[![GitHub pull-requests](https://img.shields.io/badge/Issues-pr-red.svg?style=flat-square)](https://github.com/TralahM/pytekmomoapi/pull/)\n[![Language](https://img.shields.io/badge/Language-python-3572A5.svg)](https://github.com/TralahM)\n\u003cimg title=\"Watching\" src=\"https://img.shields.io/github/watchers/TralahM/pytekmomoapi?label=Watchers\u0026color=blue\u0026style=flat-square\"\u003e\n\u003cimg title=\"Stars\" src=\"https://img.shields.io/github/stars/TralahM/pytekmomoapi?color=red\u0026style=flat-square\"\u003e\n\u003cimg title=\"Forks\" src=\"https://img.shields.io/github/forks/TralahM/pytekmomoapi?color=green\u0026style=flat-square\"\u003e\n\n# pytekmomoapi.\n\nAn Opinionated Python SDK for the for the MTN Mobile Money API.\nThe goal of this SDK library is to enable python developers implement\nMTN Mobile Money APIs in a flexible, yet consistent manner.\n\nThe Open API is a JSON REST API that is used by Partner systems to access services in the Wallet platform.\nThe Open API exposes services that are used by e.g. online merchants for managing payments and other financial services.\n\n[![TralahTek](https://img.shields.io/badge/Organization-TralahTek-black.svg?style=for-the-badge\u0026logo=github)](https://github.com/TralahTek)\n[![TralahM](https://img.shields.io/badge/Engineer-TralahM-blue.svg?style=for-the-badge\u0026logo=github)](https://github.com/TralahM)\n[![TralahM](https://img.shields.io/badge/Maintainer-TralahM-green.svg?style=for-the-badge\u0026logo=github)](https://github.com/TralahM)\n\n# Documentation\nMore Documentation can be found on readthedocs below:\n\n\n[![Documentation](https://img.shields.io/badge/Docs-pytekmomoapi-blue.svg?style=for-the-badge)](https://pytekmomoapi.readthedocs.io)\n\n# How to Install\n```bash\n# In terminal do:\n$ pip install pytekmomoapi\n```\n\n## Building from Source for Developers\n\n```console\n$ git clone https://github.com/TralahM/pytekmomoapi.git\n$ cd pytekmomoapi\n$ python setup.py install\n```\n\nQuickstart\n==========\n\nInstallation\n------------\n\n``` console\npip install pytekmomoapi\n```\n\nSandbox User Provisioning\n-------------------------\n\nWe have provided a convenient function,\n`tekmomoapi.get_user_id_and_api_key` , to help you\nquickly provision and get the required credentials i.e the **user_id**\nand **apiKey** on the sandbox environment.\n\nThe Library also provided a utility function to get a random\n`uuid.uuid4` string, this is quite useful because the\nremote Momo Developer API heavily uses uuid4s for identification and\nreferencing, i.e during user provisioning, financial transactions, party\nidentification and referencing. The function\n`tekmomoapi.get_random_uuid_str` provides that\nconvenience.\n\nThis reduces the amount of boilerplate code that would be otherwise\nrequired.\n\n### Example\n\n``` python\nimport tekmomoapi\ncreds=dict(\n   collection_subscription_key=\"3265aef9928c259a31b44faf812dc2da\",\n   remittance_subscription_key=\"928c259a31b44faf812dc2da3265aef9\",\n   disbursement_subscription_key=\"31b44faf812dc2da928c259a3265aef9\",\n)\ncuser = tekmomoapi.get_user_id_and_api_key(\n    creds.get(\"collection_subscription_key\"))\n\nduser = tekmomoapi.get_user_id_and_api_key(\n    creds.get(\"disbursement_subscription_key\"))\n\nuser = tekmomoapi.get_user_id_and_api_key(\n   creds.get(\"remittance_subscription_key\"))\n```\n\n```python\n    user = tekmomoapi.get_user_id_and_api_key(creds.get(\"remittance_subscription_key\"))\n    print(user)\n    {'user_id': 'fcbf0091-2dbe-4f37-9131-46a2a0dcda9e', 'apiKey': 'cb196acfa75b4bf1858b5dccdbb605a6'}\n```\n\nAuthentication and Authorization\n--------------------------------\n\nOAuth Token is generated from the merchants' API Key and Secret. The API\nKey and API Secret can be obtained through the provisioning API in\nSandbox.\n\nWe have built-in the authentication and authorization processes so you\ndont have to worry about base64 encodings, whether to user Bearer or\nBasic Authentication, enabling you to focus on more important details\ni.e your business logic implementation and other more fun stuff.\n\nYou can obtain the authentication header string anytime if you wish to\ndo so by using the top level `tekmomoapi.scaffold.BaseAPI`{.pycode\n.python} and its subclassess\n`tekmomoapi.scaffold.BaseAPI.basic_auth_str` or the\n`tekmomoapi.scaffold.BaseAPI.bearer_auth_str` property\nmethods.\n\n### Example\n\n``` python\nRemAPI = tekmomoapi.RemittanceAPI(\n    creds.get(\"remittance_subscription_key\"),\n    base_url=tekmomoapi.SANDBOX_BASE_URL,\n    **user,\n)\nDisAPI = tekmomoapi.DisbursementAPI(\n    creds.get(\"disbursement_subscription_key\"),\n    base_url=tekmomoapi.SANDBOX_BASE_URL,\n    **duser,\n)\nColAPI = tekmomoapi.CollectionAPI(\n    creds.get(\"collection_subscription_key\"),\n    base_url=tekmomoapi.SANDBOX_BASE_URL,\n    **cuser,\n)\nprint(\"Remittance Basic Auth str: \",RemAPI.basic_auth_str)\nprint(\"Collection Bearer Auth str: \",ColAPI.bearer_auth_str)\nprint(\"Disbursement Basic Auth str: \",DisAPI.basic_auth_str)\nprint(\"Disbursement Bearer Auth str: \",DisAPI.bearer_auth_str)\n```\n\nAccount Balance and Account Holder Validation\n---------------------------------------------\n\nAll Subclasses of `tekmomoapi.scaffold.BaseAPI` provide\na method for checking the account balance of the respective concrete API\nas well a method for checking whether an account id or **PartyId** is\nactive and valid.\n\n### Example\n\n``` python\nprint(\n    f\"ColAPI.get_account_balance: {ColAPI.get_account_balance('sandbox')}\")\nrembal=RemAPI.get_account_balance()\ndisbal=DisAPI.get_account_balance(x_target_environment=\"sandbox\")\n# print(rembal)\n# print(disbal)\n# Check if Account is Active\ntmsisdn = \"22997108557\"\nColAPI.is_account_active(tmsisdn, 'msisdn', 'sandbox')\nTrue\nRemAPI.is_account_active(tmsisdn, 'msisdn',\n'sandbox')\nTrue\nDisAPI.is_account_active(tmsisdn, 'msisdn', 'sandbox')\nTrue\n```\n\n``` console\nColAPI.get_account_balance: {'availableBalance': '1000', 'currency': 'EUR'}\n```\n\n\nCollections API\n---------------\n\nThe **CollectionAPI** provides a method for requesting payments from\ncustomers as well as a method for checking the status of a payment\nrequest in addition to the aforementioned account balance and validation\nmethods defined in the **BaseAPI** base class.\n\nThe CollectionAPI uses the **CParty** and **PaymentRequest** types for\nits PaymentRequest and Party object arguments.\n\nThe `tekmomoapi.get_collection_party_obj` and\n`tekmomoapi.get_payment_request_obj` provide\nconvenience function to create the required Party and Transfer objects.\n\n### Example\n\nCreate a Collection PaymentRequest Object using the convenience\nfunctions.\n\n``` python\npayment_request_obj = tekmomoapi.get_payment_request_obj(\n    amount=\"100\",\n    currency=\"EUR\",\n    externalId=get_random_uuid_str(),\n    payer=tekmomoapi.get_collection_party_obj(\n        \"msisdn\", \"22997108557\").to_jsonable(),\n    payerMessage=\"Payment Request Message Here\",\n    payeeNote=\"Customer Note Here\",\n)\n```\n\n### Request Payment\n\nUsing the **payment_request_obj** in the example above, we can request\npayment from a customer using the\n`tekmomoapi.CollectionAPI.request_payment` function.\n\n``` python\nColAPI.request_payment(\n    payment_request_obj.externalId,\n    payment_request_obj,\n    x_callback_url=None,\n    x_target_environment=\"sandbox\",\n)\n# Check Payment Request Status\nprint(ColAPI.get_payment_request_status(payment_request_obj.externalId))\n```\n\n``` json\n{\"amount\": \"100\", \"currency\": \"EUR\", \"financialTransactionId\": \"454621636\",\n\"externalId\": \"8b2e92fd-a9a6-48e1-bae5-099d5d3ad4c8\", \"payer\": {\"partyIdType\":\n\"MSISDN\", \"partyId\": \"22997108557\"}, \"payerMessage\": \"Payer Message Here\",\n\"payeeNote\": \"Payee Note Here\", \"status\": \"SUCCESSFUL\"}\n```\n\nDisbursements API\n-----------------\n\nThe **DisbursementAPI** provides a method for initiating transfers from\nthe business to other parties as well as a method for checking the\nstatus of a transfer request in addition to the account balance and\nvalidation methods defined in the base class **BaseAPI**.The\nDisbursementAPI uses the **DTransfer** and **DParty** classes to specify\nits Party and Transfer object arguments.\n\nThe `tekmomoapi.get_disbursement_obj` and\n`tekmomoapi.get_disbursement_party_obj` provide\nconvenience functions to create the correct and desired Transfer and\nParty objects.\n\n### Example\n\nCreate a Disbursement Transfer Object using the convenience functions.\n\n``` python\ndtransfer_obj = tekmomoapi.get_disbursement_transfer_obj(\n    amount=\"100\",\n    currency=\"EUR\",\n    externalId=get_random_uuid_str(),\n    payee=tekmomoapi.get_disbursement_party_obj(\n        \"msisdn\", \"22997108557\"\n    ),  # .to_jsonable(),\n    payerMessage=\"Disbursement Transfer Message Here\",\n    payeeNote=\"Payee Business Note Here\",\n)\n```\n\n### Transfer Funds\n\nUsing the **dtransfer_obj** in the example above, we can transfer funds\nusing the `tekmomoapi.DisbursementAPI.transfer`\nfunction.\n\n``` python\ndtres = DisAPI.transfer(\n    dtransfer_obj.externalId,\n    dtransfer_obj,\n    x_callback_url=None,\n    x_target_environment=\"sandbox\",\n)\n# Check Transaction Status\nprint(DisAPI.get_transfer_status(dtransfer_obj.externalId))\n```\n\n``` json\n{\"amount\": \"100\", \"currency\": \"EUR\", \"financialTransactionId\": \"1501780124\",\n\"externalId\": \"f832c026-fd6a-4414-9660-df3080471bdf\",\n\"payee\": {\"partyIdType\": \"MSISDN\", \"partyId\": \"22997108557\"},\n\"payerMessage\": \"Disbursement Transfer Message Here\",\n\"payeeNote\": \"Payee Business Note Here\", \"status\": \"SUCCESSFUL\"}\n```\n\nRemittance API\n--------------\n\nThe **RemittanceAPI** is almost identical to the **DisbursementAPI**,\nthe methods provided by each are the same and are used in a similar\nfashion. The difference is the type of Transfer and Party objects passed\nto their parameters. To Distinguish between the two the RemittanceAPI\nuses **RTransfer** and **RParty** classes.\n\nThe `tekmomoapi.get_remittance_obj` and\n`tekmomoapi.get_remittance_party_obj` provide\nconvenience functions to create the correct and desired Transfer and\nParty objects.\n\n### Example\n\nCreate a Remittance Transfer Object using the convenience functions.\n\n``` python\ntransfer_obj = tekmomoapi.get_remittance_transfer_obj(\n    amount=\"100\",\n    currency=\"EUR\",\n    externalId=get_random_uuid_str(),\n    payee=tekmomoapi.get_remittance_party_obj(\n        \"msisdn\", \"22997108557\"\n    ),  # .to_jsonable(),\n    payerMessage=\"Remittance Transfer Message Here\",\n    payeeNote=\"Payee Business Note Here\",\n)\n```\n\n### Transfer Funds\n\nUsing the **transfer_obj** in the example above, we can transfer funds\nusing the `tekmomoapi.RemittanceAPI.transfer` function.\n\n``` python\ntres = RemAPI.transfer(\n    transfer_obj.externalId,\n    transfer_obj,\n    x_callback_url=None,\n    x_target_environment=\"sandbox\",\n)\n# Check Transaction Status\nprint(RemAPI.get_transfer_status(transfer_obj.externalId))\n```\n\n``` json\n{\"amount\": \"100\", \"currency\": \"EUR\", \"financialTransactionId\": \"2105998992\",\n\"externalId\": \"566ee525-c60a-4aac-9fb2-0c9dc24dd290\", \"payee\": {\"partyIdType\":\n\"MSISDN\", \"partyId\": \"22997108557\"}, \"payerMessage\": \"Remittance Transfer Message Here\",\n\"payeeNote\": \"Payee Business Note Here\", \"status\": \"SUCCESSFUL\"}\n```\n# Contributing\n[See the Contributing File](CONTRIBUTING.rst)\n\n\n[See the Pull Request File](PULL_REQUEST_TEMPLATE.md)\n\n\n# Support\n\n# LICENCE\n\n[Read the license here](LICENSE)\n\n\n# Self-Promotion\n\n[![](https://img.shields.io/badge/Github-TralahM-green?style=for-the-badge\u0026logo=github)](https://github.com/TralahM)\n[![](https://img.shields.io/badge/Twitter-%40tralahtek-red?style=for-the-badge\u0026logo=twitter)](https://twitter.com/TralahM)\n[![TralahM](https://img.shields.io/badge/Kaggle-TralahM-purple.svg?style=for-the-badge\u0026logo=kaggle)](https://kaggle.com/TralahM)\n[![TralahM](https://img.shields.io/badge/LinkedIn-TralahM-red.svg?style=for-the-badge\u0026logo=linkedin)](https://linkedin.com/in/TralahM)\n\n\n[![Blog](https://img.shields.io/badge/Blog-tralahm.tralahtek.com-blue.svg?style=for-the-badge\u0026logo=rss)](https://tralahm.tralahtek.com)\n\n[![TralahTek](https://img.shields.io/badge/Organization-TralahTek-cyan.svg?style=for-the-badge)](https://org.tralahtek.com)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftralahm%2Fpytekmomoapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftralahm%2Fpytekmomoapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftralahm%2Fpytekmomoapi/lists"}