url); curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(['key'=>$this->key,'action'=>$action]+$params), CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>10, CURLOPT_TIMEOUT=>45, CURLOPT_FOLLOWLOCATION=>false, CURLOPT_SSL_VERIFYPEER=>true, CURLOPT_SSL_VERIFYHOST=>2, CURLOPT_HTTPHEADER=>['Accept: application/json','Content-Type: application/x-www-form-urlencoded']]); try { $raw = curl_exec($ch); if ($raw === false) throw new RuntimeException('Connection failed; for add retries reuse the original request ID.'); $code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); if ($code < 200 || $code >= 300) throw new RuntimeException('HTTP error '.$code); $data = json_decode($raw,true,512,JSON_THROW_ON_ERROR); if (!is_array($data)) throw new RuntimeException('Unexpected API response.'); if (isset($data['error'])) throw new RuntimeException((string)$data['error']); return $data; } finally { curl_close($ch); } } public function services(): array { return $this->call('services'); } public function balance(): array { return $this->call('balance'); } public function add(int $service,string $link,int $quantity,string $requestId, string $coupon=''): array { if (!preg_match('/^[A-Za-z0-9_-]{16,128}$/D',$requestId)) throw new InvalidArgumentException('Invalid request ID.'); if ($service<1 || $quantity<1 || trim($link)==='') throw new InvalidArgumentException('Invalid order input.'); return $this->call('add',['service'=>$service,'link'=>$link,'quantity'=>$quantity,'request_id'=>$requestId,'coupon'=>$coupon]); } public function status(int $order): array { return $this->call('status',['order'=>$order]); } public function statuses(array $orders): array { if (!$orders || count($orders)>100) throw new InvalidArgumentException('Provide 1 to 100 order IDs.'); foreach ($orders as $id) if (!is_int($id) || $id<1) throw new InvalidArgumentException('Invalid order ID.'); return $this->call('status',['orders'=>implode(',',$orders)]); } // Refill and cancel are intentionally unavailable in this API release. } // Usage (uncomment on your private server; never publish your key): // $api = new PrimeSocialApi(getenv('PRIME_API_URL') ?: 'https://praimaf.shop/api/v1', getenv('PRIME_API_KEY') ?: ''); // $balance = $api->balance(); // $services = $api->services(); // For add: generate and STORE a unique ID in your database BEFORE submitting. // $requestId = bin2hex(random_bytes(16)); // persist this ID for all retries // $order = $api->add(123, 'https://example.com/target', 100, $requestId); // $status = $api->status(12345); // $statuses = $api->statuses([12345,12346]);