Open janoschbatschi opened 3 years ago
Obviously, the CartTaxFreeTotal is calculated wrong. If I use the standard Isotope checkout everything works correctly. Using KlarnaCheckout it throws the bad_value error. It seems to be depending on the shipping (taxes or not) and depending on the rules (whole cart or individual items). Once the order_tax_amount
is correct but than the order_amount
throws the bad value error.
For me following workaround seems to work (KlarnaCheckout.php):
'order_tax_amount' => (int) round(($this->cart->getSubTotal() - $this->cart->getTaxFreeSubTotal()) / $this->cart->getSubTotal() * ($this->cart->getTotal()-$this->cart->getShippingMethod()->price) * 100, 0),
OrderLine.php -> addTotalDiscountAmountForItem()
$this->total_discount_amount += ($surcharge->total_price * (-1));
instead of
$this->total_discount_amount += ($surcharge->getAmountForCollectionItem($this->item) * (-1));
The issue seems to be due to the standard tax (13%) being included in the product. For foreign customers, a different tax is added (e.g. 20%). Klarna complains because the total amount correctly has the 20% tax calculated and the product itself still has 13%. E.g. the formula Klarna checks (https://developers.klarna.com/documentation/klarna-payments/in-depth-knowledge/tax-handling/) is not correct anymore.
Another problem occurs if in the Isotope config the "Preisanzeige" is changed from "Brutto" to "Festgelegt". Then the calculation is also wrong.
Whenever a rule is applied, an error is thrown:
KCO error: BAD_VALUE: Bad value: order_tax_amount (must be greater than or equal to 0)
Independent of if the rule is applied to subtotal or to each product.
This seems to be due to the cart_total being smaller than the cart_taxFreeTotal which leads to a negative value for order_tax_amount which is not allowed near https://github.com/richardhj/isotope-klarna-checkout/blob/c1c81094a8376a85a8a1328a3685209c115f6a44/src/Module/KlarnaCheckout.php#L244 and in the other classes where order_tax_amount is manipulated.