Decide the status from the last approved operation - #59
Closed
loevgaard wants to merge 1 commit into
Closed
Conversation
StatusAction decided from Operations::latest() alone, so a trailing rejected or still-pending attempt masked what actually happened to the money: capture 1000 then a bounced refund attempt reported unknown while 1000 was demonstrably still held, and an authorized payment whose capture attempt failed reported as failed while its authorization was intact. Both branches now read Operations::latestApproved() — the last operation that DID succeed. Payum consumers (Sylius state machines in particular) treat unknown/failed as dead ends, so the mark must not degrade just because the most recent attempt did not go through.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix/confirm-payment-approved-authorize #59 +/- ##
============================================================================
+ Coverage 97.43% 97.75% +0.31%
- Complexity 126 129 +3
============================================================================
Files 14 14
Lines 351 356 +5
============================================================================
+ Hits 342 348 +6
+ Misses 9 8 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes robustness finding R2 of #57. Stacked on #58 (shares the pending-operation test fixture) — merge that first; this PR's own diff is the last commit.
Problem
StatusActiondecided fromOperations::latest()— the last operation recorded, not the last one that succeeded:processed+ [capture 1000, refund attempt the acquirer rejected] →markUnknown(), although the 1000 is demonstrably still held (balance> 0 is already in hand at that point).processed+ [capture, async refund still pending] →markUnknown()until the callback lands.new+ [approved authorize, rejected capture attempt] →markFailed(), although the authorization is intact and a retry is possible.Downstream consumers (Sylius state machines) treat unknown/failed as dead ends, so a payment holding real money fell out of the flow.
Fix
New
Operations::latestApproved()returns the most recent operation with an approved status code, skipping trailing rejected/pending attempts. Both thenewandprocessedbranches ofStatusActionnow decide from it. The refund branch's balance logic (partial refund stayscaptured, zero balance isrefunded) is unchanged, as ismarkUnknownwhen nothing approved exists at all.Operations::isLatestApproved()is no longer used by the package but stays — it is public API.Tests
Rejected-refund-stays-captured, pending-refund-stays-captured, rejected-capture-stays-authorized,
newwith no operations pinsfailed, unmodeled state string pinsunknown, plus directOperations::latestApproved()coverage.