Official Python client for the EZBILL API. Collect payments in Pakistan over Raast: show a dynamic QR that any bank app, JazzCash or Easypaisa can scan, or send a Request-to-Pay to a payer's mobile number or IBAN.
- Python 3.9+, standard library only (
urllib), no dependencies. - Full API reference: https://ezbill.pk/developers/
pip install ezbillfrom ezbill import EzbillClient, EzbillError, is_paid
client = EzbillClient("ez_test_...") # ez_test_ = sandbox, ez_live_ = live; same host
# Amounts are integer paisa: Rs 1,500.00 = 150000
qr = client.create_qr(150000, reference="INV-1001", expiry_minutes=30)
print(qr["id"], qr["status"])
print(qr["qr_string"]) # render this string as a QR code
payment = client.get_payment(qr["id"])
if is_paid(payment["status"]): # PAID or SETTLED
print("paid")lookup = client.alias_inquiry("03001234567") # Raast mobile alias, 11 digits
# or: lookup = client.title_fetch("PK36SCBL0000001123456702")
rtp = client.create_rtp(lookup["rtp_id"], 150000, reference="INV-1002")
client.cancel(rtp["id"]) # while CREATED or SENTrtp_id can be used once; reusing it returns 409 rtp_id_used.
try:
client.create_qr(150000, reference="INV-1003")
except EzbillError as e:
print(e.status, e.code, e.retryable, e.correlation_id)
if e.retryable: # 503 = Raast / 1LINK outage; retry later
...client.status() (public, no key) tells you whether Raast is up.
Optional: client.create_token() exchanges the key for a 1-hour ezt_ access token, which you can pass to another EzbillClient as its key.
EZBILL sends events to {endpoint base URL}/onego-notification. If you set the base URL in the EZBILL portal to https://your-site.pk/ezbill, listen on /ezbill/onego-notification.
EZBILL POSTs signed events (payment.received, payment.settled, rtp.rejected, rtp.expired). Verify on the raw body:
from flask import Flask, request
from ezbill import verify_webhook, WebhookVerificationError
app = Flask(__name__)
SECRET = "your webhook secret"
@app.post("/ezbill/onego-notification")
def webhook():
try:
event = verify_webhook(request.get_data(), request.headers, SECRET) # tolerance=300 s
except WebhookVerificationError:
return "", 400
key = f'{event["event"]}:{event["correlation_id"]}' # idempotency key
if event["event"] in ("payment.received", "payment.settled"):
mark_order_paid(event["reference"], event["amount_minor"], key)
return "", 200python3 -m unittest discover -s tests -v- Website: https://ezbill.pk
- Developer docs: https://ezbill.pk/developers/
MIT