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"])
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

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.1.0.tar.gz (5.9 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.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for zarpay-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7992976d3db83b4fb67617f78f90087e06a75380d27c90877beca39692828e53
MD5 b070ae6ad94c1eb21b4e6410b10824fe
BLAKE2b-256 5dc8a0769ea00a52b63bb1fa645cb294cb654480b912e26a4ce8f767488f2da3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zarpay-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47b8c05e1ce7e86f9a5437f55aab7346f507efbf59c56468a3e1fbe258b1e82e
MD5 74a085ea129715d00ed6de07c88c56f6
BLAKE2b-256 54698eb0b1e26d9634ca3e25300d1c0cef32bcb7c39013cf6114a1c8850f45ed

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