diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b129d..5f30030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## 4.1.0 +* added `Castle\PaymentRequiredError` (`Castle_PaymentRequiredError`) for HTTP 402 responses + ## 4.0.0 **BREAKING CHANGES:** diff --git a/README.md b/README.md index 2660eec..5e34747 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,7 @@ Whenever something unexpected happens, an [exception](lib/Castle/Errors.php) is | `Castle_InternalServerError` | The Castle API returned a `5xx` response (triggers failover) | | `Castle_ConfigurationError` | The Castle secret API key has not been set | | `Castle_UnauthorizedError` | Wrong Castle API secret key | +| `Castle_PaymentRequiredError` | HTTP 402 response | | `Castle_BadRequest` | The request was invalid. For example if a challenge is created without the user having MFA enabled. | | `Castle_ForbiddenError` | The user has entered the wrong code too many times and a new challenge has to be requested. | | `Castle_NotFoundError` | The resource requestd was not found. For example if a session has been revoked. | diff --git a/lib/Castle/Castle.php b/lib/Castle/Castle.php index 0e40e26..9ee624b 100755 --- a/lib/Castle/Castle.php +++ b/lib/Castle/Castle.php @@ -4,7 +4,7 @@ abstract class Castle { - const VERSION = '4.0.0'; + const VERSION = '4.1.0'; const HEADER_COOKIE = 'Cookie'; const HEADER_USER_AGENT = 'User-Agent'; diff --git a/lib/Castle/Errors.php b/lib/Castle/Errors.php index 9fe5610..a0beb19 100755 --- a/lib/Castle/Errors.php +++ b/lib/Castle/Errors.php @@ -65,6 +65,11 @@ class InvalidRequestTokenError extends InvalidParametersError } +class PaymentRequiredError extends ApiError +{ + +} + class WebhookVerificationError extends Error { diff --git a/lib/Castle/Request.php b/lib/Castle/Request.php index 7821792..38f3065 100755 --- a/lib/Castle/Request.php +++ b/lib/Castle/Request.php @@ -23,6 +23,8 @@ public function handleApiError($response, $status) throw new BadRequest($msg, $type, $status); case 401: throw new UnauthorizedError($msg, $type, $status); + case 402: + throw new PaymentRequiredError($msg, $type, $status); case 403: throw new ForbiddenError($msg, $type, $status); case 404: diff --git a/lib/aliases.php b/lib/aliases.php index f15aa36..7ccd021 100644 --- a/lib/aliases.php +++ b/lib/aliases.php @@ -41,6 +41,7 @@ function castle_legacy_alias_map() 'Castle_NotFoundError' => 'Castle\\NotFoundError', 'Castle_InvalidParametersError' => 'Castle\\InvalidParametersError', 'Castle_InvalidRequestTokenError' => 'Castle\\InvalidRequestTokenError', + 'Castle_PaymentRequiredError' => 'Castle\\PaymentRequiredError', 'Castle_WebhookVerificationError' => 'Castle\\WebhookVerificationError', ); } @@ -82,6 +83,7 @@ class_alias($target, $class); 'Castle\\NotFoundError', 'Castle\\InvalidParametersError', 'Castle\\InvalidRequestTokenError', + 'Castle\\PaymentRequiredError', 'Castle\\WebhookVerificationError', ); diff --git a/test/ErrorsTest.php b/test/ErrorsTest.php index 252fda9..fc3f626 100644 --- a/test/ErrorsTest.php +++ b/test/ErrorsTest.php @@ -27,6 +27,14 @@ public function testUnauthorized() $this->request->send('GET', '/test'); } + public function testPaymentRequired() + { + Castle_RequestTransport::setResponse(402); + + $this->expectException(Castle_PaymentRequiredError::class); + $this->request->send('GET', '/test'); + } + public function testForbidden() { Castle_RequestTransport::setResponse(403); diff --git a/test/RequestContextTest.php b/test/RequestContextTest.php index cafc740..c623146 100644 --- a/test/RequestContextTest.php +++ b/test/RequestContextTest.php @@ -28,7 +28,7 @@ public function contextProvider() { } public function contextJsonProvider() { - return array(array('{"ip":"8.8.8.8","headers":{"User-Agent":"TestAgent","X-Castle-Client-Id":"1ccf8dee-904b-4d20-8a88-55ded468bcc5"},"library":{"name":"castle-php","version":"4.0.0"}}')); + return array(array('{"ip":"8.8.8.8","headers":{"User-Agent":"TestAgent","X-Castle-Client-Id":"1ccf8dee-904b-4d20-8a88-55ded468bcc5"},"library":{"name":"castle-php","version":"4.1.0"}}')); } /**