forked from stripe/stripe-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All classes in Stripe namespace Use psr-4 autoloading in composer
- Loading branch information
Showing
70 changed files
with
600 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class ApiConnectionError extends Error | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class ApiError extends Error | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?php | ||
|
||
class Stripe_ApiRequestor | ||
namespace Stripe; | ||
|
||
class ApiRequestor | ||
{ | ||
private $_apiKey; | ||
|
||
|
@@ -40,7 +42,7 @@ public static function utf8($value) | |
|
||
private static function _encodeObjects($d) | ||
{ | ||
if ($d instanceof Stripe_ApiResource) { | ||
if ($d instanceof ApiResource) { | ||
return self::utf8($d->id); | ||
} else if ($d === true) { | ||
return 'true'; | ||
|
@@ -105,25 +107,24 @@ public function request($method, $url, $params=null) | |
return array($resp, $myApiKey); | ||
} | ||
|
||
|
||
/** | ||
* @param string $rbody A JSON string. | ||
* @param int $rcode | ||
* @param array $resp | ||
* | ||
* @throws Stripe_InvalidRequestError if the error is caused by the user. | ||
* @throws Stripe_AuthenticationError if the error is caused by a lack of | ||
* @throws InvalidRequestError if the error is caused by the user. | ||
* @throws AuthenticationError if the error is caused by a lack of | ||
* permissions. | ||
* @throws Stripe_CardError if the error is the error code is 402 (payment | ||
* @throws CardError if the error is the error code is 402 (payment | ||
* required) | ||
* @throws Stripe_ApiError otherwise. | ||
* @throws ApiError otherwise. | ||
*/ | ||
public function handleApiError($rbody, $rcode, $resp) | ||
{ | ||
if (!is_array($resp) || !isset($resp['error'])) { | ||
$msg = "Invalid response object from API: $rbody " | ||
."(HTTP response code was $rcode)"; | ||
throw new Stripe_ApiError($msg, $rcode, $rbody, $resp); | ||
throw new ApiError($msg, $rcode, $rbody, $resp); | ||
} | ||
|
||
$error = $resp['error']; | ||
|
@@ -134,20 +135,20 @@ public function handleApiError($rbody, $rcode, $resp) | |
switch ($rcode) { | ||
case 400: | ||
if ($code == 'rate_limit') { | ||
throw new Stripe_RateLimitError( | ||
throw new RateLimitError( | ||
$msg, $param, $rcode, $rbody, $resp | ||
); | ||
} | ||
case 404: | ||
throw new Stripe_InvalidRequestError( | ||
throw new InvalidRequestError( | ||
$msg, $param, $rcode, $rbody, $resp | ||
); | ||
case 401: | ||
throw new Stripe_AuthenticationError($msg, $rcode, $rbody, $resp); | ||
throw new AuthenticationError($msg, $rcode, $rbody, $resp); | ||
case 402: | ||
throw new Stripe_CardError($msg, $param, $code, $rcode, $rbody, $resp); | ||
throw new CardError($msg, $param, $code, $rcode, $rbody, $resp); | ||
default: | ||
throw new Stripe_ApiError($msg, $rcode, $rbody, $resp); | ||
throw new ApiError($msg, $rcode, $rbody, $resp); | ||
} | ||
} | ||
|
||
|
@@ -168,7 +169,7 @@ private function _requestRaw($method, $url, $params) | |
. '"Stripe::setApiKey(<API-KEY>)". You can generate API keys from ' | ||
. 'the Stripe web interface. See https://stripe.com/api for ' | ||
. 'details, or email [email protected] if you have any questions.'; | ||
throw new Stripe_AuthenticationError($msg); | ||
throw new AuthenticationError($msg); | ||
} | ||
|
||
$absUrl = $this->_apiBase.$url; | ||
|
@@ -191,12 +192,12 @@ private function _requestRaw($method, $url, $params) | |
$headers[] = 'Stripe-Version: ' . Stripe::$apiVersion; | ||
} | ||
$hasFile = false; | ||
$hasCurlFile = class_exists('CURLFile'); | ||
$hasCurlFile = class_exists('\CURLFile'); | ||
foreach ($params as $k => $v) { | ||
if (is_resource($v)) { | ||
$hasFile = true; | ||
$params[$k] = self::_processResourceParam($v); | ||
} else if ($hasCurlFile && $v instanceof CURLFile) { | ||
} else if ($hasCurlFile && $v instanceof \CURLFile) { | ||
$hasFile = true; | ||
} | ||
} | ||
|
@@ -220,21 +221,21 @@ private function _requestRaw($method, $url, $params) | |
private function _processResourceParam($resource) | ||
{ | ||
if (get_resource_type($resource) !== 'stream') { | ||
throw new Stripe_ApiError( | ||
throw new ApiError( | ||
'Attempted to upload a resource that is not a stream' | ||
); | ||
} | ||
|
||
$metaData = stream_get_meta_data($resource); | ||
if ($metaData['wrapper_type'] !== 'plainfile') { | ||
throw new Stripe_ApiError( | ||
throw new ApiError( | ||
'Only plainfile resource streams are supported' | ||
); | ||
} | ||
|
||
if (class_exists('CURLFile')) { | ||
if (class_exists('\CURLFile')) { | ||
// We don't have the filename or mimetype, but the API doesn't care | ||
return new CURLFile($metaData['uri']); | ||
return new \CURLFile($metaData['uri']); | ||
} else { | ||
return '@'.$metaData['uri']; | ||
} | ||
|
@@ -247,7 +248,7 @@ private function _interpretResponse($rbody, $rcode) | |
} catch (Exception $e) { | ||
$msg = "Invalid response body from API: $rbody " | ||
. "(HTTP response code was $rcode)"; | ||
throw new Stripe_ApiError($msg, $rcode, $rbody); | ||
throw new ApiError($msg, $rcode, $rbody); | ||
} | ||
|
||
if ($rcode < 200 || $rcode >= 300) { | ||
|
@@ -263,7 +264,7 @@ private function _curlRequest($method, $absUrl, $headers, $params, $hasFile) | |
$opts = array(); | ||
if ($method == 'get') { | ||
if ($hasFile) { | ||
throw new Stripe_ApiError( | ||
throw new ApiError( | ||
"Issuing a GET request with a file parameter" | ||
); | ||
} | ||
|
@@ -282,7 +283,7 @@ private function _curlRequest($method, $absUrl, $headers, $params, $hasFile) | |
$absUrl = "$absUrl?$encoded"; | ||
} | ||
} else { | ||
throw new Stripe_ApiError("Unrecognized method $method"); | ||
throw new ApiError("Unrecognized method $method"); | ||
} | ||
|
||
$absUrl = self::utf8($absUrl); | ||
|
@@ -331,7 +332,7 @@ private function _curlRequest($method, $absUrl, $headers, $params, $hasFile) | |
/** | ||
* @param number $errno | ||
* @param string $message | ||
* @throws Stripe_ApiConnectionError | ||
* @throws ApiConnectionError | ||
*/ | ||
public function handleCurlError($errno, $message) | ||
{ | ||
|
@@ -359,7 +360,7 @@ public function handleCurlError($errno, $message) | |
$msg .= " let us know at [email protected]."; | ||
|
||
$msg .= "\n\n(Network error [errno $errno]: $message)"; | ||
throw new Stripe_ApiConnectionError($msg); | ||
throw new ApiConnectionError($msg); | ||
} | ||
|
||
/** | ||
|
@@ -399,7 +400,7 @@ private function checkSslCert($url) | |
$url, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $sslContext | ||
); | ||
if (($errno !== 0 && $errno !== NULL) || $result === false) { | ||
throw new Stripe_ApiConnectionError( | ||
throw new ApiConnectionError( | ||
'Could not connect to Stripe (' . $url . '). Please check your '. | ||
'internet connection and try again. If this problem persists, '. | ||
'you should check Stripe\'s service status at '. | ||
|
@@ -414,7 +415,7 @@ private function checkSslCert($url) | |
openssl_x509_export($cert, $pemCert); | ||
|
||
if (self::isBlackListed($pemCert)) { | ||
throw new Stripe_ApiConnectionError( | ||
throw new ApiConnectionError( | ||
'Invalid server certificate. You tried to connect to a server that '. | ||
'has a revoked SSL certificate, which means we cannot securely send '. | ||
'data to that server. Please email [email protected] if you need '. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.