fix(payments): orchestrate a payment automatically after it is initiated - #319
Merged
Conversation
A payment created through the API stayed in INITIATED forever: the orchestrator that screens and submits it had no production caller (only the retry path touched it, and only for payments already in SCREENING). Publish an in-process event when a payment is persisted and drive orchestration from an after-commit, asynchronous listener on a bounded executor, so screening and bank submission run off the request thread, after the row is durably committed, and never inside a transaction. A bank failure still leaves the payment in SCREENING for the scheduled retry. Idempotent replays do not re-trigger. Closes #317
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.
fix(payments) #317 - orchestrate a payment automatically after initiate.
The defect
PaymentOrchestrator.process() (INITIATED -> SCREENING -> bank submit -> SUBMITTED) had NO production caller - only the retry path used the orchestrator, and only for payments already in SCREENING (its scheduler is off by default). So a payment created via POST /v1/payments stayed in INITIATED forever. Found during #236 scoping by source verification; the e2e demo (#236) is precisely the test that would have caught it.
Fix
Tests
Unit: the trigger processes on the event and swallows a failure; the service publishes the event on initiate. The full after-commit -> async -> SUBMITTED path is exercised by the #236 compose-smoke demo on a live stack (a JVM @DataJpaTest slice cannot load the async listener). detekt + spotless + unit tests green locally; integrationTest runs on CI.
Gate chain
critic: GO-WITH-CHANGES. code-reviewer + security-auditor reviewed. Applied: bounded @async executor (was the HIGH), invariant comment. Verified: process() is non-transactional by design (each transition is its own short tx). Durability backstop (the retry sweeper should also recover stuck INITIATED, not only SCREENING) tracked as follow-up #318; the bounded executor's graceful drain already covers the shutdown case, leaving only a hard-crash window. evaluator: PASS (0.85).
Closes #317