diff --git a/AUTHORS.md b/AUTHORS.md index 71ef76b..0343a4e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -2,4 +2,7 @@ Authors ======= -* Moses Mugisha - http://sparkpl.ug +* Moses Mugisha +* Ray Besiga + +For [Sparkplug](http://sparkpl.ug) \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 28de1ce..be573c9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,30 +1,79 @@ -============ -Contributing -============ +# Contributing -Contributions are welcome, and they are greatly appreciated! Every -little bit helps, and credit will always be given. +First off, thank you for considering contributing to this Python MTN MoMo Library. It's people like you that make it such a great tool. Contributions are welcome, and they are greatly appreciated! -Bug reports -=========== +## Where do I go from here? -When `reporting a bug `_ please include: +If you've noticed a bug or have a question that doesn't belong on the +[Spectrum](https://spectrum.chat/momo-api-developers/) or [Stack Overflow](https://stackoverflow.com/), [search the issue tracker](https://github.com/sparkplug/momoapi-python/issues) to see if +someone else in the community has already created a ticket. If not, go ahead and +[make one](https://github.com/sparkplug/momoapi-python/issues/new/choose)! - * Your operating system name and version. - * Any details about your local setup that might be helpful in troubleshooting. - * Detailed steps to reproduce the bug. -Documentation improvements -========================== -momoapi-python could always use more documentation, whether as part of the -official momoapi-python docs, in docstrings, or even on the web in blog posts, -articles, and such. +## Fork & create a branch -Feature requests and feedback -============================= +If there is something you think you can fix, then fork the [repo](https://github.com/sparkplug/momoapi-python) and create a branch with a descriptive name. -The best way to send feedback is to file an issue at https://github.com/mossplix/python-momoapi/issues. +A good branch name would be (where issue #32 is the ticket you're working on): + +```sh +git checkout -b 32-add-swahili-translations +``` + +## Get the test suite running + +This library has a comprehensive test suite, which can be run using the `tox` command: + +To view all test environments + +```sh +$ tox -l +``` +To run the tests for Python 2.7 + +```sh +$ tox -e py27-cover +``` + +To run the tests for Python 3.4 + +```sh +$ tox -e py34-cover +``` + +To run a subset of tests:: + +```sh +tox -e envname -- pytest -k test_myfeature +``` + +To run all the test environments in *parallel*, you need to `pip install detox`: + +```sh +detox +``` + +## Bugs and Fixes + +### Did you find a bug? + +* **Ensure the bug was not already reported** by [searching all issues](https://github.com/sparkplug/momoapi-python/issues). + +* If you're unable to find an open issue addressing the problem, + [open a new one](https://github.com/sparkplug/momoapi-python/issues/new/choose). Be sure to include a **title and clear + description**, as much relevant information as possible, and a **code sample** + or an **executable test case** demonstrating the expected behavior that is not + occurring. + +* If possible, use the relevant bug report templates to create the issue. + Make the necessary changes to demonstrate the issue, and **paste the content into the + issue description** + +### Implement your fix or feature + +At this point, you're ready to make your changes! Feel free to ask for help; +everyone is a beginner at first :smile_cat: If you are proposing a feature: @@ -32,59 +81,120 @@ If you are proposing a feature: * Keep the scope as narrow as possible, to make it easier to implement. * Remember that this is a volunteer-driven project, and that code contributions are welcome :) -Development -=========== - -To set up `python-momoapi` for local development: +If you would like to send us feedback, simply [file an issue](https://github.com/sparkplug/momoapi-python/issues/new/choose). -1. Fork `python-momoapi `_ - (look for the "Fork" button). -2. Clone your fork locally:: +## Local Development - git clone git@github.com:your_name_here/python-momoapi.git +To set up `python-momoapi` for local development: -3. Create a branch for local development:: +1. Fork the repo. Look for the "Fork" button in the Github UI. +2. Clone your fork locally: - git checkout -b name-of-your-bugfix-or-feature +```sh +git clone https://github.com/your_name_here/momoapi-python.git +``` - Now you can make your changes locally. +3. Create a branch for local development: +```sh +git checkout -b name-of-your-bugfix-or-feature +``` -4. When you're done making changes, run all the checks, doc builder and spell checker with `tox `_ one command:: +Now you can make your changes locally. - tox +4. When you're done making changes, run all the checks, doc builder and spell checker with `tox`. +```sh +tox +``` +Make sure Tox is installed by following the instructions [here](http://tox.readthedocs.io/en/latest/install.html) 5. Commit your changes and push your branch to GitHub:: - git add . - git commit -m "Your detailed description of your changes." - git push origin name-of-your-bugfix-or-feature +```sh +git add . +git commit -m "Your detailed description of your changes." +git push origin name-of-your-bugfix-or-feature +``` 6. Submit a pull request through the GitHub website. -Pull Request Guidelines ------------------------ +## Pull Request Guidelines -If you need some code review or feedback while you're developing the code just make the pull request. +### Make a Pull Request -For merging, you should: +At this point, you should switch back to your master branch and make sure it's +up to date with `momoapi-python`'s master branch: -1. Include passing tests (run ``tox``) [1]_. -2. Update documentation when there's new API, functionality etc. -3. Add a note to ``CHANGELOG.rst`` about the changes. -4. Add yourself to ``AUTHORS.rst``. +```sh +git remote add upstream https://github.com/sparkplug/momoapi-python.git +git checkout master +git pull upstream master +``` -.. [1] If you don't have all the necessary python versions available locally you can rely on Travis - it will - `run the tests `_ for each change you add in the pull request. +Then update your feature branch from your local copy of master, and push it! - It will be slower though ... +```sh +git checkout 32-add-swahili-translations +git rebase master +git push --set-upstream origin 32-add-swahili-translations +``` -Tips ----- +Finally, go to GitHub and make a Pull Request :D -To run a subset of tests:: +TravisCI will run our test suite against all supported Python versions. We care +about quality, so your PR won't be merged until all tests pass. It's unlikely, +but it's possible that your changes pass tests in one Python version but fail in +another. In that case, you'll have to setup your development environment to use your Python version, and investigate what's going on! + +### Keeping your Pull Request updated + +If a maintainer asks you to "rebase" your PR, they're saying that a lot of code has changed, and that you need to update your branch so it's easier to merge. + +To learn more about rebasing in Git, there are a lot of [good](https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase) [resources](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) but here's the suggested workflow: + +```sh +git checkout 32-add-swahili-translations +git pull --rebase upstream master +git push --force-with-lease 32-add-swahili-translations +``` + +### Merging a PR (maintainers only) + +A PR can only be merged into master by a maintainer if: + +* It is passing CI. +* It has been approved by at least one maintainers. If it was a maintainer who opened the PR, only one extra approval is needed. +* It has no requested changes. +* It is up to date with current master. + +Any maintainer is allowed to merge a PR if all of these conditions are met. + +### Shipping a release (maintainers only) + +Maintainers need to do the following to push out a release: + +* Make sure all pull requests are in and that changelog is current +* Update version and changelog with new version number using semver +* If it's not a patch level release, create a stable branch for that release, + otherwise switch to the stable branch corresponding to the patch release you + want to ship: + + ```sh + git checkout master + git fetch momoapi-python + git rebase momoapi-python/master + # If the release is 2.1.x then this should be: 2-1-stable + git checkout -b N-N-stable + git push momoapi-python N-N-stable:N-N-stable + ``` + +Before you make a Pull Request, make sure of the following: + +1. Make sure your tests pass. Run `tox` beforehand. +2. Update documentation where necessary. +3. Note changes to `CHANGELOG.md`. +4. Add yourself to `AUTHORS.md`. - tox -e envname -- pytest -k test_myfeature +## Improvements -To run all the test environments in *parallel* (you need to ``pip install detox``):: +This library could always use more documentation, whether as part of the official docs, in docstrings, or even in blog posts and articles. We look forward to add them to our RESOURCES file. - detox diff --git a/README.md b/README.md index 4ce45fc..5e46eed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,29 @@ -# MTN Mobile Money API Client +# MTN MoMo API Python Client + + + +**🛑 This repository is no longer actively maintained.** + +As of July 14, 2025, this project is no longer under active development. This means: +* No new features will be added. +* Bugs will not be fixed. +* Pull requests will not be reviewed or merged. +* Issues will not be addressed. + +We appreciate your interest and contributions. +**Thank you.** + +
+ +Power your apps with our MTN MoMo API +
+ Join our active, engaged community:
+ Website + | + Spectrum +

