This is the official python SDK for the Transfa API.
Project description
Transfa Python SDK
The Transfa Python SDK provides methods and resources to the Transfa API for applications written in Python.
Documentation
You can check the Python API documentation for more details about the API.
Installation
Run the following command:
pip install --upgrade transfa
Requirements
- Python 3.8+
Usage
from transfa.api_client import client
client.api_key = "ak_test_..."
response = client.Payment.request_payment({
"account_alias": "60201010",
"amount": 5000,
"mode": "mtn-benin"
})
print(response.text)
Verify webhook
Before you respond to a Webhook request, you need first to verify that it is coming from Transfa.
from rest_framework.decorators import api_view
from rest_framework import status
from rest_framework.response import Response
from transfa.webhook import Webhook
# Do not save the secret key in plain text in your code, set it instead as an environment variable.
secret_key = 'ps_test:...'
@api_view(["POST"])
def webhook_endpoint(request):
body = request.data
# Will return True or False and the body of the request that has been slightly modified
# You should use that data when processing the webhook instead of the previous one
webhook = Webhook(webhook_token=secret_key, body=body, headers=request.headers)
verified = webhook.verify()
if verified is None:
return Response({"detail": "unauthorized"}, status=status.HTTP_401_UNAUTHORIZED)
# Process Webhook payload
# ...
# ...
return Response({"detail": True}, status=status.HTTP_200_OK)
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
transfa-0.2.0.tar.gz
(10.5 kB
view hashes)
Built Distribution
Close
Hashes for transfa-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8a58705731c71de70e7b9b4308e87f888a5bb549cb8389d5416980281ec9e5f |
|
MD5 | 6b4902f8894424c1cf614feb0d76e70d |
|
BLAKE2b-256 | 13e30fc349489cd49aeab3801b504ca21171c84521339e3c9aeaaf947c18fd44 |