richardhj / isotope-klarna-checkout

Klarna Checkout for Isotope eCommerce (replaces Isotope's entire checkout).
GNU Lesser General Public License v3.0
3 stars 4 forks source link

Not possible to apply rules #10

Open janoschbatschi opened 3 years ago

janoschbatschi commented 3 years ago

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.

Example: 
    Zwischensumme           € 27,00  
    davon Umsatzsteuer  13% € 3,11   
    Versand (Pauschalversand)   € 10,00  
    Gutschein           € -20,00     
    Bestellsumme            € 17,00 

CartTotal: 17€ 
CartTaxFreeTotal: 37€ (27€+10€)
janoschbatschi commented 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));

janoschbatschi commented 3 years ago

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.