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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mathiasgmeiner created an issue. See original summary.

mathiasgmeiner’s picture

This is my first take on this bug.

mathiasgmeiner’s picture

FileSize
948 bytes

I've copied the calculation to the wrong line. Sorry for that inconvenience.
This should be the working patch.

jsacksick’s picture

why do you have a unit price with 6 decimals?

Anybody’s picture

why do you have a unit price with 6 decimals?

That's a valid question. Is the amount calculated dynamically or perhaps the result of a VAT calculation?

Of course this shouldn't fail, but instead be rounded to the expected number of decimals before.

mathiasgmeiner’s picture

The amount is the result of a VAT calculation.
Does that help?