mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
98 stars 49 forks source link

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

Closed mikerooijackers closed 1 month ago

mikerooijackers commented 2 months ago

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

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 [] []

Frank-Magmodules commented 2 months ago

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! :)

mikerooijackers commented 2 months ago

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 commented 2 months ago

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

mikerooijackers commented 2 months ago
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()),
Frank-Magmodules commented 1 month ago

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.