A minimalist python library that integrates with PesaPal's API 3.0 - JSON APIs (https://developer.pesapal.com/how-to-integrate/e-commerce/api-30-json/api-reference)
Project description
pesapal-py
A minimalist python library that integrates with PesaPal's API 3.0 - JSON APIs (https://developer.pesapal.com/how-to-integrate/e-commerce/api-30-json/api-reference).
This library abstracts PesaPals API 3.0 into four main methods, authenticate
, register_ipn
, transact
and get_transaction_status
Getting started
Register as a merchant
- Register as a PesaPal merchant at https://www.pesapal.com/
- On successfull registration, you will receive a consumer key and consumer secret via email - keep these safe as they are your API credentials
Install pesapal-py
pip install pesapal-py
Authenticating
from pesapal_py.payments import PesaPal
pesapal = PesaPal("test_consumer_key", "test_consumer_secret")
auth = pesapal.authenticate()
print(auth)
This step returns a bearer token that is used with all the other methods below. The token expires after every 5 minutes. To prevent calling this method every time you need to transact, I recommend that you store it in an in-memory data store (e.g. redis) and expire it before 5 minutes.
Register IPN
register_ipn = pesapal.register_ipn("sample_token", "https://www.sample-url.com/ipn")
print(register_ipn)
Transact
transact = pesapal.transact(
token="sample_token",
description="sample_description",
transaction_id="sample_transaction_id",
amount=1000,
callback_url="https://www.callback-url.com/status",
ipn_id="sample_ipn_id",
email_address="sample@email-address.com",
phone_number="254722001122",
country_code="KE",
first_name="first",
last_name="last",
currency="KES",
)
print(transact)
Validate Transaction
transaction_status = pesapal.get_transaction_status(
token="sample_token", order_tracking_id="sample_order_tracking_id"
)
print(transaction_status)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for pesapal_py-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40d8d64fb953999304ad6966d1c7f5b8af92ab9ba3f5e5939ecc3e316cef237a |
|
MD5 | bc9df0eb162bfe668ec1171a56ee5ece |
|
BLAKE2b-256 | 0ae6f74edca3b3661b00ca59fe288a3fbe0a4d617fb43eb623e483c2496ad594 |