Server-side integration with the lyel-pay Python package
The Python SDK (lyel-pay) is designed for server-side environments. Use it from Django, Flask, FastAPI, Odoo, or any Python backend to create payment intents, retrieve their status, and validate incoming webhook events.
Custom key/value pairs. Returned on webhook events.
idempotency_key
str
❌
Safe-retry token. Auto-generated as a UUID4 if omitted.
Pass an explicit idempotency_key derived from a stable identifier (e.g. your
order ID) when the same logical operation may be retried — the API will
deduplicate so you never create a second intent for the same order.
client.payment_intents.retrieve(session_token)
Retrieve the current status of an intent using its session token.
Use retrieve() only as a fallback. For production, webhooks are the
authoritative source of truth — they keep state correct even when the
customer closes their browser mid-payment.
Validates an incoming webhook event and returns the parsed event. Raises ValueError if the signature is invalid or the timestamp is older than 5 minutes.
# Flask example — use request.get_data() to get the RAW bodyfrom flask import Flask, requestfrom lyel_pay import WebhookVerifierapp = Flask(__name__)verifier = WebhookVerifier()@app.post("/webhooks/lyelpay")def webhook(): payload = request.get_data() # raw bytes, NOT request.get_json() header = request.headers.get("Lyel-Signature", "") try: event = verifier.construct_event( payload=payload, header=header, secret="YOUR_WEBHOOK_SECRET", ) except ValueError as exc: return {"error": str(exc)}, 400 if event.type == "payment.completed": fulfill_order(event.data["paymentIntent"]) elif event.type == "payment.failed": notify_customer(event.data["paymentIntent"]) elif event.type == "payment.expired": cleanup_expired_order(event.data["paymentIntent"]) return {"received": True}, 200
Use the raw request body (e.g. request.get_data() in Flask, request.body
in Django, await request.body() in FastAPI). Re-serializing the parsed JSON
changes the byte order and breaks the HMAC check.
Signature format: the Lyel-Signature header carries
t=1716000000,v1=abc123def456...
t — Unix timestamp at emission
v1 — HMAC-SHA256 of "{t}.{payload}", keyed by your webhook secret
Webhook event types:
Type
Description
payment.completed
Payment was successfully processed
payment.failed
Payment attempt failed
payment.expired
Intent expired before completion
Error handling
API errors raise LyelPayError, which carries the HTTP status code:
from lyel_pay import LyelPay, LyelPayErrorclient = LyelPay(environment="sandbox")try: intent = client.payment_intents.create(amount="1500.00", currency="XAF")except LyelPayError as exc: if exc.status_code == 401: print("Invalid API key") elif exc.status_code == 422: print("Validation error:", exc) else: raise
The SDK retries automatically on 5xx responses and network errors — 3 attempts with exponential backoff (1s, 2s). 4xx errors are surfaced immediately without retry, because they will not succeed on retry.