Official Python SDK for CtechPay hosted payments, Airtel Money, and card status checks.
Project description
CtechPay Python SDK
Official Python SDK for integrating CtechPay payments in Python applications.
Use this package from your server. Your CtechPay service token must never be exposed in browser JavaScript, mobile apps, or public repositories.
Installation
pip install ctechpay
Basic Usage
from ctechpay import CtechPay
ctechpay = CtechPay.client("YOUR_SERVICE_TOKEN")
You can also configure the API base URL and request timeout:
ctechpay = CtechPay.client(
"YOUR_SERVICE_TOKEN",
base_url="https://new-api.ctechpay.com",
timeout=30,
)
Hosted Payment Page
Hosted checkout is the recommended integration for most merchants. CtechPay gives you a secure payment page where the customer can choose Airtel Money or card.
payment = ctechpay.hosted_payments.create({
"amount": 100,
"customer_reference": "INV-1001",
"customer_message": "Invoice payment",
"customer_name": "Jane Doe",
"customer_email": "jane@example.com",
"redirectUrl": "https://example.com/payments/success",
"cancelUrl": "https://example.com/payments/cancelled",
})
print(payment["data"]["hosted_payment_url"])
Redirect your customer to payment["data"]["hosted_payment_url"].
Hosted Redirect Reference
When a hosted payment completes successfully, CtechPay redirects the customer to your redirectUrl with a reference query parameter.
https://example.com/payments/success?reference=TRANSACTION_OR_ORDER_REFERENCE
Use the reference to check the final payment status.
For card payments, the reference is the card order reference:
status = ctechpay.cards.status(reference)
For Airtel Money hosted payments, the reference is the Airtel transaction ID:
details = ctechpay.airtel.details(reference)
Airtel Money
Initiate Payment
payment = ctechpay.airtel.pay({
"amount": 100,
"phone": "0999123456",
"customer_reference": "INV-1001",
"customer_message": "Invoice payment",
})
transaction_id = payment["data"]["transaction"]["id"]
Check Airtel Status
Use the transaction ID returned when initiating payment.
status = ctechpay.airtel.status(transaction_id)
Get Airtel Transaction Details
details = ctechpay.airtel.details(transaction_id)
Find CtechPay Transaction By Airtel Money ID
reference = ctechpay.airtel.reference("AIRTEL_MONEY_ID")
Card Hosted Bank Page
This creates the Standard Bank hosted card checkout page.
order = ctechpay.cards.create_payment_page({
"amount": 100,
"merchantAttributes": True,
"redirectUrl": "https://example.com/payments/success",
"cancelUrl": "https://example.com/payments/cancelled",
"customer_reference": "INV-1001",
"customer_message": "Invoice payment",
})
print(order["payment_page_URL"])
Check Card Order Status
status = ctechpay.cards.status(order["order_reference"])
Flask Example
from flask import Flask, redirect, request, jsonify
from ctechpay import CtechPay
app = Flask(__name__)
ctechpay = CtechPay.client("YOUR_SERVICE_TOKEN")
@app.post("/pay")
def pay():
payment = ctechpay.hosted_payments.create({
"amount": 100,
"customer_reference": "ORDER-1001",
"redirectUrl": "https://example.com/payments/success",
"cancelUrl": "https://example.com/payments/cancelled",
})
return redirect(payment["data"]["hosted_payment_url"])
@app.get("/payments/success")
def payment_success():
reference = request.args.get("reference")
status = ctechpay.cards.status(reference)
return jsonify(status)
Error Handling
The SDK throws CtechPayError for failed requests.
from ctechpay import CtechPayError
try:
payment = ctechpay.hosted_payments.create({
"amount": 100,
})
except CtechPayError as error:
print(error)
print(error.status_code)
print(error.response)
Security Notes
This SDK intentionally does not expose direct card PAN/CVV helpers. Use the CtechPay Hosted Payment Page for card collection unless your integration is formally approved for card-data handling.
Do not disable SSL verification in production.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ctechpay-0.1.0.tar.gz.
File metadata
- Download URL: ctechpay-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1345629059c2975f9f6377f45ff9c9ddf4be94e47dde8d5ed8f8a0ea3174c3c
|
|
| MD5 |
e48069317177fcdef4520b149f5d0f59
|
|
| BLAKE2b-256 |
4c79b438a77d989408692a98f8be9ef703398ff22d2cc61a9de98543c4dad664
|
File details
Details for the file ctechpay-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ctechpay-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc4c3f49b719f4645fed089bf6c6026f83b17ed3bed71f6414f1c0cf5833ebb0
|
|
| MD5 |
b3c8eedc6aad6e0a6d1fdd4cedbf0ef0
|
|
| BLAKE2b-256 |
175a9e2fe0ac20b602e2fe5ded052cb35a16b5c19ee87e08578a2eee7420434e
|