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.1.tar.gz (5.6 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.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zarpay-1.0.1.tar.gz
  • Upload date:
  • Size: 5.6 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.1.tar.gz
Algorithm Hash digest
SHA256 b4ae58c7775035de878041f816961089342e356b38c1def6a671e550900ff786
MD5 bb3da129acc22d734643bd7c0656fcbc
BLAKE2b-256 e1155cad0d40ec21c5cc87d81e1ae660137250e915fc84f44b2efb30f50d0e09

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zarpay-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dab453d9ff5b7def86a9a2f027696977e83b8c70c4790d24424e78e8d51e144e
MD5 de4c55e2e7b1522e6d1f5e90f1a3ccdc
BLAKE2b-256 45c39e5f8b64c5881e7a8b7202c6de20dfa2f1302d1b840e4847afbb0ef97463

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