public function retrieve($id, $params = null) { list($url, $params) = $this->extractPathAndUpdateParams($params); $requestor = new Divido_ApiRequestor($this->_apiKey); $id = Divido_ApiRequestor::utf8($id); $extn = urlencode($id); list($response, $apiKey) = $requestor->request('get', "{$url}/{$extn}", $params); return Divido_Util::convertToDividoObject($response, $apiKey); }
private function _curlRequest($method, $absUrl, $headers, $params) { if (!self::$_preFlight) { self::$_preFlight = $this->checkSslCert($this->apiUrl()); } $myApiKey = $this->_apiKey; if (!$myApiKey) { $myApiKey = Divido::$apiKey; } if (!isset($params['merchant'])) { $params['merchant'] = $myApiKey; } $curl = curl_init(); $method = strtolower($method); $opts = array(); if ($method == 'get') { $opts[CURLOPT_HTTPGET] = 1; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } else { if ($method == 'post') { $opts[CURLOPT_POST] = 1; //$opts[CURLOPT_POSTFIELDS] = self::encode($params); $opts[CURLOPT_POSTFIELDS] = http_build_query($params); } else { if ($method == 'delete') { $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } else { throw new Divido_ApiError("Unrecognized method {$method}"); } } } $absUrl = self::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 (!Divido::$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-Divido-Client-Info: {"ca":"using Divido-supplied CA bundle"}'); $cert = $this->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($errno, $message); } $rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); return array($rbody, $rcode); }
protected function _scopedDelete($class, $params = null) { self::_validateCall('delete'); $requestor = new Divido_ApiRequestor($this->_apiKey); $url = $this->instanceUrl(); list($response, $apiKey) = $requestor->request('delete', $url, $params); $this->refreshFrom($response, $apiKey); return $this; }