public function request($method, $absUrl, $headers, $params, $hasFile) { $curl = curl_init(); $method = strtolower($method); $opts = array(); if ($method == 'get') { if ($hasFile) { throw new Error\Api("Issuing a GET request with a file parameter"); } $opts[CURLOPT_HTTPGET] = 1; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } elseif ($method == 'post') { $opts[CURLOPT_POST] = 1; $opts[CURLOPT_POSTFIELDS] = $hasFile ? $params : self::encode($params); } elseif ($method == 'delete') { $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } else { throw new Error\Api("Unrecognized method {$method}"); } $absUrl = Util\Util::utf8($absUrl); $opts[CURLOPT_URL] = $absUrl; $opts[CURLOPT_RETURNTRANSFER] = true; $opts[CURLOPT_CONNECTTIMEOUT] = 30; $opts[CURLOPT_TIMEOUT] = 80; $opts[CURLOPT_RETURNTRANSFER] = true; $opts[CURLOPT_HTTPHEADER] = $headers; if (!Payjp::$verifySslCerts) { $opts[CURLOPT_SSL_VERIFYPEER] = false; } curl_setopt_array($curl, $opts); $rbody = curl_exec($curl); if (!defined('CURLE_SSL_CACERT_BADFILE')) { define('CURLE_SSL_CACERT_BADFILE', 77); // constant not defined in PHP } $errno = curl_errno($curl); if ($errno == CURLE_SSL_CACERT || $errno == CURLE_SSL_PEER_CERTIFICATE || $errno == CURLE_SSL_CACERT_BADFILE) { array_push($headers, 'X-Payjp-Client-Info: {"ca":"using Payjp-supplied CA bundle"}'); $cert = self::caBundle(); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CAINFO, $cert); $rbody = curl_exec($curl); } if ($rbody === false) { $errno = curl_errno($curl); $message = curl_error($curl); curl_close($curl); $this->handleCurlError($absUrl, $errno, $message); } $rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); return array($rbody, $rcode); }
public function __toArray($recursive = false) { if ($recursive) { return Util\Util::convertPayjpObjectToArray($this->_values); } else { return $this->_values; } }