url = $url; $this->request = $request; $this->headers = $headers; $this->body = $body; $this->isReturnable = $isReturnable; } /** * @throws GenericErrorException */ public function makeRequest(): string { $curl = curl_init(); $this->setCurlBody($curl); $response = curl_exec($curl); if(!$response){ throw new GenericErrorException(); } if(curl_errno($curl)){ echo curl_error($curl); die; } curl_close($curl); return $response; } public function setCurlBody(CurlHandle &$curl): void { curl_setopt($curl, CURLOPT_URL, $this->url); curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->request); curl_setopt($curl, CURLOPT_RETURNTRANSFER, $this->isReturnable); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl,CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($this->body)); } }