Skip to main content

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.Session and 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

  1. Call request_payment on your backend.
  2. Store authority, order_id, and amount_unique from the response.
  3. Redirect the customer to start_pay_url.
  4. In the callback handler, call parse_callback first and then verify_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 input
  • PayexaTransportError: network, timeout, or transport-level failure
  • PayexaAPIError: PAYEXA returned an API error response

PayexaAPIError exposes these fields:

  • status_code
  • message
  • payload

Notes

  • amount must be a positive numeric value
  • callback_url must be a valid http or https URL
  • meta must be a mapping if provided
  • amount_unique is stored as Decimal
  • amount_unique_token is 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

payexa-0.4.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

payexa-0.4.3-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

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

Hashes for payexa-0.4.3.tar.gz
Algorithm Hash digest
SHA256 802a2c04e5379d456bf7cf6be226708b410e5cc30b4fb6e14d381577cd4309b3
MD5 9f9265a07ff366349d722a8aff3820fd
BLAKE2b-256 eaa92e549a099d35f7f77f8676c8e928cbfac2afc7f7ce8e9ab692f5ce057cd0

See more details on using hashes here.

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

Hashes for payexa-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fd8c84f6eef3ae9d681aaae7cb22f24e6cd6f8cfe2413a3781fe9d65d9634047
MD5 7e441c1c28d2477b3c51a975ae2e7e64
BLAKE2b-256 baa957406762bd08f921da71bfb4f3e73adb3b7da5ff57150227db5317dfc7ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page