Skip to main content

pypesa

Pypesa banner PyPI version Releases Downloads Downloads Downloads License: MIT

Python wrapper on Mpesa public API for mobile Payment Integration made with care to offer easy and elegant integration made by kalebu

Become a patron

Implemented Features

The following are the features that are supported by the Mpesa public API and require the python implementation.

  • Customer to Bussiness (C2B) Single Payment
  • Bussiness to Customer (B2C)
  • Bussiness to Bussiness (B2B)
  • Payment Reversal
  • Query Transaction status
  • Direct debit creation and Payment

Documentation

Full documentation can be found on pypesa

Getting started

Getting started with pypesa is pretty straight forward and can be categorized

into steps shown below.

  • Sign up for Mpesa Developer portal

  • Install the pypesa package using pip

  • Build your services with pypesa

Signing up

To sign up for Mpesa public API visit Mpesa-API and then

you can go through getting started Mpesa Developer portal by alphaolomi to see how.

Installation

To install the pypesa package to your machine you can either

install directly from github or use pip to install it.

  • Using github
$~ git clone https://github.com/Kalebu/pypesa
$~ cd pypesa
$ pypesa ~ python setup.py install 
  • Using pip
pip install python-pesa

Usage

To begin using the package is pretty straight forward

  1. You need to have a json file named keys.json on your project directly and then fill put in it your public and api keys in json format shown below
  {
   'api_key': 'xxx', 
   'public_key': 'xxxxxxxxxxxxxx' 
  }

2.Once done you're ready to go, just make sure you have active internet connection

Example of Usage (Customer to Bussiness Transaction)

>>> import pypesa
>>> mpesa = pypesa()
>>> transaction_query = {"input_Amount": "10", 
                        "input_Country": "TZN", 
                        "input_Currency": "TZS", 
                        "input_CustomerMSISDN": "000000000001", 
                        "input_ServiceProviderCode": "000000", 
                        "input_ThirdPartyConversationID":'2edf7a0206d848f6b6fedea26accdc3a', 
                        "input_TransactionReference": 'T23434ZE5',
                        "input_PurchasedItemsDesc": "Python Book"
}
>>> mpesa.customer_to_bussiness(transaction_query)

Request processed successfully   INS-0
{'output_ResponseCode': 'INS-0', 'output_ResponseDesc': 'Request processed successfully',
 'output_TransactionID': 'uGnPxFoXT2W0', 'output_ConversationID': '1d1e38495dc946729a8cffb136ab8391', 'output_ThirdPartyConversationID': '2edf7a0206d848f6b6fedea26accdc3a'}

Naming the authentication json

If you named your authentication json in other name than keys you might to specify it while creating an instance for mpesa just as shown below;

>>> import pypesa
>>> mpesa = pypesa(auth_path = filename)

production environmnent

The package run by default using sandbox environmnent, If you wanna use it to real production environmnent you can specify it while creating an instance as shown below

>>> import pypesa
>>> mpesa = pypesa(environmnent="production")

To do list

  • Adding a well structured documentation
  • Adding a detailed test case to the implementation
  • Fixing rising bugs

Contributing

Wanna contribute to Pypesa ? then please contributing.md to see how

Give it a star

If you found this repository useful, give it a star, You can also keep in touch with on twitter.

Bug bounty?

If you encounter issue with the usage of the package, feel free raise an issue so as we can fix it as soon as possible(ASAP) or just reach me directly through my email isaackeinstein(at)gmail.com

Credit

All the credits to kalebu and all the future contributors

Metadata

Release files for python-pesa 0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-pesa 0.7
File Size Uploaded Provenance
python-pesa-0.7.tar.gz 10.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for python-pesa 0.7
File Interpreter ABI Platform
python_pesa-0.7-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / python-pesa-0.7.tar.gz

Download URL python-pesa-0.7.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
12d9555c4d8d92a0343bc7106e45227264d9ee46f77a1298c7ffe9bd538da47f
BLAKE2b-256 checksum
How to use checksums
17eddf17fdffd5496cbd8b62f89975d77f0fd854d9f2a39b757f8e354cd97edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release files / python_pesa-0.7-py3-none-any.whl

Download URL python_pesa-0.7-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88e6098b42ccd040e647d278edac7d64c78f6aa371a7e6e263d17b9f6c94761d
BLAKE2b-256 checksum
How to use checksums
b30a4c11213047a35c26e5bfa920562f9f8d55e9751fd327b29fd768b3d57ede
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Security for python-pesa 0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page