Esempio n. 1
0
 public function retrieve($id, $params = null)
 {
     $requestor = new Pingpp_ApiRequestor($this->_apiKey);
     $base = $this['url'];
     $id = Pingpp_ApiRequestor::utf8($id);
     $extn = urlencode($id);
     list($response, $apiKey) = $requestor->request('get', "{$base}/{$extn}", $params);
     return Pingpp_Util::convertToPingppObject($response, $apiKey);
 }
Esempio n. 2
0
 /**
  * @return string The API URL for this Pingpp refund.
  */
 public function instanceUrl()
 {
     $id = $this['id'];
     $charge = $this['charge'];
     if (!$id) {
         throw new Pingpp_InvalidRequestError("Could not determine which URL to request: " . "class instance has invalid ID: {$id}", null);
     }
     $id = Pingpp_ApiRequestor::utf8($id);
     $charge = Pingpp_ApiRequestor::utf8($charge);
     $base = self::classUrl('Pingpp_Charge');
     $chargeExtn = urlencode($charge);
     $extn = urlencode($id);
     return "{$base}/{$chargeExtn}/refunds/{$extn}";
 }
Esempio n. 3
0
 protected function _scopedDelete($class, $params = null)
 {
     self::_validateCall('delete');
     $requestor = new Pingpp_ApiRequestor($this->_apiKey);
     $url = $this->instanceUrl();
     list($response, $apiKey) = $requestor->request('delete', $url, $params);
     $this->refreshFrom($response, $apiKey);
     return $this;
 }
Esempio n. 4
0
 private function _curlRequest($method, $absUrl, $headers, $params)
 {
     if (!self::$_preFlight) {
         self::$_preFlight = $this->checkSslCert($this->apiUrl());
     }
     $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] = json_encode($params);
         } else {
             if ($method == 'delete') {
                 $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
                 if (count($params) > 0) {
                     $encoded = self::encode($params);
                     $absUrl = "{$absUrl}?{$encoded}";
                 }
             } else {
                 throw new Pingpp_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 (!Pingpp::$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-Pingpp-Client-Info: {"ca":"using Pingpp-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);
 }