true, CURLOPT_POSTFIELDS => http_build_query($parameters), CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_HTTPHEADER => ['Accept: application/json'], ]); $body = curl_exec($handle); if ($body === false) { $message = curl_error($handle); curl_close($handle); throw new RuntimeException('API request failed: ' . $message); } curl_close($handle); $response = json_decode($body, true); if (!is_array($response)) { throw new RuntimeException('The API returned invalid JSON.'); } if (isset($response['error'])) { throw new RuntimeException((string) $response['error']); } return $response; } try { // 1. Get the current service list and select a service ID. $services = apiRequest($apiUrl, $apiKey, [ 'action' => 'services', ]); // 2. Place an order. Use a real service ID from the response above. $newOrder = apiRequest($apiUrl, $apiKey, [ 'action' => 'add', 'service' => 1, 'link' => 'https://www.example.com/profile', 'quantity' => 100, ]); // 3. Check the order later using the returned local order ID. $status = apiRequest($apiUrl, $apiKey, [ 'action' => 'status', 'order' => $newOrder['order'], ]); // 4. Read the reseller balance. $balance = apiRequest($apiUrl, $apiKey, [ 'action' => 'balance', ]); print_r([ 'services' => $services, 'order' => $newOrder, 'status' => $status, 'balance' => $balance, ]); } catch (Throwable $exception) { echo $exception->getMessage(); } /* * Refill example: * $refill = apiRequest($apiUrl, $apiKey, [ * 'action' => 'refill', * 'order' => 1242, * ]); * * Refill status example: * $refillStatus = apiRequest($apiUrl, $apiKey, [ * 'action' => 'refill_status', * 'refill' => $refill['refill'], * ]); * * Keep the API key on your server. Do not put it in browser JavaScript, * mobile app source code, public repositories, or user-facing URLs. */