magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

[Fooman_Surcharge] Error when using Klarna - Division by zero

Open gerben86 opened this issue 2 years ago • 3 comments

Describe the bug When a customer tries to pay via Klarna I see this error in the system.log:

[2022-09-27T11:42:30.406991+00:00] main.CRITICAL: Exception message: Warning: Division by zero in vendor/mollie/magento2/Service/Order/Lines/Generator/FoomanTotals.php on line 63
Trace: <pre>#1 Mollie\Payment\Model\Mollie->startTransaction() called at [vendor/mollie/magento2/Controller/Checkout/Redirect.php:240]
#2 Mollie\Payment\Controller\Checkout\Redirect->startTransaction() called at [vendor/mollie/magento2/Controller/Checkout/Redirect.php:127]
#3 Mollie\Payment\Controller\Checkout\Redirect->execute() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#4 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#5 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#6 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->___callPlugins() called at [generated/code/Mollie/Payment/Controller/Checkout/Redirect/Interceptor.php:23]
#7 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->execute() called at [vendor/magento/framework/App/Action/Action.php:111]
#8 Magento\Framework\App\Action\Action->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#9 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#10 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#11 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->___callPlugins() called at [generated/code/Mollie/Payment/Controller/Checkout/Redirect/Interceptor.php:32]
#12 Mollie\Payment\Controller\Checkout\Redirect\Interceptor->dispatch() called at [vendor/magento/framework/App/FrontController.php:245]
#13 Magento\Framework\App\FrontController->getActionResponse() called at [vendor/magento/framework/App/FrontController.php:212]
#14 Magento\Framework\App\FrontController->processRequest() called at [vendor/magento/framework/App/FrontController.php:147]
#15 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#16 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#17 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php:99]
#18 Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#19 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php:75]
#20 Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#21 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#22 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:23]
#23 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:116]
#24 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#25 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:60]
</pre> [] []

I don't see the error on the Mollie Dashboard and the status within Magento is 'Payment review'.

Used versions

  • Magento Version number(eg 2.3.5): 2.4.4
  • Open source/Enterprise/B2b: Open source
  • Mollie version number (Check configuration): v2.16.0

Expected behavior Order just gets accepted by Mollie and Klarna. The order gets a status in which I can process the order.

Actual behavior Order not visible in Mollie Dashboard. An error in the system.log and the order has the status 'Payment review'

Screenshots

image

image

gerben86 avatar Sep 27 '22 18:09 gerben86

I'm also using Fooman module Fooman_Surcharge, so maybe it's related to this fixed issue: https://github.com/mollie/magento2/issues/512

gerben86 avatar Sep 28 '22 20:09 gerben86

Hello @gerben86 ,

Thank you for opening this issue and adding the comment regarding the Fooman_Surcharge module. 
As we don’t have access to this module, could you check if this patch fixes the issue for you?

diff --git a/Service/Order/Lines/Generator/FoomanTotals.php b/Service/Order/Lines/Generator/FoomanTotals.php
index 68630ce..3c292ce 100644
--- a/Service/Order/Lines/Generator/FoomanTotals.php
+++ b/Service/Order/Lines/Generator/FoomanTotals.php
@@ -59,7 +59,7 @@ class FoomanTotals implements GeneratorInterface
             $taxAmount = $forceBaseCurrency ? $total->getBaseTaxAmount() : $total->getTaxAmount();

             $vatRate = 0;
-            if ($taxAmount) {
+            if ($taxAmount && $amount) {
                 $vatRate = round(($taxAmount / $amount) * 100, 2);
             }
             $orderLines[] = [

Frank-Magmodules avatar Oct 03 '22 06:10 Frank-Magmodules

Hi Frank,

Thanks for your suggention: && $amount still throws the error, but this works:

if ($taxAmount && $amount != 0) {

I just updated my code and I that I'm now redirected to Klarna. Thanks!

gerben86 avatar Oct 03 '22 18:10 gerben86

Hi @gerben86 ,

We are happy to share that we've just released the new 2.18.0 version where we have fixed this issue.
Thank you for opening this issue and for the detailed issue report.

We are closing this issue now but please feel free to reopen the issue if this still occurs.

Frank-Magmodules avatar Nov 04 '22 08:11 Frank-Magmodules