atomicpay

Simplified Payments


License
MIT
Install
pip install atomicpay==0.1.3

Documentation

Atomic Pay: Integrate Payments Easily

Provides Python APIs to create, process and manage mobile payments.

DEPRECATED: MAINTENANCE HAS BEEN STOPPED.

Feel free to Fork it and add features it.

Build Status codecov PyPI PyPI PyPI Say Thanks! PRs Welcome

Stage: Draft

Atomic Pay makes it easily possible to intergrate with mpesa or equity. Many More to be supported in future

Installation

pip install atomicpay

Mpesa

>>> import atomicpay as atm 

>>> mpesa = atm.Mpesa(<key>, <secret>, <config>)

Or

>>> import atomicpay as atm

>>> with atm.Mpesa(<key>, <secret>, config=configs) as at:
>>>      print(at.balance())

Takes the consumer key, consumer secret and the configuration dict

Live defaults to False

>>> mpesa = atm.Mpesa(<key>, <secret>, <config>, live=True)

Sample Mpesa Listener

Configurations

In order to simplify the work of integrating it is worth it to write a one time config dict

configs = {
    "Shortcode": 111111,
    "Initiator": "AtomicPay",
    "SecurityCredential": "xxxxxxxx...",
    "Shortcode2": 222222, #Test PartyB
    "MSISDN": 254712345678, #Test
    "LipaShortcode": 333333,
    "LipaPassKey": "xxxxxxxx...",
    "URLS":{
        "BALANCE":{
            "QueueTimeOutURL": "",
            "ResultURL": "",
        },
        "TRANSACTIONS":{
            "QueueTimeOutURL": "",
            "ResultURL": "",
        },
        "B2B":{
            "QueueTimeOutURL": "",
            "ResultURL": ",
        },
        "B2C":{
            "QueueTimeOutURL": "",
            "ResultURL": "",
        },
        "LIPA":{
            "CallBackURL": "",
        }
    }   
}

Pass the configs

>>> mpesa = atm.Mpesa(<key>, <secret>, config=configs, live=False)

Responses

Every mpesa api call return an instance of MpesaResponse

Every equity api call return an instance of EquityResponse

MpesaResponse

  • .json(): Returns the original json response [json]
  • .code: Returns mpesa status code [str]
  • .ok: Returns True for successful requests else False
  • .text: Returns the response description
>>> balance = mpesa.balance()

>>> print(balance) #prints <MpesaResponse [200]>

"""Response Description message"""
>>> balance.text

"""Mpesa status code"""
>>> balance.code

"""Check if requests was successful"""
>>> if balance.ok:
>>>    print("Okayyy")

Balance

>>> response = mpesa.balance()

Transactions

>>> response = mpesa.transaction(<txn_id>, <originator_id>)

Business to Business

>>> b2b = mpesa.b2b()

>>> response = b2b.buy_goods(<shortcode>, <amount>, <reference>,<remarks>)

>>> response = b2b.paybill(<shortcode>, <amount>, <reference>,<remarks>)

Business to Customer

>>> b2c = mpesa.b2c()

>>> response = b2c.pay_salary(<phone>, <amount>, <remarks>)

>>> response = b2c.pay_business(<phone>, <amount>, <remarks>)

>>> response = b2c.pay_promotion(<phone>, <amount>, <remarks>, <occassion>)

Customer to Business

>>> c2b = mpesa.c2b()

>>> response = c2b.buy_goods(<phone>, <amount>, <reference>)

>>> response = c2b.paybill(<phone>, <amount>, <reference>)

Lipa Na Mpesa

>>> lipa = mpesa.lipa()

>>> pay = lipa.pay(<to>, <amount>, <description>, <reference>)

>>> if pay.ok:
        checkout_id = pay.json()['CheckoutRequestID']
        response = lipa.query(checkout_id)        
        print(response.json())

Advanced

Every atomicpay api is also async just pass a callback and thats all

>>> def callback(response):
>>>     print(response)

>>> mpesa.balance(callback=callback)
>>> print("mpesaaa")

>>> # mpesaaa
>>> # <MpesaResponse [200]>

Not Implemented

B2B

  • DisburseFundsToBusiness
  • BusinessToBusinessTransfer
  • MerchantToMerchantTransfer