ZENGAPAY is a Payments Gateway service that enables businesses to receive payments from their customers via mobile money, as well as make mobile money payments to any mobile money account holder or purchase Mobile Airtime or Mobile Data.
This is the ZENGAPAY Python Client Library
Add the latest version of the library to your project by using pip:
$ pip install zengapay
This library supports Python 3.6+
Before using the library in your applications, please head over to our 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
And Here is the API Endpoint for our production environment:
https://api.zengapay.com/v1
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 needed for each API Request you will be performing.
The collections client can be created with configuration parameters as indicated below.
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)
- collect: This operation is used to request a payment from customer (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)
orget_transaction_status(transaction_ref)
using thetransaction 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)
- get_collections: Retrieve the collection transactions for a given account.
collections = client.get_collections()
- get_collection: Retrieve a certain collection transaction using the
transaction reference
collection = client.get_collection(transaction_ref)
- 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)
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)
- 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)
orget_transaction_status(transaction_ref)
using thetransaction 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)
- get_transfers: Retrieve the transfer transactions for a given account.
transfers = client.get_transfers()
- get_transfer: Retrieve a certain tranfer transaction using the
transaction reference
transfer = client.get_transfer(transaction_ref)
- 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)
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.
- get_balance: This API allows you to get the current merchant account balance.
balance = client.get_balance()
- 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')