Repository navigation
Fix 100x over-refund for small amounts: treat integer refund amounts as cents - #19
Open
nickygerritsen wants to merge 1 commit into
Open
nickygerritsen wants to merge 1 commit into
nickygerritsen wants to merge 1 commit into
Conversation
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
The admin refund UI always sends the amount as an integer number of cents (
MultiSafepayApi.service.js:Math.round(amount * 100)), butRefundController::normalizeRefundAmount()guesses the unit of integer input: any integer ≤ the order total is interpreted as full units (euros) instead of cents.As a result, every refund whose cent value is smaller than the order's total in units is multiplied by 100:
20→20 <= 25→ interpreted as €20.00 → €20.00 refunded (reproduced on 4.3.0 against the test API).500→500 <= 1000→ €500.00 refunded.The larger the order, the larger the window: any refund up to 1% of the order total triggers the bug, and the money actually leaves the merchant's account.
Fix
Integer input (no decimal separator) is now always interpreted as cents, matching what the shipped admin UI sends. Decimal input (
"9.99","9,99") keeps its meaning of full units. The order-total-based guessing (and the now-unused$orderAmountTotalparameter) is removed, so the interpretation of an amount no longer depends on the order it is refunded against.Tests
testNormalizeRefundAmountParsesDecimalsAndCentsCorrectlyto cover the regression case ("20"→ €0.20) and adjusted therefund()happy-path test to send cents like the admin UI does.tests/Unit/Storefront/Controller/RefundController*Test.phppass.20on a €25 order now creates a €0.20 refund (previously €20.00).🤖 Generated with Claude Code