# QuataPay in PHP Plain HTTP, no QuataPay package; works with test and live keys. Secrets come from `QUATAPAY_API_KEY` and `QUATAPAY_WEBHOOK_SECRET`. ## Create a payment ```php true, CURLOPT_POST => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $key, 'Content-Type: application/json', 'Idempotency-Key: ' . $idempotencyKey, // one per checkout attempt, reused on retries ], CURLOPT_POSTFIELDS => json_encode([ 'amount' => $amountXaf, // integer XAF 'currency' => 'XAF', 'customer_reference' => $orderId, 'return_url' => 'https://your-site.example/pay/return?order=' . $orderId, 'cancel_url' => 'https://your-site.example/pay/cancel?order=' . $orderId, ]), ]); $body = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status < 200 || $status >= 300) { throw new RuntimeException("QuataPay $status " . ($body['code'] ?? '') . ': ' . ($body['error'] ?? '')); } return [$body['data']['checkout_url'], $body['data']['payment']['id']]; } ``` ## Verify a webhook ```php 300) return false; $expected = 'sha256=' . hash_hmac('sha256', $timestamp . '.' . $rawBody, $secret); return hash_equals($expected, $signature); } $raw = file_get_contents('php://input'); $ok = quatapayValidSignature( getenv('QUATAPAY_WEBHOOK_SECRET'), $raw, $_SERVER['HTTP_X_QUATAPAY_TIMESTAMP'] ?? null, $_SERVER['HTTP_X_QUATAPAY_SIGNATURE'] ?? null, ); if (!$ok) { http_response_code(400); exit; } // Then: insert (data.id, event) under a UNIQUE constraint; a duplicate means already handled, answer 200. ```