Fully asynchronous crypto payments in FastAPI: a shared httpx.AsyncClient for the Moonvex API, a redirect to the checkout where the customer picks the coin, and a webhook that verifies the signature over the raw body and marks the order in PostgreSQL through asyncpg.
Step by step
1. Get an API key and a webhook secret
In the Moonvex dashboard go to “Integration” → “Create key” → type “Secret” (sk_live_…). The key is shown only once: store it on your server as MOONVEX_SECRET_KEY. On the same page add a webhook pointing to an https URL on your server and store its signing secret as MOONVEX_WEBHOOK_SECRET.
pip install fastapi uvicorn httpx asyncpg
export MOONVEX_SECRET_KEY = sk_live_... export MOONVEX_WEBHOOK_SECRET = whsec_... export DATABASE_URL = postgresql://user:pass@localhost:5432/shop
Enter fullscreen mode
Exit fullscreen mode
2. Create a checkout
The httpx client is created once in lifespan with the base URL and the Authorization header.…