protected function sendRequest($uri, $method, $data = null) { try { $url = new \http\Url("https://{$this->active_domain}.chargify.com{$uri}", null, \http\Url::PARSE_MBLOC | \http\Url::PARSE_MBUTF8 | \http\Url::PARSE_TOPCT); $request = new Request($method, $url); $request->setHeaders(array('Content-Type' => 'application/xml')); $request->setOptions(array('httpauth' => "{$this->active_api_key}:x", 'timeout' => 45, 'connecttimeout' => 45)); if ($data) { $request->getBody()->append($data); } } catch (Exception $e) { //TODO: throw $e; } $response = (new \http\Client())->enqueue($request)->send()->getResponse($request); return $response; }
protected function sendRequest($uri, $method, $data = null) { try { $url = new \http\Url("https://{$this->domain}.chargify.com{$uri}", null, \http\Url::PARSE_MBLOC | \http\Url::PARSE_MBUTF8 | \http\Url::PARSE_TOPCT); $request = new Request($method, $url); $request->setHeaders(array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . base64_encode("{$this->apiKey}:x"))); $request->setOptions(array('httpauth' => "{$this->apiKey}:x", 'timeout' => 45, 'connecttimeout' => 45, 'ssl' => array('version' => 6))); $request->getBody()->append($data); } catch (Exception $e) { throw $e; } $response = (new \http\Client())->enqueue($request)->send()->getResponse($request); if ($response->getResponseCode() == 500) { throw new Exception("Unable to proceed your request at the moment. Please try again later."); } if ($response->getResponseCode() == 404) { throw new Exception("Unable to proceed your request. Please contact billing@scalr.net to get help."); } return $response; }