Production-ready Python SDK for PAYEXA payment request, callback parsing, and verify flow with sync and async clients
Project description
PAYEXA Python SDK
Official Python SDK for the PAYEXA payment flow, including payment creation, callback parsing, and transaction verification.
The package provides a small, typed interface for integrating PAYEXA into synchronous and asynchronous Python applications.
Features
- Sync and async clients in a single package
- Input validation before any HTTP request is sent
- Clear separation between validation, transport, and API errors
- Typed result models for payment requests, callbacks, and verification
- Support for custom
requests.Sessionand injected async sessions
Requirements
- Python 3.10 or newer
Installation
Install the standard client:
pip install payexa
Install with async support:
pip install "payexa[async]"
Public API
from payexa import AsyncPayexaClient, PayexaClient
Use PayexaClient for standard synchronous applications and AsyncPayexaClient for async frameworks such as FastAPI.
Quick Start
from payexa import PayexaClient
with PayexaClient(
base_url="https://pay.pexn.ir",
api_key="YOUR_API_KEY",
default_merchant_id=1001,
) as client:
payment = client.request_payment(
amount=600000,
callback_url="https://merchant.example.com/payexa/callback",
meta={"order_ref": "INV-1001"},
)
print(payment.authority)
print(payment.order_id)
print(payment.amount_unique_token)
print(payment.start_pay_url)
Async Example
from payexa import AsyncPayexaClient
async def create_payment() -> None:
async with AsyncPayexaClient(
base_url="https://pay.pexn.ir",
api_key="YOUR_API_KEY",
default_merchant_id=1001,
) as client:
payment = await client.request_payment(
amount=600000,
callback_url="https://merchant.example.com/payexa/callback",
meta={"order_ref": "INV-1001"},
)
print(payment.authority)
print(payment.amount_unique_token)
Payment Flow
- Call
request_paymenton your backend. - Store
authority,order_id, andamount_uniquefrom the response. - Redirect the customer to
start_pay_url. - In the callback handler, call
parse_callbackfirst and thenverify_payment.
Example callback verification:
from payexa import PayexaAPIError, PayexaClient, PayexaValidationError
client = PayexaClient(
base_url="https://pay.pexn.ir",
api_key="YOUR_API_KEY",
)
callback = client.parse_callback(request.args)
if callback.is_ok:
try:
verification = client.verify_payment(
order_id=stored_order_id,
token=stored_amount_unique_token,
)
print(verification.status)
print(verification.merchant_verified)
except PayexaAPIError as exc:
print(exc.status_code, exc.message)
except PayexaValidationError as exc:
print(str(exc))
Error Model
PayexaValidationError: invalid client-side inputPayexaTransportError: network, timeout, or transport-level failurePayexaAPIError: PAYEXA returned an API error response
PayexaAPIError exposes these fields:
status_codemessagepayload
Notes
amountmust be a positive numeric valuecallback_urlmust be a validhttporhttpsURLmetamust be a mapping if providedamount_uniqueis stored asDecimalamount_unique_tokenis the recommended value for verification requests
Release
For maintainers, the release workflow is documented in RELEASE_CHECKLIST.md and covers validation, build, TestPyPI upload, and production publishing commands.
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 payexa-0.4.3.tar.gz.
File metadata
- Download URL: payexa-0.4.3.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
802a2c04e5379d456bf7cf6be226708b410e5cc30b4fb6e14d381577cd4309b3
|
|
| MD5 |
9f9265a07ff366349d722a8aff3820fd
|
|
| BLAKE2b-256 |
eaa92e549a099d35f7f77f8676c8e928cbfac2afc7f7ce8e9ab692f5ce057cd0
|
File details
Details for the file payexa-0.4.3-py3-none-any.whl.
File metadata
- Download URL: payexa-0.4.3-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd8c84f6eef3ae9d681aaae7cb22f24e6cd6f8cfe2413a3781fe9d65d9634047
|
|
| MD5 |
7e441c1c28d2477b3c51a975ae2e7e64
|
|
| BLAKE2b-256 |
baa957406762bd08f921da71bfb4f3e73adb3b7da5ff57150227db5317dfc7ad
|