Floating number issue may lead to lower price passed to PayU

Created on 26 March 2024, 8 months ago
Updated 30 May 2024, 6 months ago

Problem/Motivation

For specific prices in the order, the price passed to PayU might be slightly smaller than defined in the order. This may lead to serious issue when users are paying 0,01 less than they should.

Steps to reproduce

  1. Create a product with price like 269,90
  2. Start an roder with PayU as payment method
  3. Observe that price in PayU is 269,89 instead of 269,90

Proposed resolution

The issue is caused by Float being used to represent currency. Problem is described in Commerce documentation: https://docs.drupalcommerce.org/commerce2/developer-guide/pricing/prices, linking specifally to: https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-... as a description why Float should not be used to represent currency.

My suggestion for fix is in the patch.

This issue is really critical, as customer, in case of some prices, may pay different price (just 0,01 lower) than they should. But it may lead to lot of accounting issues and cause problems when total order amount is compared with amount paid.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇵🇱Poland besek

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

Comments & Activities

Production build 0.71.5 2024