MultiSafepay / magento2

MultiSafepay plugin for Magento 2
Open Software License 3.0
19 stars 8 forks source link

Divided by zero error: payment not possible #11

Closed jdereus87 closed 2 years ago

jdereus87 commented 3 years ago

After upgrading all MSP packages to their newest version I am running into the following error when trying to submit an order.

2021-04-02 08:25:46] MultiSafepay.ERROR: (Order ID: 1000071989) ERROR: Warning: Division by zero in /data/web/magento2/vendor/multisafepay/magento2-core/Model/Api/Builder/OrderRequestBuilder/ShoppingCartBuilder/CustomTotalBuilder.php on line 156 (code: 0, line: 61, file: /data/web/magento2/vendor/magento/framework/App/ErrorHandler.php)

Local dockerbox, Magento 2.3.6

If needed I can run the file through xdebug, but some pointers on where to start would be helpful.

vinodsowdagar commented 3 years ago

Hi @jdereus87 ,

Thank you for the report.

It seems there is an issue with a custom Total in your shop, where we try to retrieve the TaxRate through the TaxAmount. We have not accounted for totals with this value being 0. I have put this issue on the backlog for fixing. It will probably be picked up from next week.

When we have released the fix for this i will let you know.

The latest version also makes it possible to disable the shopping cart, including the retrieving of the custom totals for certain payment methods. Which payment methods are you planning to use?

jdereus87 commented 3 years ago

@Vinod-MultiSafepay

Thank you for the quick reply.

First to answer your question, the client wants to use:

My question:

  1. What do these $total->getValue() actually represent? Since you said there might be an issue with the shop, this would be helpful information for me.
  2. What do you mean by disabling the cart including retrieving custom totals?
  3. I do see an if($total-<getValue()) statement on the line before, not sure why that does not filter out the zero value.
jdereus87 commented 3 years ago

@Vinod-MultiSafepay

I made some progress on this issue. Since the MSP 2+ version was not working for my client's shop I decided to switch back to the MSP 1 version. Here also I got an error: Class MultiSafepay\PaymentFee\Helper\Data does not exist.

I ran it through xdebug and it was retrieving a float with value "0.00000" in $order->getPaymentFee in Model/Connect.php. (code payment_fee). Since we recently installed the Mageprince_Payementfee, i removed this module. The error persisted. However after manually clearing up the db columns this module has set (5 tables, 4 columns), the MSP v1 worked again. The float mentioned is the mageprince default value for payment_fee values. The old MSP sees this values and triggers object creation of the class above (which does not exist).

After that I removed the MSP v1 module and re-installed the latest V2. It now works again. When setting a marker on line 156 in CustomTotalBuilder it now does not catch anything, thus the problem is solved. Payments with the test merchant are also working correctly again.

Solution: Remove MagePrince/PaymentFee and clear DB tables of its installschema. Mageprince module version used: 2.1.3

Hope this helps you in further development / testing.

vinodsowdagar commented 3 years ago

Hi @jdereus87 ,

Thank you for the feedback. I am glad this issue has been solved for you.

We have also found that the value "0.00000" returns true instead of false, but we still consider it an empty value. So instead of if ($total->getValue()) we are going to change it to if (empty($total->getValue())) and that should also fix the same type of issues happening in the future.

For now i will close this issue. If you have any more questions or comments, feel free to reopen this issue or create a new one.

bojandavkov commented 2 years ago

@Vinod-MultiSafepay Is this issue fixed, since i`m having exactly the same issue on my shop? version: "multisafepay/magento2": "^2.11"

vinodsowdagar commented 2 years ago

Hi @bojandavkov ,

I have reopened this issue to check this out again. When we have confirmed it or if we have questions, we will let you know.

vinodsowdagar commented 2 years ago

Hi @bojandavkov ,

It could be that the total value in your case is something like '0.0'. In that case the issue would still occur.

I have created a fix for this which is currently internally in review. When this has been released i will let you know.

vinodsowdagar commented 2 years ago

Hi @bojandavkov ,

This issue should be fixed by now. Therefore i am closing this. If there are still questions, please feel free to place a comment.