--- name: quatapay-integration description: Integrate QuataPay payments (Cameroon, XAF, MTN Mobile Money, wallet, payment links) into a website or app: create a hosted-checkout payment, redirect the customer, receive and verify signed webhooks, test in the sandbox and go live. Use when the user mentions QuataPay, accepting payments in Cameroon or in XAF, MTN MoMo checkout, a QuataPay API key, payment link or webhook. --- # QuataPay integration QuataPay payments (Cameroon, XAF). Use these rules whenever the task touches QuataPay, a hosted checkout, payment links or payment webhooks. If something is not written here, ask the user or read https://quatapay.com/developer; never invent endpoints, fields or statuses. ## Before coding Ask the user: language and framework, checkout vs open amounts, where secrets live. Then write the integration, the webhook route and a test, and run the test. Mobile apps must call the merchant's own backend; never put a QuataPay key in an app, a browser bundle or git. ## Facts - Base URL (test and live): https://api.quatapay.com/api/v1. Header: Authorization: Bearer . Keys: qpay_test_... (test), qpay_live_... (live). Read the key from QUATAPAY_API_KEY, server side only. Webhook secret: QUATAPAY_WEBHOOK_SECRET. - Create: POST /gateway/sandbox/payments with a test key, POST /gateway/payments with a live key (wrong pairing is 403). Pick the path from the key prefix. HTTP 201, then redirect the browser to data.checkout_url; keep data.payment.id. - Body: amount (integer XAF, no decimals, no x100) and currency "XAF" are required. Optional: description, customer_reference (your order id), order_reference, return_url, cancel_url, failure_url (https), metadata, expires_in_minutes (1-1440, default 60), allowed_methods ["wallet","momo"]. Unknown fields are HTTP 422. - Send an Idempotency-Key header on creation: one key per checkout attempt, reused on retries (kept for good per merchant account on live keys, 24 h on test keys; same key with a different body is 409). - Response envelope: { success, data, error, code, details }. Errors: code VALIDATION_ERROR for 422, HTTP_ otherwise. Rate limit 60 requests per 60 seconds per API key and endpoint; 429 has Retry-After. - Read a payment: GET /gateway/payments/{payment_id} (sandbox: /gateway/sandbox/payments/{payment_id}), id not slug. status: requested, processing, succeeded, failed, cancelled, expired. Metadata is read back as metadata_json. - Redirects add no query parameters: put your own order id in return_url. Never mark an order paid from the redirect. - Mobile Money checkouts add a payer fee on top (currently 1.3%, shown to the customer before they confirm; read data.methods[].fee_note from GET /gateway/checkout/{slug}, do not hard-code or add it yourself). - Live today: pay from a QuataPay wallet, and MTN Mobile Money (no QuataPay account needed). Coming soon, do not build for them: Orange Money, bank transfer, international cards, and payouts to MoMo or Orange Money. ## Webhooks (the only thing that marks an order paid) - POST with JSON { event, data }. Headers X-QuataPay-Timestamp and X-QuataPay-Signature. - Verify first: expected = "sha256=" + hex(HMAC_SHA256(secret, timestamp + "." + RAW body)); constant-time compare; reject if |now - timestamp| > 300 s; answer 400 on failure. Use the raw bytes, never re-serialised JSON. - Events: gateway.payment.succeeded, gateway.payment.failed, gateway.payment.cancelled, gateway.payment.expired, gateway.payment.escrowed, gateway.payment.released. Fulfil on gateway.payment.succeeded only; it can arrive after expired. - Idempotent: insert (data.id, event) under a UNIQUE constraint, skip duplicates, check data.amount and data.customer_reference against your order, answer 2xx within 5 s. Retries: 5 attempts (1 minute, 5 minutes, 30 minutes, 2 hours). - Test vector: secret "test_secret_do_not_use", timestamp "1791370800", body {"data":{"amount":5000,"id":"pay-1"},"event":"gateway.payment.succeeded"} -> sha256=1c3a8d850ee6a783931573bb1066171269e25dcf1a8d9709ecb6bac778e3b121. ## Sandbox A test-mode checkout cannot be paid in a browser. Finish it with POST /gateway/sandbox/payments/{slug}/simulate (test key, body { "outcome": "succeeded" } or { "outcome": "failed" }, {slug} from creation); it sends the same webhooks with "simulated": true. The SDKs only call live paths, so use plain HTTP in the sandbox. Webhook endpoints must be public https (use a tunnel locally). ## Never Hard-code or log a key; use NEXT_PUBLIC_/VITE_/EXPO_PUBLIC_ for secrets; trust an amount from the browser; use floats; parse before verifying; retry 4xx; invent a refund endpoint (refunds are made in the merchant panel) or a WordPress plugin (none exists). Go live: set a live key and the production webhook secret only in production env, register the production https webhook URL, make one small real payment, confirm the order is paid exactly once. Full instructions with code for Node, Python, PHP, Ruby, Go, Java, C# and curl: https://quatapay.com/developer/master-prompt.txt ## Which integration - **Payment link.** You sell one thing or take open amounts and have no server (a social page, a WhatsApp shop, a static site). Create the link in the merchant panel under Payment links. Share https://quatapay.com/pay/{slug}. No code, no API key. - **Hosted checkout through the API (recommended for any site or app with a backend).** You have a server, an order or cart, and want to know automatically when it is paid. Your server calls POST /gateway/payments with an API key, redirects the customer to checkout_url, and fulfils the order from a signed webhook. - **Browser script (quatapay.js).** You already create payments on your server and want the hosted checkout in a popup instead of a full-page redirect. Your server still creates the payment. The page loads https://quatapay.com/quatapay.js and calls QuataPay.openCheckout({ slug }). Never put an API key in the page. - **SDK (Node or Python).** You want typed helpers for live payments and webhook verification. The SDKs only call the live path, so test keys do not work with them: use plain HTTP while you are in the sandbox. Source is in the Apps/sdk/ folder of the QuataPay repository. Plain HTTP works in every language and needs no package. ## References (read when needed) - `references/endpoints.md`: every endpoint, field, status and error. - `references/webhook-verification.md`: signature algorithm, test vector, events, payload, retries. - `examples/.md`: create a payment and verify a webhook in Node.js / TypeScript, Python, PHP, Ruby, Go, Java, C# / .NET, curl (any other language).