Exemplo n.º 1
0
 /**
  * @return null|string The instance URL for this resource. It needs to be special
  *                     cased because it doesn't fit into the standard resource pattern.
  *
  * @throws Error\InvalidRequest
  */
 public function instanceUrl()
 {
     $id = $this['id'];
     if (!$id) {
         $class = get_class($this);
         $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}";
         throw new Error\InvalidRequest($msg, null);
     }
     if ($this['customer']) {
         $parent = $this['customer'];
         $base = Customer::classUrl();
         $path = 'sources';
     } elseif ($this['account']) {
         $parent = $this['account'];
         $base = Account::classUrl();
         $path = 'external_accounts';
     } elseif ($this['recipient']) {
         $parent = $this['recipient'];
         $base = Recipient::classUrl();
         $path = 'cards';
     } else {
         return;
     }
     $parent = Util\Util::utf8($parent);
     $id = Util\Util::utf8($id);
     $parentExtn = urlencode($parent);
     $extn = urlencode($id);
     return "{$base}/{$parentExtn}/{$path}/{$extn}";
 }
Exemplo n.º 2
0
 public function retrieve($id, $params = null, $opts = null)
 {
     list($url, $params) = $this->extractPathAndUpdateParams($params);
     $id = Util\Util::utf8($id);
     $extn = urlencode($id);
     list($response, $opts) = $this->_request('get', "{$url}/{$extn}", $params, $opts);
     return Util\Util::convertToStripeObject($response, $opts);
 }
Exemplo n.º 3
0
 /**
  * @return string The instance URL for this resource. It needs to be special
  *                cased because it doesn't fit into the standard resource pattern.
  */
 public function instanceUrl()
 {
     if ($result = parent::instanceUrl()) {
         return $result;
     }
     $id = $this['id'];
     $id = Util\Util::utf8($id);
     $extn = urlencode($id);
     $base = self::classUrl();
     return "{$base}/{$extn}";
 }
Exemplo n.º 4
0
 public function testUtf8()
 {
     // UTF-8 string
     $x = "é";
     $this->assertSame(Util\Util::utf8($x), $x);
     // Latin-1 string
     $x = "é";
     $this->assertSame(Util\Util::utf8($x), "é");
     // Not a string
     $x = true;
     $this->assertSame(Util\Util::utf8($x), $x);
 }
Exemplo n.º 5
0
 /**
  * @return string The instance endpoint URL for the given class.
  */
 public static function resourceUrl($id)
 {
     if ($id === null) {
         $class = get_called_class();
         $message = "Could not determine which URL to request: " . "{$class} instance has invalid ID: {$id}";
         throw new Error\InvalidRequest($message, null);
     }
     $id = Util\Util::utf8($id);
     $base = static::classUrl();
     $extn = urlencode($id);
     return "{$base}/{$extn}";
 }
Exemplo n.º 6
0
 /**
  * @return string The instance URL for this resource. It needs to be special
  *    cased because it doesn't fit into the standard resource pattern.
  */
 public function instanceUrl()
 {
     $result = parent::instanceUrl();
     if ($result) {
         return $result;
     } else {
         $id = $this['id'];
         $id = Util\Util::utf8($id);
         $extn = urlencode($id);
         $base = BitcoinReceiver::classUrl();
         return "{$base}/{$extn}";
     }
 }
Exemplo n.º 7
0
 /**
  * @return string The API URL for this Stripe transfer reversal.
  */
 public function instanceUrl()
 {
     $id = $this['id'];
     $transfer = $this['transfer'];
     if (!$id) {
         throw new Error\InvalidRequest("Could not determine which URL to request: " . "class instance has invalid ID: {$id}", null);
     }
     $id = Util\Util::utf8($id);
     $transfer = Util\Util::utf8($transfer);
     $base = Transfer::classUrl();
     $transferExtn = urlencode($transfer);
     $extn = urlencode($id);
     return "{$base}/{$transferExtn}/reversals/{$extn}";
 }
