From ae05ef170c8d6fc2abbffde3e9be38e77eaa2992 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Mon, 7 Sep 2026 13:32:41 +0200 Subject: [PATCH 1/2] Release 4.0.1: PaymentRequiredError for HTTP 402. --- CHANGELOG.md | 3 +++ README.md | 1 + lib/Castle/Castle.php | 2 +- lib/Castle/Errors.php | 5 +++++ lib/Castle/Request.php | 2 ++ lib/aliases.php | 2 ++ test/ErrorsTest.php | 8 ++++++++ test/RequestContextTest.php | 2 +- 8 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b129d..7ea2f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## 4.0.1 +* 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..aa6d8a8 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.0.1'; 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..dd23a14 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.0.1"}}')); } /** From e9c9cd4a505ac01804361f96b3cf24d61d6b5907 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Mon, 7 Sep 2026 15:43:48 +0200 Subject: [PATCH 2/2] Release 4.1.0 Bump the PaymentRequiredError release from 4.0.1 to 4.1.0. --- CHANGELOG.md | 2 +- lib/Castle/Castle.php | 2 +- test/RequestContextTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ea2f53..5f30030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## 4.0.1 +## 4.1.0 * added `Castle\PaymentRequiredError` (`Castle_PaymentRequiredError`) for HTTP 402 responses ## 4.0.0 diff --git a/lib/Castle/Castle.php b/lib/Castle/Castle.php index aa6d8a8..9ee624b 100755 --- a/lib/Castle/Castle.php +++ b/lib/Castle/Castle.php @@ -4,7 +4,7 @@ abstract class Castle { - const VERSION = '4.0.1'; + const VERSION = '4.1.0'; const HEADER_COOKIE = 'Cookie'; const HEADER_USER_AGENT = 'User-Agent'; diff --git a/test/RequestContextTest.php b/test/RequestContextTest.php index dd23a14..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.1"}}')); + 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"}}')); } /**