From c3e556c24d1c29ceaa5a54903a84f281a1169509 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Mon, 7 Sep 2026 12:54:15 +0200 Subject: [PATCH 1/5] Add PaymentRequiredError for HTTP 402. --- CHANGELOG.md | 4 ++++ lib/castle/core/process_response.rb | 1 + lib/castle/errors.rb | 3 +++ spec/lib/castle/core/process_response_spec.rb | 1 + 4 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e4f8b8..76a2aaa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add `Castle::PaymentRequiredError` for HTTP 402 responses. + ## 9.2.0 **Changes:** diff --git a/lib/castle/core/process_response.rb b/lib/castle/core/process_response.rb index 9797266e..8788927b 100644 --- a/lib/castle/core/process_response.rb +++ b/lib/castle/core/process_response.rb @@ -7,6 +7,7 @@ module ProcessResponse RESPONSE_ERRORS = { 400 => Castle::BadRequestError, 401 => Castle::UnauthorizedError, + 402 => Castle::PaymentRequiredError, 403 => Castle::ForbiddenError, 404 => Castle::NotFoundError, 419 => Castle::UserUnauthorizedError, diff --git a/lib/castle/errors.rb b/lib/castle/errors.rb index 7530aebb..589eb35e 100644 --- a/lib/castle/errors.rb +++ b/lib/castle/errors.rb @@ -65,6 +65,9 @@ class UnauthorizedError < Castle::ApiError class RateLimitError < Castle::ApiError end + class PaymentRequiredError < Castle::ApiError + end + # all internal server errors class InternalServerError < Castle::ApiError end diff --git a/spec/lib/castle/core/process_response_spec.rb b/spec/lib/castle/core/process_response_spec.rb index f52053d9..f64a2e43 100644 --- a/spec/lib/castle/core/process_response_spec.rb +++ b/spec/lib/castle/core/process_response_spec.rb @@ -92,6 +92,7 @@ it_behaves_like 'response_failed', '400', Castle::BadRequestError it_behaves_like 'response_failed', '401', Castle::UnauthorizedError + it_behaves_like 'response_failed', '402', Castle::PaymentRequiredError it_behaves_like 'response_failed', '403', Castle::ForbiddenError it_behaves_like 'response_failed', '404', Castle::NotFoundError it_behaves_like 'response_failed', '419', Castle::UserUnauthorizedError From 70c8e3d5ea564339b3805f060c11914e4ecffdb8 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Mon, 7 Sep 2026 12:55:00 +0200 Subject: [PATCH 2/5] Document PaymentRequiredError in the README errors table. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 78569341..6aa4e6f1 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,7 @@ All exceptions inherit from `Castle::Error`. The most useful ones: | `Castle::InvalidRequestTokenError` | The `request_token` is missing or invalid. | | `Castle::InvalidParametersError` | 422 response with validation details. | | `Castle::RateLimitError` | 429 response — back off and retry. | +| `Castle::PaymentRequiredError` | 402 response. | | `Castle::UnauthorizedError` | 401 — bad API secret. | | `Castle::InternalServerError` | 5xx response from Castle. | | `Castle::WebhookVerificationError` | Webhook signature did not match. | From 5de54023442a2020fb28e68d11bf7353ebecdea0 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Mon, 7 Sep 2026 13:32:30 +0200 Subject: [PATCH 3/5] Release 9.2.1: PaymentRequiredError for HTTP 402. --- CHANGELOG.md | 2 +- lib/castle/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a2aaa1..e92ac683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## 9.2.1 - Add `Castle::PaymentRequiredError` for HTTP 402 responses. diff --git a/lib/castle/version.rb b/lib/castle/version.rb index c4adb7b2..a70f7b70 100644 --- a/lib/castle/version.rb +++ b/lib/castle/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Castle - VERSION = '9.2.0' + VERSION = '9.2.1' end From ea385dc7cb23619ec109d878d2fdfb283d765ce0 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Mon, 7 Sep 2026 13:49:51 +0200 Subject: [PATCH 4/5] Sync Gemfile.lock to castle-rb 9.2.1. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 559224c1..9493a62a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - castle-rb (9.2.0) + castle-rb (9.2.1) base64 (~> 0.2) GEM From 26898a5d52e7c93fbdc54317030e821288f9a64b Mon Sep 17 00:00:00 2001 From: Bartosz Date: Mon, 7 Sep 2026 15:38:55 +0200 Subject: [PATCH 5/5] Release 9.3.0 Bump the PaymentRequiredError release from 9.2.1 to 9.3.0. --- CHANGELOG.md | 2 +- Gemfile.lock | 2 +- lib/castle/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e92ac683..42528245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 9.2.1 +## 9.3.0 - Add `Castle::PaymentRequiredError` for HTTP 402 responses. diff --git a/Gemfile.lock b/Gemfile.lock index 9493a62a..529a5c0d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - castle-rb (9.2.1) + castle-rb (9.3.0) base64 (~> 0.2) GEM diff --git a/lib/castle/version.rb b/lib/castle/version.rb index a70f7b70..88daa753 100644 --- a/lib/castle/version.rb +++ b/lib/castle/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Castle - VERSION = '9.2.1' + VERSION = '9.3.0' end