Skip to main content

Python Wrapper for the ZengaPay API

Project description

ZengaPay API Python Client

Power your apps with our ZengaPay API

This is the ZENGAPAY Python Client Library

Usage

Installation

Add the latest version of the library to your project by using pip:

$ pip install zengapay

This library supports Python 3.6+

Sandbox and Production Environment

Creating a sandbox environment user environment

Before using the library in your applications, please head over to the API Documentation to see how to set up your sandbox environment.

The following is the API Endpoint for our sandbox environment:

https://api.sandbox.zengapay.com/v1

Here is the API Endpoint for our production environment:

https://api.zengapay.com/v1

Configuration

Before we can fully utilize the library, we need to specify the global configurations. The global configuration must contain the following.

  • ZENGAPAY_APP_SETTINGS: Optional environment, either "sandbox" or "production". Default is "sandbox".
  • ZENGAPAY_BASE_URL: An optional base url to ZengaPay API. By default the sandbox base url will be used.
  • ZENGAPAY_USER_API_TOKEN: Your secret user API token. This is mandatory. See he API Documentation to obtain your API token.

Once you have specified the global config variables, the full configuration object to use in your project should look like this.

config = {
    ZENGAPAY_ENVIRONMENT: os.environ.get("ZENGAPAY_APP_SETTINGS", "sandbox"),
    ZENGAPAY_BASE_URL: os.environ.get("ZENGAPAY_BASE_URL", "https://api.sandbox.zengapay.com/v1"),
    ZENGAPAY_USER_API_TOKEN: os.environ.get("ZENGAPAY_USER_API_TOKEN")
}

This will be need for each transaction you will be performing.

Collections.

The collections client can be created with configuration parameters as indicated above.

import os
from zengapay import Collections


config = {
    ZENGAPAY_ENVIRONMENT: os.environ.get("ZENGAPAY_APP_SETTINGS", "sandbox"),
    ZENGAPAY_BASE_URL: os.environ.get("ZENGAPAY_BASE_URL", "https://api.sandbox.zengapay.com/v1"),
    ZENGAPAY_USER_API_TOKEN: os.environ.get("ZENGAPAY_USER_API_TOKEN")
}

client = Collections(config)

Methods

  1. collect: This operation is used to request a payment from another 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 get_collection(transaction_ref) or get_transaction_status(transaction_ref) using the transaction reference.

You can perform a collection using the payload as below. See he API Documentation to get what the parameters mean.

payload = {
    "msisdn": "256703######",  # The phone number that the collection request is intended for.
    "amount": 20000,  #The collection request amount.
    "external_reference": "157899393020236",  # Internal description or reason for this collection request and must be unique for every request. 
    "narration":"Clearing Invoice - #157899393020236"  # Textual narrative describing the transaction. 
}

collection = client.collect(payload)
  1. get_collections: Retrieve the collection transactions for a given account.
collections = client.get_collections()
  1. get_collection: Retrieve a certain collection transaction using the transaction reference
collection = client.get_collection(transaction_ref)
  1. get_transaction_status: The status of the transaction, this can be one of these; PENDING,SUCCEEDED,FAILED,INDETERMINATE
trans_status = client.get_transaction_status(transaction_ref)

Transfers.

The transfers client can be created with configuration parameters as indicated above.

import os
from zengapay import Transfers


config = {
    ZENGAPAY_ENVIRONMENT: os.environ.get("ZENGAPAY_APP_SETTINGS", "sandbox"),
    ZENGAPAY_BASE_URL: os.environ.get("ZENGAPAY_BASE_URL", "https://api.sandbox.zengapay.com/v1"),
    ZENGAPAY_USER_API_TOKEN: os.environ.get("ZENGAPAY_USER_API_TOKEN")
}

client = Transfers(config)

Methods

  1. transfer: Used to transfer an amount from the owner’s account to a payee account. Status of the transaction can be validated by using get_transfer(transaction_ref) or get_transaction_status(transaction_ref) using the transaction reference.

You can perform a transfer using the payload as below. See he API Documentation to get what the parameters mean.

payload = {
    "msisdn": "256703######",  # The phone number that the transfer request is intended for.
    "amount": 20000,  #The transfer request amount.
    "external_reference": "157899393020236",  # Internal description or reason for this transfer request and must be unique for every request. 
    "narration":"Clearing Invoice - #157899393020236"  # Textual narrative describing the transaction. 
}

transfer = client.transfer(payload)
  1. get_transfers: Retrieve the transfer transactions for a given account.
transfers = client.get_transfers()
  1. get_transfer: Retrieve a certain tranfer transaction using the transaction reference
transfer = client.get_transfer(transaction_ref)
  1. get_transaction_status: The status of the transaction, this can be one of these; PENDING,SUCCEEDED,FAILED,INDETERMINATE
trans_status = client.get_transaction_status(transaction_ref)

Account

The account client can be created with configuration parameters as indicated above.

import os
from zengapay import Accounts


config = {
    ZENGAPAY_ENVIRONMENT: os.environ.get("ZENGAPAY_APP_SETTINGS", "sandbox"),
    ZENGAPAY_BASE_URL: os.environ.get("ZENGAPAY_BASE_URL", "https://api.sandbox.zengapay.com/v1"),
    ZENGAPAY_USER_API_TOKEN: os.environ.get("ZENGAPAY_USER_API_TOKEN")
}

client = Accounts(config)

See the API Documentation.

Methods

  1. get_balance: This API allows you to get the current merchant account balance.
balance = client.get_balance()
  1. get_account_statement: To retrieve a list of all transactions on your account (account statement). This will return a list of transactions. See API Documentation to see how to make filters.
statement = client.get_account_statement()

Performing a limit and status filters. See link above for more filters

statement = client.get_account_statement(limit=2, status='FAILED')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zengapay-0.2.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zengapay-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file zengapay-0.2.0.tar.gz.

File metadata

  • Download URL: zengapay-0.2.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.4

File hashes

Hashes for zengapay-0.2.0.tar.gz
Algorithm Hash digest
SHA256 870c7cf5628592d1acee21b67599b1f44953b774aae470c14f426fe00ea87d84
MD5 7b02b0231b34de204b07a6deda3167e9
BLAKE2b-256 5dfdb1fa7c2562ce4b0d8cedab1a4d1dfcd8a77efe655c1cc577dffca55d36b0

See more details on using hashes here.

File details

Details for the file zengapay-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: zengapay-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.4

File hashes

Hashes for zengapay-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27646fc3a04375dae68196e823bad6f929941549b037b02fbd3eb0f2f74232ac
MD5 fa594637ca72530cf9d6c391b8da61a5
BLAKE2b-256 bf90d25b66c0b2f7f6685c4686755fed383b5224b7cb7c6fc31c639c70d6e9ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page