Reconcile a rejected admin refund against the real EveryPay state - #6
Merged
Conversation
A refund made in the EveryPay merchant portal used to make the admin Refund button fail with a generic error until the portal callback was processed: EveryPay rejects the API refund because the money already left the account, and the rejection was indistinguishable from a real failure. The refund handler now treats a 4xx rejection as a hint only: it re-reads the authoritative payment state and, when EveryPay confirms refunded, completes the in-flight refund transition with the fresh snapshot. Any other rejection, server error or transport failure keeps the existing behavior - transaction rollback, error flash, payment stays completed in the database. The remote snapshot merge is now shared between the synchronizer and the refund handler via EveryPayGateway::withRemoteSnapshot().
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.
Problem
A refund made in the EveryPay merchant portal makes the admin Refund button fail with a generic "refund failed" flash until the portal callback is processed: EveryPay rejects the API refund (the amount exceeds what is standing), and that rejection was indistinguishable from a real failure - the payment stayed
completedeven though the money had already been reimbursed.Change
RefundEveryPayPaymentHandlernow treats a 4xx rejection as a hint only:GET /v4/payments/{payment_reference}- the same authenticated call the synchronizer uses, so no state change ever derives from an error response;refunded, the in-flightcompleted -> refundedtransition completes with the fresh payment snapshot (the listener and its transaction are untouched - the commit path is exactly today's success path);completedin the database.The remote-snapshot merge (
payment_state/payment_method/standing_amount/synchronized_at) is now shared between the synchronizer and the refund handler viaEveryPayGateway::withRemoteSnapshot(), so both write the same details shape.Known trade-off (documented in the code): EveryPay reports
refundedfor partial portal refunds too, so a partial portal refund reconciles the Sylius payment torefunded- the same thing the callback path already does;standing_amountin the snapshot keeps the remainder visible on the admin order page.Tests
Gates
phpunit(both suites),phpstanlevel 9,ecs,behat --strict- all green, also undercomposer update --prefer-lowest --prefer-stable.