feat(payments): add scheduled retry for stuck payments - #227
Merged
Conversation
Add an opt-in scheduled job that re-routes payments stuck in screening (left there by a transient bank failure) back to the bank within a bounded age window, and fails them once past the deadline. The job is not transactional: it resumes a stuck payment through the orchestrator, which re-submits to the bank outside any transaction and settles the outcome in its own short transaction; each payment is attempted independently so one failure does not abort the batch. The retry window is bounded by stuck-after and max-age (validated so stuck-after never exceeds max-age), and the scheduler is off by default. A partial index on the live statuses backs the stuck-payment query. Closes #215
Apply the service interface+impl rule (CLAUDE.md 8.3): PaymentRetryService is now an interface and the logic moves to PaymentRetryServiceImpl with @service. No behaviour change.
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.
What
Eighth slice of E-02. An opt-in
@Scheduledjob that recovers payments stuck inSCREENING(left there when a bank submission failed transiently in #213).PaymentOrchestrator.resume(payment): re-route aSCREENINGpayment to the bank (re-submit, outside any transaction).PaymentRetryService(not@Transactional): findSCREENINGpayments older thanstuck-after; per payment, re-route viaresume, or - if older thanmax-age-markFailed("retry deadline exceeded"). Per-paymenttry/catchso one failure does not abort the batch.[stuck-after, max-age]window bounds total attempts;PaymentRetryProperties.initvalidatesstuck-after <= max-age. Age-based (noretry_countcolumn / migration).PaymentRetryScheduler:@Configuration @EnableScheduling @ConditionalOnProperty(...enabled, matchIfMissing=false)- off by default (mirrors the ledger cleanup scheduler Cleanup/TTL job for idempotency_keys (24h) and outbox (30d) #67).idx_payments_status_created_aton the live statuses backs the query.§8.10: the bank call runs outside any transaction (service + orchestrator non-transactional; transitions are separate-bean short transactions). Single-scheduler-instance + idempotent-submit is documented as a load-bearing contract; a
SCREENING -> SUBMITTEDtransition removes a payment from the retry set once accepted.Gates
Local (
-x integrationTest)::services:payments:{test,detekt,detektTest,spotlessCheck,assemble,compileIntegrationTestKotlin}green. critic GO (single-instance contract +stuck-after<=max-ageguard applied), security-auditor PASS (§8.10 + bounded-retry + §5.3, 5/5 ACs), evaluator 0.914 (a prior eval pass hallucinated a §8.10 violation referencing a non-existent status; a fresh grep-verified re-eval confirmed PASS). The migration runs on CI.Closes #215