request(['action' => 'services']); } public function balance(): array { return $this->request(['action' => 'balance']); } public function addOrder(array $order): array { return $this->request(['action' => 'add'] + $order); } public function status(int $orderId): array { return $this->request(['action' => 'status', 'order' => $orderId]); } public function refill(int $orderId): array { return $this->request(['action' => 'refill', 'order' => $orderId]); } private function request(array $payload): array { $curl = curl_init($this->apiUrl); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(['key' => $this->apiKey] + $payload), CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => true, ]); $response = curl_exec($curl); if ($response === false) { throw new RuntimeException(curl_error($curl)); } curl_close($curl); $decoded = json_decode($response, true); if (!is_array($decoded)) { throw new RuntimeException('La API devolvió una respuesta inválida.'); } return $decoded; } } $api = new ApiClient(); $services = $api->services(); $balance = $api->balance(); $order = $api->addOrder([ 'service' => 1, 'link' => 'https://example.com/publicacion', 'quantity' => 100, ]); $status = $api->status((int) ($order['order'] ?? 0));