Install
pip install qashx
Initialise
import os
from qashx import QashX
client = QashX(
api_key=os.environ["QASHX_API_KEY"],
env="sandbox", # "sandbox" | "live"
timeout=15,
max_retries=3,
)
Payments
import uuid
payment = client.payments.create(
amount=1500,
currency="EUR",
capability="card_payment",
customer={"email": "buyer@example.com"},
idempotency_key=str(uuid.uuid4()),
)
client.payments.retrieve("pay_...")
client.payments.list(limit=20)
client.payments.refund("pay_...", amount=500)
client.payments.cancel("pay_...")
Async
from qashx import AsyncQashX
async with AsyncQashX(api_key=...) as client:
payment = await client.payments.create(amount=1500, currency="EUR",
capability="card_payment")
Webhooks
from qashx.webhooks import verify
@app.post("/webhook")
async def handler(request):
event = verify(
payload=await request.body(),
signature=request.headers["x-qashx-signature"],
secret=os.environ["QASHX_WEBHOOK_SECRET"],
)
return {"ok": True}
Errors
from qashx import QashXError, RateLimitError
try:
client.payments.create(...)
except RateLimitError as e:
time.sleep(e.retry_after)
except QashXError as e:
print(e.type, e.code, e.request_id)
Type hints
Models are dataclasses. Import them from qashx.models:
from qashx.models import Payment, PaymentStatus, Refund