/** * @return Stripe_Subscription The updated subscription. */ public function deleteDiscount() { $requestor = new M2_Stripe_ApiRequestor($this->_apiKey); $url = $this->instanceUrl() . '/discount'; list($response, $apiKey) = $requestor->request('delete', $url); $this->refreshFrom(array('discount' => null), $apiKey, true); }
/** * @param string|null $params * * @return Stripe_ApplicationFee The refunded application fee. */ public function refund($params = null) { $requestor = new M2_Stripe_ApiRequestor($this->_apiKey); $url = $this->instanceUrl() . '/refund'; list($response, $apiKey) = $requestor->request('post', $url, $params); $this->refreshFrom($response, $apiKey); return $this; }
/** * @return Stripe_Invoice The paid invoice. */ public function pay() { $requestor = new M2_Stripe_ApiRequestor($this->_apiKey); $url = $this->instanceUrl() . '/pay'; list($response, $apiKey) = $requestor->request('post', $url); $this->refreshFrom($response, $apiKey); return $this; }
public function retrieve($id, $params = null) { $requestor = new M2_Stripe_ApiRequestor($this->_apiKey); $base = $this['url']; $id = M2_Stripe_ApiRequestor::utf8($id); $extn = urlencode($id); list($response, $apiKey) = $requestor->request('get', "{$base}/{$extn}", $params); return M2_Stripe_Util::convertToStripeObject($response, $apiKey); }
/** * @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) { $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}"; throw new M2_Stripe_InvalidRequestError($msg, null); } if (isset($this['customer'])) { $parent = $this['customer']; $base = self::classUrl('M2_Stripe_Customer'); } else { if (isset($this['recipient'])) { $parent = $this['recipient']; $base = self::classUrl('M2_Stripe_Recipient'); } else { return null; } } $parent = M2_Stripe_ApiRequestor::utf8($parent); $class = get_class($this); $id = M2_Stripe_ApiRequestor::utf8($id); $parentExtn = urlencode($parent); $extn = urlencode($id); return "{$base}/{$parentExtn}/cards/{$extn}"; }
/** * @return string The API URL for this Stripe refund. */ public function instanceUrl() { $id = $this['id']; $charge = $this['charge']; if (!$id) { throw new M2_Stripe_InvalidRequestError("Could not determine which URL to request: " . "class instance has invalid ID: {$id}", null); } $id = M2_Stripe_ApiRequestor::utf8($id); $charge = M2_Stripe_ApiRequestor::utf8($charge); $base = self::classUrl('M2_Stripe_Charge'); $chargeExtn = urlencode($charge); $extn = urlencode($id); return "{$base}/{$chargeExtn}/refunds/{$extn}"; }
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] = self::encode($params); } else { if ($method == 'delete') { $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } else { throw new M2_Stripe_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 (!M2_Stripe::$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-Stripe-Client-Info: {"ca":"using Stripe-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 M2_Stripe_ApiRequestor($this->_apiKey); $url = $this->instanceUrl(); list($response, $apiKey) = $requestor->request('delete', $url, $params); $this->refreshFrom($response, $apiKey); return $this; }