Example #1
0
 public static function request($meth, $url, $env, $params, $headers)
 {
     $curl = curl_init();
     $opts = array();
     if ($meth == ChargeBee_Request::GET) {
         $opts[CURLOPT_HTTPGET] = 1;
         if (count($params) > 0) {
             $encoded = http_build_query($params, null, '&');
             $url = "{$url}?{$encoded}";
         }
     } else {
         if ($meth == ChargeBee_Request::POST) {
             $opts[CURLOPT_POST] = 1;
             $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
         } else {
             throw new Exception("Invalid http method {$meth}");
         }
     }
     $url = self::utf8($env->apiUrl($url));
     $opts[CURLOPT_URL] = $url;
     $opts[CURLOPT_RETURNTRANSFER] = true;
     $opts[CURLOPT_CONNECTTIMEOUT] = ChargeBee_Environment::$connectTimeout;
     $opts[CURLOPT_TIMEOUT] = ChargeBee_Environment::$timeout;
     $userAgent = "Chargebee-PHP-Client" . " v" . ChargeBee_Version::VERSION;
     $httpHeaders = self::addCustomHeaders($headers);
     array_push($httpHeaders, 'Accept: application/json', "User-Agent: " . $userAgent);
     // Adding headers to array
     $opts[CURLOPT_HTTPHEADER] = $httpHeaders;
     $opts[CURLOPT_USERPWD] = $env->getApiKey() . ':';
     if (ChargeBee::getVerifyCaCerts()) {
         $opts[CURLOPT_SSL_VERIFYPEER] = true;
         $opts[CURLOPT_SSL_VERIFYHOST] = 2;
         $opts[CURLOPT_CAINFO] = ChargeBee::getCaCertPath();
     }
     curl_setopt_array($curl, $opts);
     $response = curl_exec($curl);
     if ($response === false) {
         $errno = curl_errno($curl);
         $curlMsg = curl_error($curl);
         $message = "IO exception occurred when trying to connect to " . $url . " . Reason : " . $curlMsg;
         curl_close($curl);
         throw new ChargeBee_IOException($message, $errno);
     }
     $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     return array($response, $httpCode);
 }
Example #2
0
 public static function request($meth, $url, $env, $params)
 {
     $curl = curl_init();
     $opts = array();
     if ($meth == ChargeBee_Request::GET) {
         $opts[CURLOPT_HTTPGET] = 1;
         if (count($params) > 0) {
             $encoded = http_build_query($params, null, '&');
             $url = "{$url}?{$encoded}";
         }
     } else {
         if ($meth == ChargeBee_Request::POST) {
             $opts[CURLOPT_POST] = 1;
             $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
         } else {
             throw new ChargeBee_APIError("Invalid http method {$meth}");
         }
     }
     $url = self::utf8($env->apiUrl($url));
     $opts[CURLOPT_URL] = $url;
     $opts[CURLOPT_RETURNTRANSFER] = true;
     $opts[CURLOPT_CONNECTTIMEOUT] = 50;
     $opts[CURLOPT_TIMEOUT] = 100;
     $headers = array('Accept: application/json', "User-Agent: Chargebee-PHP-Client");
     $opts[CURLOPT_HTTPHEADER] = $headers;
     $opts[CURLOPT_USERPWD] = $env->getApiKey() . ':';
     if (ChargeBee::getVerifyCaCerts()) {
         $opts[CURLOPT_SSL_VERIFYPEER] = true;
         $opts[CURLOPT_SSL_VERIFYHOST] = 2;
         $opts[CURLOPT_CAINFO] = ChargeBee::getCaCertPath();
     }
     curl_setopt_array($curl, $opts);
     $response = curl_exec($curl);
     if ($response === false) {
         $errno = curl_errno($curl);
         $message = curl_error($curl);
         curl_close($curl);
         throw new ChargeBee_APIError($message, 0, $errno);
     }
     $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     return array($response, $httpCode);
 }
 public static function setVerifyCaCerts($verify)
 {
     self::$verifyCaCerts = $verify;
 }