Add opt-in transport retries following PayWay retry guidance - #6
Merged
Conversation
Retry on connection errors, timeouts and HTTP 429/503 (honouring Retry-After), never on other status codes, and never for a POST without an Idempotency-Key. Off by default (max_retries=0). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 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
Adds opt-in transport retries to
Client, following PayWay's retry guidance:Client(..., max_retries=0, retry_delay=1.0). Defaultmax_retries=0keeps existing single-attempt behaviour — fully backwards compatible.requests.ConnectionError,requests.Timeout, and HTTP 429/503, with linear backoff (retry_delay × attempt), honouring a numericRetry-Afterheader when present.retry_delayis configurable since synchronous checkout flows can't afford PayWay's suggested 20s wait.idempotency_keywas supplied, and the sameIdempotency-Keyheader is resent on every attempt so PayWay replays the original response instead of double-charging. PUTs never carry a key, so they never retry. GETs always retry.(response, errors)contract is unchanged.Also documents the new params in the README, adds a CHANGELOG, and bumps the version to 0.0.8.
Test plan
TestClientRetriesunit tests (HTTP layer mocked): connection error then success (same key on both attempts), 429 then success (waits, honoursRetry-After), 503 exhausting retries, 500 not retried, POST without key not retried, defaultmax_retries=0single attempt, GET retried.ruff check paywayandmypy paywayclean.🤖 Generated with Claude Code