Reject non-integer amounts instead of truncating them - #62
Open
loevgaard wants to merge 1 commit into
Open
Conversation
Amounts::forOperation() accepted anything is_numeric() and cast it with (int), so a fractional value was silently truncated: 249.99 — which, in minor units, can only mean someone passed kroner where øre were expected — became a charge of 249 rather than an error. Only integers and integer strings (the shape a serialization round trip may produce) are accepted now; anything fractional throws the same LogicException the other unusable shapes get, with the offending value in the message.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #62 +/- ##
=========================================
Coverage 97.43% 97.44%
- Complexity 126 129 +3
=========================================
Files 14 14
Lines 351 352 +1
=========================================
+ Hits 342 343 +1
Misses 9 9 ☔ 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 R6 of #57.
Problem
Amounts::forOperation()accepted anythingis_numeric()and cast it with(int). A fractional value was silently truncated:249.99became a capture/refund of 249. Since every amount in this gateway is minor units, a fractional value is always a caller bug — it can only mean kroner were passed where øre were expected — and truncation turns that bug into an undercharge instead of an error.Fix
Accept integers and integer strings (the shape a serialization round trip in the consumer's storage may produce); everything else — floats, decimal strings, booleans — throws the same
LogicExceptionthe other unusable shapes get, now with the offending value in the message. The positive-amount rule and thecapture_amount/refund_amountoverride semantics are unchanged.Tests
Data-provider cases for
249.99,250.0,'249.99'andtrue; the existing integer-string acceptance is already pinned byshouldAcceptNumericStrings.