$orderId, 'amount' => $amount, 'customer_ref' => (string)$userId]; if ($currency !== 'USDT') $body['currency'] = $currency; $ch = curl_init(GW_URL . '/v1/orders'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey, 'Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($body), ]); $res = json_decode(curl_exec($ch), true); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($code !== 201) { http_response_code(502); echo json_encode(['error' => $res['error'] ?? 'gateway']); exit; } $pdo = new PDO(getenv('DB_DSN'), getenv('DB_USER'), getenv('DB_PASS'), [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $pdo->prepare('INSERT INTO charges(order_id,user_id,gw_id,currency,amount,status) VALUES(?,?,?,?,?,?)') ->execute([$orderId, $userId, $res['id'], $res['currency'], $res['fiat_amount'] ?? $res['amount'], 'pending']); header('Content-Type: application/json'); echo json_encode(['id' => $res['id']]);