Normalise decimal WC quantities to integers before sending to Mollie#1240
Open
mmaymo wants to merge 1 commit into
Open
Conversation
danielhuesken
approved these changes
Jun 29, 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.
What and why
WooCommerce supports fractional product quantities (e.g. 1.5 metres of fabric) via third-party plugins. When a
cart contained such a quantity, both OrderLines and PaymentLines passed the raw float directly to the Mollie API
as the quantity field. Mollie requires quantity to be a whole number of at least 1, so any order with a
fractional quantity was rejected with a 422 Unprocessable Entity response — making payment completely impossible
for those customers.
How it works now
Both OrderLines and PaymentLines now include a private toIntegerQuantity() helper that converts a fractional
WooCommerce quantity to the smallest equivalent whole number by finding the minimal decimal scale factor (e.g.
1.5 → ×10 → 15, 0.4 → ×10 → 4). get_item_quantity() returns this scaled integer to Mollie, and get_item_price()
divides the line subtotal by the same scaled value — preserving Mollie's required invariant unitPrice × quantity
− discountAmount == totalAmount exactly. For repeating decimals that cannot be scaled exactly within four
decimal places, the helper falls back to rounding and clamps to a minimum of 1.
What to verify in review
Covered by unit tests
division by zero
Not covered by unit tests
None — all acceptance criteria are covered by the unit test suite.