OAuth
6 years ago
Api.php
6 years ago
ApiConnection.php
6 years ago
Authentication.php
6 years ago
Base.php
6 years ago
Card.php
6 years ago
Idempotency.php
6 years ago
InvalidRequest.php
6 years ago
Permission.php
6 years ago
RateLimit.php
6 years ago
SignatureVerification.php
6 years ago
Base.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Stripe\Error; |
| 4 | |
| 5 | use Exception; |
| 6 | |
| 7 | abstract class Base extends Exception |
| 8 | { |
| 9 | public function __construct( |
| 10 | $message, |
| 11 | $httpStatus = null, |
| 12 | $httpBody = null, |
| 13 | $jsonBody = null, |
| 14 | $httpHeaders = null |
| 15 | ) { |
| 16 | parent::__construct($message); |
| 17 | $this->httpStatus = $httpStatus; |
| 18 | $this->httpBody = $httpBody; |
| 19 | $this->jsonBody = $jsonBody; |
| 20 | $this->httpHeaders = $httpHeaders; |
| 21 | $this->requestId = null; |
| 22 | |
| 23 | // TODO: make this a proper constructor argument in the next major |
| 24 | // release. |
| 25 | $this->stripeCode = isset($jsonBody["error"]["code"]) ? $jsonBody["error"]["code"] : null; |
| 26 | |
| 27 | if ($httpHeaders && isset($httpHeaders['Request-Id'])) { |
| 28 | $this->requestId = $httpHeaders['Request-Id']; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public function getStripeCode() |
| 33 | { |
| 34 | return $this->stripeCode; |
| 35 | } |
| 36 | |
| 37 | public function getHttpStatus() |
| 38 | { |
| 39 | return $this->httpStatus; |
| 40 | } |
| 41 | |
| 42 | public function getHttpBody() |
| 43 | { |
| 44 | return $this->httpBody; |
| 45 | } |
| 46 | |
| 47 | public function getJsonBody() |
| 48 | { |
| 49 | return $this->jsonBody; |
| 50 | } |
| 51 | |
| 52 | public function getHttpHeaders() |
| 53 | { |
| 54 | return $this->httpHeaders; |
| 55 | } |
| 56 | |
| 57 | public function getRequestId() |
| 58 | { |
| 59 | return $this->requestId; |
| 60 | } |
| 61 | |
| 62 | public function __toString() |
| 63 | { |
| 64 | $id = $this->requestId ? " from API request '{$this->requestId}'": ""; |
| 65 | $message = explode("\n", parent::__toString()); |
| 66 | $message[0] .= $id; |
| 67 | return implode("\n", $message); |
| 68 | } |
| 69 | } |
| 70 |