diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e4f8b..4252824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 9.3.0 + +- Add `Castle::PaymentRequiredError` for HTTP 402 responses. + ## 9.2.0 **Changes:** diff --git a/Gemfile.lock b/Gemfile.lock index 559224c..529a5c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - castle-rb (9.2.0) + castle-rb (9.3.0) base64 (~> 0.2) GEM diff --git a/README.md b/README.md index 7856934..6aa4e6f 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. | diff --git a/lib/castle/core/process_response.rb b/lib/castle/core/process_response.rb index 9797266..8788927 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 7530aeb..589eb35 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/lib/castle/version.rb b/lib/castle/version.rb index c4adb7b..88daa75 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.3.0' end diff --git a/spec/lib/castle/core/process_response_spec.rb b/spec/lib/castle/core/process_response_spec.rb index f52053d..f64a2e4 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