Git Product home page Git Product logo

pypesa's Introduction

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)

>>> from pypesa import Mpesa
>>> mpesa = Mpesa()
>>> 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;

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

production environment

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

>>> from pypesa import Mpesa
>>> mpesa = Mpesa(environment="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

  1. kalebu
  2. SentielWarren
  3. and all the future contributors

pypesa's People

Contributors

dependabot[bot] avatar kalebu avatar sentinelwarren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pypesa's Issues

Payment Reversal raise MpesaConnectionError

When try to reverse a transaction or a particular TransactionID, connection to the openapi portal timeout and raises the Mpesa Connection Error

Here is the sample of the error message;

    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openapi.m-pesa.com', port=433): Max retries exceeded with url: /sandbox/ipg/v2/vodacomTZN/reversal/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f51f410f2e0>: Failed to establish a new connection: [Errno 111] Connection refused'))

Run tests against all supported Python versions.

This is just a suggestion, I used to run tests against the python version I was using on my machine before pushing to GitHuB, using this approach sometimes I found my self breaking my packages on other python versions unknowingly by using some features which are not compatible with some versions of python usually older versions because on my machine I was usually using the latest version. So to avoid this I started using tox and CI to tests my packages against all versions of python which I support before merging changes to master branch this way I would know whether I’ve broken something or not.

So my suggestion here is to add a way to run tests against all versions of python which you want to support so that u don’t break things on other versions unknowingly, don’t just assume whatever runs on python version on your machine will run on other versions too.

Improve pypesa directory structure

Greetings @Kalebu , so this just a suggestion on the package structure improvement. Suggestion list goes as follows;

  • Use __init__.py to only Import key classes | methods from modules directly into the package namespace. i.e the folder structure could then be;
pypesa/
__init__.py
mpesa.py
mpesa_execptions.py
service_urls.py
  • __init__.py could also include other important parameters like, version, author, release date, doc-string with a decent sample usage etc etc.
  • Add a tests folder with the following structure;
tests/
__init__.py
test_pypesa.py

Note, tests/__init__.py can/should be left empty.

  • Any other structural improvements that i haven't listed/noticed yet.

So to sum up, i think i can working on this if you think it might be a good idea. Also, i think there other code related improvements suggestion(mostly on the OOD), that i will definitely create their own separate issues.

Github Actions config

@Kalebu Hello again. So i think at this point it would be advantageous to add Actions to the project for the ease of workflows automation. Current all (if not most) of the workflows a manual, of which its a perfect disasters recipe along the way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.