magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

When 'quantity' refers to a decimal number, the digits after the decimal point are stripped away.

Open mikerooijackers opened this issue 10 months ago • 4 comments

Describe the bug If you place an order with a quantity of 0.3 , this will not be correctly processed by Mollie. The number that Mollie receives as the quantity is 0.

Used versions

  • Magento Version number(eg 2.3.5): 2.4.6-p4
  • Open source/Enterprise/B2b: Open source
  • Mollie version number (Check configuration): 2.36.0

To Reproduce Steps to reproduce the behavior:

  1. Order a product with a quantity of 0.3
  2. place order with payment method mollie
  3. See error in mollie.log

Expected behavior No error in de request.

Actual behavior Error in de request: Mollie.ERROR: error: Error executing API call (422: Unprocessable Entity): Order line 1 is invalid. Quantity must be greater than 0.. Field: lines.1.quantity. Documentation: https://docs.mollie.com/overview/handling-errors [] []

mikerooijackers avatar Apr 04 '24 07:04 mikerooijackers

Hey @mikerooijackers, thanks for bringing this up! We'll look into it and get back to you soon after checking how Mollie handles things and reviewing the invoicing/credit process. Stay tuned! :)

Frank-Magmodules avatar Apr 04 '24 07:04 Frank-Magmodules

When the round function is removed and the quantity is sent correctly, you will receive the following error message.

Error executing API call (422: Unprocessable Entity): Order line 1 is invalid. The 'quantity' field should be a whole number. Field: lines.1.quantity. Documentation: https://docs.mollie.com/overview/handling-errors

mollie.patch

mikerooijackers avatar Apr 04 '24 09:04 mikerooijackers

Scherm­afbeelding 2024-04-04 om 11 24 44

mikerooijackers avatar Apr 04 '24 09:04 mikerooijackers

diff --git a/vendor/mollie/magento2/Service/Order/Lines/Order.php b/Service/Order/Lines/Order.php
--- a/vendor/mollie/magento2Service/Order/Lines/Order.php
+++ b/vendor/mollie/magento2Service/Order/Lines/Order.php
@@ -155,7 +155,7 @@
          * The price of a single item including VAT in the order line.
          * Calculated back from the totalAmount + discountAmount to overcome rounding issues.
          */
-        $unitPrice = round(($totalAmount + $discountAmount) / $item->getQtyOrdered(), 2);
+        $unitPrice = ($totalAmount + $discountAmount) / ($item->getQtyOrdered() * 100);

         /**
          * The amount of VAT on the line.
@@ -176,7 +176,7 @@
             'item_id' => $item->getId(),
             'type' => $item->getIsVirtual() !== null && (int) $item->getIsVirtual() !== 1 ? 'physical' : 'digital',
             'name' => preg_replace('/[^\p{L}\p{N} -]/u', '', $item->getName() ?? ''),
-            'quantity' => round($item->getQtyOrdered()),
+            'quantity' => $item->getQtyOrdered() * 100,
             'unitPrice' => $this->mollieHelper->getAmountArray($this->currency, $unitPrice),
             'totalAmount' => $this->mollieHelper->getAmountArray($this->currency, $totalAmount),
             'vatRate' => sprintf("%.2f", $item->getTaxPercent()),

mikerooijackers avatar Apr 04 '24 11:04 mikerooijackers

Hi There @mikerooijackers , sorry for the wait but we had some internal discussions on what the best approach and solution is for this issue.

We had fixed this issue based on your idea but decided not to include this in the default. You can use this patch that we have created for you, but surely only at your own risk. We won’t support this any further and/or merge it into a future release, so you need to keep an eye on that.

I'm closing this issue for now but feel free to comment on the issue once you feel like it.

Frank-Magmodules avatar May 23 '24 08:05 Frank-Magmodules

We just encountered exactly the same issue.

If the quantity is below 0.5, you get something like this:

Mollie.ERROR: error: [2024-08-04T19:10:53+0000] Error executing API call (422: Unprocessable Entity): Order line 1 is invalid. Quantity must be greater than 0.. Field: lines.1.quantity. Documentation: https://docs.mollie.com/overview/handling-errors [] []

However, if your quantity is something like 1.5, you might also get something like this:

Mollie.ERROR: error: [2024-08-05T01:18:34+0000] Error executing API call (422: Unprocessable Entity): Order line 2 is invalid. Total amount is off. Expected total amount to be CHF 14.80 (2 × CHF 7.40), got CHF 11.10. Field: lines.2.totalAmount. Documentation: https://docs.mollie.com/overview/handling-errors [] []

@Frank-Magmodules, this is clearly a bug. Why don't you include a proper fix in the module? I'd prefer not to include a patch on a permanent basis for this.

sprankhub avatar Aug 05 '24 12:08 sprankhub

We can't just fix it in the integration, as it will lead to unpredictable results. The Orders API does not support fractional quantities, and in so far I don't agree that this is a bug in the plugin (the different results with the round are maybe a bit of a different story).

We will, however, migrate away from the strict requirement for line items by moving things away from the Orders API, so we should see this happening a lot less.

fjbender avatar Aug 05 '24 12:08 fjbender

Then it's a massive oversight in the Orders API.

So what is the official recommendation in this case? Only using the Payments API, not using the Orders API at all?

I am currently unsure about the consequences, besides a clunky log file. We still have some issues with some orders, but I'm not sure yet if this is related to this issue.

sprankhub avatar Aug 05 '24 12:08 sprankhub

The recommendation depends a bit on your exact use case. If you're selling e.g. apples by weight and require a payment method currently only available on the Orders API, using the patch with multiplying might solve your issue for now (but could potentially confuse customers). If you don't require any Orders API features, turning off the Orders API completely is the better way forward.

fjbender avatar Aug 05 '24 13:08 fjbender