paytrail / paytrail-for-adobe-commerce

Paytrail payment service for Adobe Commerce (formerly known as Magento 2)
https://www.paytrail.com
MIT License
2 stars 7 forks source link

A problem occurred during Paytrail Api connection: Items units can't be a negative number #52

Closed sheepfy closed 1 year ago

sheepfy commented 1 year ago

I have an order with 3 x 74.65 priced product, 9.90 shopping row and discount code of 10. in file: vendor/paytrail/paytrail-for-adobe-commerce/Helper/ApiData.php::getOrderItemLines we get a $itemSum != $orderTotal which created the rounding-row with units of -1 .

Then, in file: vendor/paytrail/paytrail-php-sdk/src/Model/Item.php::validate we have this validation: if ($props['units'] < 0) { throw new ValidationException('Items units can\'t be a negative number'); }

sheepfy commented 1 year ago

Issue can be replicated with any qty 3 products that have any price and a cart discount applied of 10.

On the roundings in the module, the discount is substracted from the items at line: vendor/paytrail/paytrail-for-adobe-commerce/Model/Token/RequestData.php::getItemArgs floatval($item->getPriceInclTax()) - round(($discountIncl / $item->getQtyOrdered()), 2),

since 10 divided by 3 it's resulting into 3.33 and sum of 3.33 + 3.33 + 3.33 = 9.99 the rounding diff of 0.01 if present there for rounding item. And item is created in such manner that IF statement from here: $roundingItem->setUnits(($orderTotal - $itemSum > 0) ? 1 : -1); will populate the value with -1

loueranta-paytrail commented 1 year ago

Thanks for reporting, we will look in to this.

bartoszkaluzny-solteq commented 1 year ago

Issue has been fixed with new version 1.4.4