Skip to Content
SDKsPython

Python examples

All examples use the Inzi REST API directly. No SDK package required.


Create checkout (httpx)

import httpx INZI_KEY = "sk_live_..." async def create_checkout(amount: str, order_id: str) -> str: async with httpx.AsyncClient() as client: resp = await client.post( "https://api.inzilink.com/api/v1/checkouts", headers={"Authorization": f"Bearer {INZI_KEY}"}, json={ "amount": amount, "currency": "USD", "metadata": {"order_id": order_id}, "redirect_url": "https://yoursite.com/success", "webhook_url": "https://yoursite.com/webhooks/inzi", }, ) resp.raise_for_status() return resp.json()["checkout_url"]

Create checkout (requests)

import requests resp = requests.post( "https://api.inzilink.com/api/v1/checkouts", headers={"Authorization": f"Bearer {INZI_KEY}"}, json={ "amount": "25.00", "currency": "USD", "metadata": {"order_id": "ORD-123"}, }, ) checkout_url = resp.json()["checkout_url"]

Get checkout status

resp = httpx.get( f"https://api.inzilink.com/api/v1/checkouts/{checkout_id}", headers={"Authorization": f"Bearer {INZI_KEY}"}, ) status = resp.json()["status"] # pending | completed | expired

Verify webhook signature

import hmac, hashlib, time, json def verify_webhook(body: str, headers: dict, secret: str) -> dict: timestamp = headers["X-Inzi-Timestamp"] signature = headers["X-Inzi-Signature"].removeprefix("sha256=") signed_payload = f"{timestamp}.{body}" expected = hmac.new( secret.encode(), signed_payload.encode(), hashlib.sha256 ).hexdigest() if not hmac.compare_digest(expected, signature): raise ValueError("Invalid signature") if abs(time.time() - int(timestamp)) > 300: raise ValueError("Webhook too old") return json.loads(body)

Webhook handler (FastAPI)

from fastapi import FastAPI, Request, HTTPException app = FastAPI() @app.post("/webhooks/inzi") async def handle_webhook(request: Request): body = (await request.body()).decode() event = verify_webhook(body, dict(request.headers), WEBHOOK_SECRET) if event["event"] == "checkout.completed": order_id = event["data"]["metadata"]["order_id"] await mark_order_paid(order_id) return {"ok": True}