Skip to content

Rounding differences potentially lead to order failure #3372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
luzat opened this issue May 9, 2025 · 0 comments
Open

Rounding differences potentially lead to order failure #3372

luzat opened this issue May 9, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@luzat
Copy link

luzat commented May 9, 2025

Describe the Bug

Rounding differences can change the basket to contain physical goods and lead to additional errors such as order failure.

To Reproduce

  1. Create an order with only digital goods which introduces rounding differences (I guess because PayPal is receiving net values; here, this happens with a VAT of 19% and two items of 9.50 gross value each).
  2. An extra_line item Subtotal mismatch will be added by default by PurchaseUnitSanitizer. This item is a physical product.
  3. An error can occur at a later point, which would otherwise not happen, such as in OrderProcessor::process:
if ($this->order_helper->contains_physical_goods($order) && !$this->order_is_ready_for_process($order)) {
    throw new Exception(__('The payment is not ready for processing yet.', 'woocommerce-paypal-payments'));
}

This is because $this->order_helper->contains_physical_goods($order) now returns true.

Expected Behavior

I expect the order to go through.

Actual Behavior

An exception is sometimes (always?) thrown after the order is completed and the order fails (even though it has already been paid) at the mentioned lines in OrderProcessor::process.

Environment

  • WordPress Version 6.8.1
  • WooCommerce Version 9.8.4
  • Plugin Version 3.0.5

Additional Details

My workaround is to patch PurchaseUnitSanitizer::sanitize_item_amount_mismatch:

$this->purchase_unit['items'][] = (new Item($line_name, $roundings_money, 1, category: Item::DIGITAL_GOODS))->to_array();

Problems with that implementation: This will always add digital goods and is only PHP 8.0+ (not 7.4).

luzat added a commit to luzat/woocommerce-paypal-payments that referenced this issue May 9, 2025
Rounding differences were previously added as physical goods, which changed the properties of the
cart. Now, if the cart does not contain physical items, the extra line item will be added as a
digital goods item.
@InpsydeNiklas InpsydeNiklas added the enhancement New feature or request label Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants