Order items unit_amount is not rounded properly

Created on 3 June 2022, over 2 years ago
Updated 29 July 2024, about 1 month ago

I get this error because the unit_amount in CheckoutSdk.php has 6 decimals instead of 2.

{"name":"UNPROCESSABLE_ENTITY","details":[@"field":"/purchase_units/@reference_id=='default'item/0/unit_amount/value","value":"49.903333","issue":"DECIMAL_PRECISION","description":"If the currency supports decimals, only two decimal place precision is supported."],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"a420329cadd78","links":[@"href":"https://developer.paypal.com/docs/api/orders/v2/#error-DECIMAL_PRECISION","rel":"information_link","method":"GET"]}

Is this related to this issue? https://www.drupal.org/project/commerce_paypal/issues/2846568

🐛 Bug report
Status

Fixed

Version

1.0

Component

PayPal Checkout

Created by

🇦🇹Austria mathiasgmeiner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇪🇸Spain plopesc Valladolid

    We are experiencing a similar issue, and the reason why we have prices with more than 2 decimals is that Commerce price widget allows to enter them. Product manager entered a 3 decimals price by accident.

    Adjustments are more likely to have more than 2 decimals, but they are not throwing this error. Reason is that adjustments are rounded by the following call:
    $adjustments = $this->adjustmentTransformer->processAdjustments($adjustments);
    That internally combines, sort and round the adjustments.

    So, it seems logic that unit item prices are rounded as well, as proposed in the patch.

    Would be great if you could consider this patch, or propose a different approach.

    Thank you!

  • Status changed to Needs work about 2 months ago
  • 🇮🇱Israel jsacksick

    Usually the total is rounded, not the unit price, but if not rounding is causing issues in some cases, willing to commit the patch.
    However, the patch doesn't use dependency injection, so it's not acceptable as is.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 158s
    #224417
  • Status changed to Needs review about 2 months ago
  • 🇪🇸Spain plopesc Valladolid

    MR created using DI for the rounder service.

    • 132b1805 committed on 8.x-1.x
      Issue #3283973: Order items unit_amount is not rounded properly
      
  • Status changed to Fixed about 2 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024