wallee-payment / woocommerce

Wallee integration for WooCommerce
https://wallee.com
Apache License 2.0
5 stars 6 forks source link

Bug with coupons activated still exists #29

Open snmabaur opened 1 year ago

snmabaur commented 1 year ago

Hi

we were in contact 3 days ago with this ticket #28

Unfortunaltey your solution didn't work and now we get the following error

Is there an update available for your plugin? We are missing a lot of payments because people can't pay at the moment

Thank you

Bildschirmfoto 2023-06-15 um 09 32 22

snmabaur commented 1 year ago

This is my log file from today

2023-06-15T07:31:33+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:31:33.81Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:31:33.810Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:31:35+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:31:35.542Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:31:35.542Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:36:05+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:36:05.181Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:36:05.181Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:36:07+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:36:07.33Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:36:07.330Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:37:16+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:37:16.652Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:37:16.652Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:37:18+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:37:18.531Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:37:18.531Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:42:01+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:42:01.795Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:42:01.795Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:42:03+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:42:03.393Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:42:03.393Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:43:58+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:43:58.113Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:43:58.113Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:43:59+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:43:59.823Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:43:59.823Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:48:29+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:48:29.75Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:48:29.750Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:48:31+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:48:31.52Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:48:31.520Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:48:35+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:48:35.258Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:48:35.258Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:48:38+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:48:38.885Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:48:38.885Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:48:42+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:48:42.908Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:48:42.908Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
2023-06-15T07:49:07+00:00 DEBUG Error 442 connecting to the API (https://app-wallee.com/api/transaction/create?spaceId=5353) : {"date":"2023-06-15T07:49:07.438Z","defaultMessage":"The line item discount must have the same sign as the line item amount.","id":"NDr2xV3lnPSkEW1A9vFg8dduO235Z4T3k3lGFb0DK-c (2023-06-15T07:49:07.438Z)","message":"The line item discount must have the same sign as the line item amount.","type":"DEVELOPER_ERROR"}
theodorspringwallee commented 1 year ago

Dear snmabaur

We still have one open BUG, that let the payment methods disappear, when a coupon as well a tax is defined on the order.

If the deactivation of the line item consistency didn't work for you, I think the only way is to wait for the BUG fix.

Please also consider, that we are only compatible with the WooCommerce Standard Coupons as well the Smart Coupon Plugin.

If you are using some other coupon or product plugins, which could change the product object structure, compared to the WooCommerce standard environment, this also could be an issue for the current issue you got.

We will let you know as soon the BUG fix has been published.

Best regards

snmabaur commented 1 year ago

Do you have a timeline when this bug should be fixed?

We use PDF Product Vouchers from SkyVerge and the normals Woocommerce Coupons... the problems exist with both of them

But then we wait until the bugfix will be published

Thanks

philb74 commented 1 year ago

We are experiencing the exact same issue.

Here's what I've discovered so far: The problem occurs only when there is a single line item in the cart. However, when we have at least two line items per product, everything functions as expected.

I would greatly appreciate a hotfix, even if it means I have to implement it directly into the currently running plugin myself.

Thanks! Phil

philb74 commented 1 year ago

Hi @snmabaur,

is there an ETA when this bug with a single line item together with a coupon code in cart gets fixed?

snmabaur commented 1 year ago

@philb74 I also would like to know if there is an ETA :) Is there one @theodorspringwallee ?

mschaer commented 1 year ago

@snmabaur @theodorspringwallee Any news in this case? We are experiencing the exact same issue and waiting desperately for a bugfix.

theodorspringwallee commented 1 year ago

Dear mschaer

According to our product owner, we will work on this developer sprint. So it probably will be finished after 2 weeks.

Best regards.

theodorspringwallee commented 1 year ago

Dear mschaer, snmabaur, philb74

I had right now a talk with our developers, and they can't reproduce the mentioned issue in the newest plugin version and without the line item consistency option.

To provide you optimal support on this, please can you create a ticket by writing to info@wallee.com, that we can take a more in deep look on your shop systems. This can help us to identify possible issues, we don't see on our developer instances.

Many thanks for your cooperation.

Best regards

ausov commented 11 months ago

Dear contributors!

The issue might be caused by lost precision when using a rounded tax value in calculations.

See \WC_Wallee_Service_Line_Item::create_product_line_items_from_session lines 98-99 on current master:

$amount_including_tax = $values['line_subtotal'] + $values['line_subtotal_tax'];
$discount_including_tax = $values['line_total'] + $values['line_tax'];

Here $values['line_subtotal_tax'] are already rounded to 2 digits!

Example fix using raw tax data from $values['line_tax_data']:

$subtotal_tax = array_sum($values['line_tax_data']['subtotal']);
$total_tax = array_sum($values['line_tax_data']['total']);
$amount_including_tax = $values['line_subtotal'] + $subtotal_tax;
$discount_including_tax = $values['line_total'] + $total_tax;

The same issue is obviously in \WC_Wallee_Service_Line_Item::create_product_line_items_from_order. There you can obtain precise tax data from $item->get_taxes().

Another possibly dangerous place to check - it seems masking this issue by using abs() on incorrectly calculated discount when value becomes negative and therefore submitting wrong data to Wallee API. See: class-wc-wallee-service-line-item.php:380:

$discount = abs($amount_including_tax - $discount_including_tax - $coupon_discount);

Hope this helps...