+
-MTN MoMo API Client for Python. [![Build Status](https://travis-ci.com/sparkplug/momoapi-python.svg?branch=master)](https://travis-ci.com/sparkplug/momoapi-node) [![Latest Version](https://img.shields.io/pypi/v/tox-travis.svg)](https://badge.fury.io/js/mtn-momo) @@ -8,7 +31,9 @@ MTN MoMo API Client for Python. [![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/momo-api-developers/) -# Installing +# Usage + +## Installation Add the latest version of the library to your project using pip: @@ -44,7 +69,7 @@ These are the credentials we shall use for the sandbox environment. In productio 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 enviroment, either "sandbox" or "production". Default is 'sandbox' +* `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. @@ -95,7 +120,7 @@ client = Collection({ 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. `getTransaction`: 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. +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. @@ -129,7 +154,7 @@ You can create a disbursements client with the following ```python import os -from mtnmomo.collection import Disbursement +from mtnmomo.disbursement import Disbursement client = Disbursement({ "DISBURSEMENT_USER_ID": os.environ.get("DISBURSEMENT_USER_ID"), @@ -152,7 +177,7 @@ client = Disbursement({ ```python import os -from mtnmomo.collection import Disbursement +from mtnmomo.disbursement import Disbursement client = Disbursement({ "DISBURSEMENT_USER_ID": os.environ.get("DISBURSEMENT_USER_ID"), @@ -164,25 +189,4 @@ client.transfer(amount="600", mobile="256772123456", external_id="123456789", pa ``` -# Unit Tests - -This library has a comprehensive test suite, which can be run using the `tox` command: - -## to view all test environments - -```bash -$ tox -l -``` -## to run the tests for Python 2.7 - -```bash -$ tox -e py27-cover -``` - -## to run the tests for Python 3.4 - -```bash -$ tox -e py34-cover -``` - Thank you. diff --git a/RESOURCES.md b/RESOURCES.md new file mode 100644 index 0000000..e2899d7 --- /dev/null +++ b/RESOURCES.md @@ -0,0 +1,11 @@ +# Resources + +Here, we keep a list of resources for use of the library + +## Official Docs + +* [Developer Portal](https://momodeveloper.mtn.com/api-documentation) + +## Articles + + diff --git a/src/mtnmomo/client.py b/src/mtnmomo/client.py index fdeee8f..2740009 100644 --- a/src/mtnmomo/client.py +++ b/src/mtnmomo/client.py @@ -99,7 +99,6 @@ def request(self, method, url, headers, post_data=None): def interpret_response(self, resp): rcode = resp.status_code rheaders = resp.headers - print(resp) try: rbody = resp.json() @@ -163,7 +162,6 @@ def getTransactionStatus( "Ocp-Apim-Subscription-Key": subscription_key } _url = self.config.baseUrl + url + transaction_id - print(_url) res = self.request("GET", _url, headers) return res.json() @@ -192,5 +190,4 @@ def generateToken( def close(self): if self._session is not None: - print("closing!") self._session.close() diff --git a/src/mtnmomo/config.py b/src/mtnmomo/config.py index 7376814..60c6912 100644 --- a/src/mtnmomo/config.py +++ b/src/mtnmomo/config.py @@ -18,7 +18,7 @@ def __init__(self, conf): 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") + REMITTANCE_PRIMARY_KEY: os.environ.get("REMITTANCE_PRIMARY_KEY") DISBURSEMENT_USER_ID: os.environ.get("DISBURSEMENT_USER_ID"), DISBURSEMENT_API_SECRET: os.environ.get("DISBURSEMENTS_API_SECRET"), diff --git a/src/mtnmomo/disbursement.py b/src/mtnmomo/disbursement.py index 6d71deb..4472b95 100644 --- a/src/mtnmomo/disbursement.py +++ b/src/mtnmomo/disbursement.py @@ -58,6 +58,5 @@ def transfer( if kwargs.get("callback_url"): headers["X-Callback-Url"] = kwargs.get("callback_url") url = super(Disbursement, self).config.baseUrl + "/disbursement/v1_0/transfer" - print(url) self.request("POST", url, headers, data) return {"transaction_ref": ref}