Skip to main content

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"])
print(payment["data"]["payment_method_label"])

Payments

# 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",
)

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

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

Refunds

refund = client.refunds.create(
    zarpay_id="ZP_abc123def456",
    amount=500,
    reason="Customer requested refund",
)

print(refund["data"]["status"])  # 'pending' — requires admin approval

Balance

balance = client.balance.get()

print("Available:", balance["data"]["available"])
print("Settled:", balance["data"]["settled"])
print("Unsettled:", balance["data"]["unsettled"])
print("Pending:", balance["data"]["pending"])

Settlements

settlements = client.settlements.list(status="PAID", page=1, limit=10)

for s in settlements["data"]["settlements"]:
    print(f"#{s['id']}: PKR {s['net_amount']} ({s['status']})")

Channels

channels = client.channels.list()

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

Verify Webhooks

from zarpay import verify_webhook

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":
            pass  # Fulfill the order
        elif event["event"] == "refund.completed":
            pass  # Update order status
        elif event["event"] == "settlement.paid":
            pass  # Record settlement

        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:3550/api/v1",
    timeout=60,
)

API Reference

Resource Method Endpoint
payments.create() POST /payments
payments.get() GET /payments/:id
payments.get_by_order_id() GET /payments/by-order/:id
refunds.create() POST /refunds
balance.get() GET /balance
settlements.list() GET /settlements
channels.list() GET /channels
verify_webhook() — Verify webhook signature

License

MIT

Metadata

Release files for zarpay 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zarpay 1.1.0
File Size Uploaded Provenance Actions
zarpay-1.1.0.tar.gz 5.9 kB Without provenance Details for zarpay-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for zarpay 1.1.0
File Interpreter ABI Platform Actions
zarpay-1.1.0-py3-none-any.whl Python 3 none any Details for zarpay-1.1.0-py3-none-any.whl

Total release size: 12.3 kB

Release files / zarpay-1.1.0.tar.gz

Download URL zarpay-1.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7992976d3db83b4fb67617f78f90087e06a75380d27c90877beca39692828e53
BLAKE2b-256 checksum
How to use checksums
5dc8a0769ea00a52b63bb1fa645cb294cb654480b912e26a4ce8f767488f2da3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / zarpay-1.1.0-py3-none-any.whl

Download URL zarpay-1.1.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47b8c05e1ce7e86f9a5437f55aab7346f507efbf59c56468a3e1fbe258b1e82e
BLAKE2b-256 checksum
How to use checksums
54698eb0b1e26d9634ca3e25300d1c0cef32bcb7c39013cf6114a1c8850f45ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for zarpay 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page