feat: add X-Request-ID header support for idempotency (#3)#4
Merged
Conversation
Add `with_request_id` block for thread-safe idempotency key management. The X-Request-ID header is sent with API requests when set, enabling CloudPayments server-side result caching for 1 hour. - Add `CloudPayments.with_request_id` method with thread-local storage - Add `CloudPayments.current_request_id` method - Modify Client#headers to include X-Request-ID when set - Add comprehensive tests for idempotency functionality - Update README with usage examples - Add base64 gem for Ruby 3.4+ compatibility Refs #3 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…#3) Replace thread-local storage with explicit request_id: keyword parameter passed through the method chain. This approach: - Avoids Thread.current/Fiber issues in async environments - Makes the API more explicit and predictable - Uses Ruby 3.0+ compatible explicit hash syntax API: method(attributes, request_id: "key") Refs #3 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Strip whitespace from request_id before sending - Filter whitespace-only strings (e.g. " ") - Add integration test for Base#request with request_id - Add integration test for Tokens#charge with request_id - Add tests for whitespace handling in headers Refs #3 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add GitHub Actions workflow for CI (Ruby 3.1, 3.2, 3.3, 3.4) - Add mise.toml for Ruby version management (3.3) - Delete outdated .travis.yml (was Ruby 2.3-2.7) - Set required_ruby_version >= 3.1 in gemspec Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
request_id:keyword parameter to payment methods for idempotency supportX-Request-IDheader is sent with API requests whenrequest_idis providedrequest_id:is optionalAPI
Changes
lib/cloud_payments/client.rbrequest_id:toperform_requestandheaderslib/cloud_payments/namespaces/base.rbrequest_id:torequestmethodlib/cloud_payments/namespaces/*.rbrequest_id:to charge/auth/refund/create methodsspec/cloud_payments/client_spec.rbX-Request-IDheader behaviorREADME.mdGemfilebase64gem for Ruby 3.4+ compatibilityDesign Decision
Used explicit
request_id:parameter instead ofThread.currentblock approach:Test plan
X-Request-IDheader presence/absenceCloses #3
🤖 Generated with Claude Code