Decide the status from the last approved operation - #65
Open
loevgaard wants to merge 1 commit into
Open
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.
This was referenced Aug 10, 2026
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. Supersedes #59, which was auto-closed when its stacked base branch (#58's) was deleted on merge — #58 is now in 2.x, so this targets 2.x directly and the diff is the R2 change alone.
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.