Skip to main content

Official Python SDK for the ZarPay payment gateway

Project description

ZarPay Python SDK

Official Python SDK for the ZarPay payment gateway.

Installation

pip install zarpay

Quick Start

from zarpay import ZarPay

client = ZarPay("sk_sandbox_xxxxxxxxxxxxx")

payment = client.payments.create(
    merchant_order_id="ORD-123",
    amount=1500,
    channel_id=1,
    customer_phone="03001234567",
)

print(payment["data"]["status"])  # 'completed' | 'processing' | 'failed'

Usage

List Available Channels

channels = client.channels.list()

for ch in channels["data"]["channels"]:
    print(f"{ch['id']}: {ch['wallet_type']}")

Create a Payment

payment = client.payments.create(
    merchant_order_id="ORD-456",
    amount=2500,
    channel_id=1,
    customer_phone="03001234567",
    metadata={"customer_name": "Ahmed Khan"},
    idempotency_key="unique-key-456",
)

if payment["success"]:
    print("Payment completed:", payment["data"]["zarpay_id"])
else:
    print("Payment failed:", payment["data"]["failure_reason"])

Get Payment Status

# By ZarPay ID
payment = client.payments.get("ZP_abc123def456")

# By your order ID
payment = client.payments.get_by_order_id("ORD-456")

Verify Webhooks

from zarpay import verify_webhook

# In your webhook handler (e.g. Flask/Django)
def webhook_handler(request):
    try:
        event = verify_webhook(
            raw_body=request.body,
            signature_header=request.headers["X-ZarPay-Signature"],
            secret="whsec_your_webhook_secret",
        )

        if event["event"] == "payment.completed":
            # Fulfill the order
            pass
        elif event["event"] == "payment.failed":
            # Notify customer
            pass

        return HttpResponse(status=200)
    except ValueError:
        return HttpResponse(status=400)

Error Handling

from zarpay import ZarPay, ZarPayAPIError

try:
    payment = client.payments.create(...)
except ZarPayAPIError as e:
    print(e.status_code)  # 400, 401, 409, etc.
    print(e.error)        # Human-readable error message

Configuration

client = ZarPay(
    "sk_sandbox_xxx",
    base_url="http://localhost:3000/api/v1",  # local development
    timeout=60,                                # seconds
)

License

MIT

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

zarpay-1.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

zarpay-1.0.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file zarpay-1.0.0.tar.gz.

File metadata

  • Download URL: zarpay-1.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for zarpay-1.0.0.tar.gz
Algorithm Hash digest
SHA256 19f425d046a51079abb96c5fe7e5083aa999cbf2f183cc227aa588b4f50b0c93
MD5 7077e0d7a546f6760b3944c363182271
BLAKE2b-256 6610ccf3e8d96727f563ac207d99dc6fb2af941ec730989214ec0467d9f01ae3

See more details on using hashes here.

File details

Details for the file zarpay-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zarpay-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for zarpay-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da70d7d73a5699a819b1abb281043f683f6d500eb37572eb5b5edf8c8c3f9fce
MD5 42dd37b78eae2d85c2ea00b2d2094f49
BLAKE2b-256 939c4fd2a6e0705fd469e45ceb33a9afd2880b369f9ffac43b430df4d733619a

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