Exemplo n.º 8
0
 /**
  * @return string The API URL for this Pingpp refund.
  */
 public function instanceUrl()
 {
     $id = $this['id'];
     $charge = $this['charge'];
     if (!$id) {
         throw new Error\InvalidRequest("Could not determine which URL to request: " . "class instance has invalid ID: {$id}", null);
     }
     $id = Util\Util::utf8($id);
     $charge = Util\Util::utf8($charge);
     $base = Charge::classUrl();
     $chargeExtn = urlencode($charge);
     $extn = urlencode($id);
     return "{$base}/{$chargeExtn}/refunds/{$extn}";
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function instanceUrl()
 {
     $id = $this['id'];
     $customer = $this['customer'];
     if (!$id) {
         throw new Error\InvalidRequest('Could not determine which URL to request: ' . "class instance has invalid ID: {$id}", null);
     }
     $id = Util\Util::utf8($id);
     $customer = Util\Util::utf8($customer);
     $base = Customer::classUrl();
     $customerExtn = urlencode($customer);
     $extn = urlencode($id);
     return "{$base}/{$customerExtn}/subscriptions/{$extn}";
 }
Exemplo n.º 10
0
 private static function _encodeObjects($d)
 {
     if ($d instanceof ApiResource) {
         return Util\Util::utf8($d->id);
     } elseif ($d === true) {
         return 'true';
     } elseif ($d === false) {
         return 'false';
     } elseif (is_array($d)) {
         $res = array();
         foreach ($d as $k => $v) {
             $res[$k] = self::_encodeObjects($v);
         }
         return $res;
     } else {
         return Util\Util::utf8($d);
     }
 }
Exemplo n.º 11
0
 /**
  * @return string The instance URL for this resource. It needs to be special
  *    cased because it doesn't fit into the standard resource pattern.
  */
 public function instanceUrl()
 {
     $id = $this['id'];
     if (!$id) {
         $class = get_class($this);
         $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}";
         throw new Error\InvalidRequest($msg, null);
     }
     $id = Util\Util::utf8($id);
     $extn = urlencode($id);
     if (!$this['customer']) {
         $base = BitcoinReceiver::classUrl();
         return "{$base}/{$extn}";
     } else {
         $base = Customer::classUrl();
         $parent = Util\Util::utf8($this['customer']);
         $parentExtn = urlencode($parent);
         return "{$base}/{$parentExtn}/sources/{$extn}";
     }
 }
Exemplo n.º 12
0
 private function _curlRequest($method, $absUrl, $headers, $params)
 {
     $curl = curl_init();
     $method = strtolower($method);
     $opts = array();
     $requestSignature = NULL;
     if ($method == 'get') {
         $opts[CURLOPT_HTTPGET] = 1;
         if (count($params) > 0) {
             $encoded = self::encode($params);
             $absUrl = "{$absUrl}?{$encoded}";
         }
     } elseif ($method == 'post' || $method == 'put') {
         if ($method == 'post') {
             $opts[CURLOPT_POST] = 1;
         } else {
             $opts[CURLOPT_CUSTOMREQUEST] = 'PUT';
         }
         $rawRequestBody = json_encode($params);
         $opts[CURLOPT_POSTFIELDS] = $rawRequestBody;
         if ($this->privateKey()) {
             $signResult = openssl_sign($rawRequestBody, $requestSignature, $this->privateKey(), 'sha256');
             if (!$signResult) {
                 throw new Error\Api("Generate signature failed");
             }
         }
     } 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}");
     }
     if ($requestSignature) {
         $headers[] = 'Pingplusplus-Signature: ' . base64_encode($requestSignature);
     }
     $absUrl = Util\Util::utf8($absUrl);
     $opts[CURLOPT_URL] = $absUrl;
     $opts[CURLOPT_RETURNTRANSFER] = true;
     $opts[CURLOPT_CONNECTTIMEOUT] = 30;
     $opts[CURLOPT_TIMEOUT] = 80;
     $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);
 }