Klarna Checkout error "Bad value: total_tax_amount"

Hi,

We get error message from Klarna Addon when loading the checkout page while having an active campaign that reduces the price for multiple order rows with a percentage. It seems like there is something off with the calculations, maybe a rounding error?

We’re using the latest version of the add-on but with an old (5.6.10) version of Litium & Accelerator.

Any ideas on what to look for?

Messages: Error when calling POST https://api.playground.klarna.com/checkout/v3/orders/a4d1aebf-3d59-658d-965d-75e0d91b11be.
Exception: Klarna.Rest.Core.Commuication.ApiException, Klarna.Rest.Core, Version=3.1.12.0, Culture=neutral, PublicKeyToken=a952321ed6e24c14
HttpStatusCode : BadRequest
Klarna API error messages:
{
  "error_code": "BAD_VALUE",
  "error_messages": [
    "Bad value: total_tax_amount"
  ],
  "correlation_id": "315da2dd-4582-4f4e-9880-fe18b28dfae5"
}
   at Klarna.Rest.Core.Communication.BaseRestClient.<ThrowIfError>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Klarna.Rest.Core.Communication.BaseRestClient.<MakeRequest>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Klarna.Rest.Core.Communication.BaseRestClient.<Post>d__4`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Klarna.Rest.Core.Store.CheckoutStore.<UpdateOrder>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Litium.AddOns.Klarna.Common.AsyncHelper.RunSync[TResult](Func`1 func)
   at Litium.AddOns.Klarna.Kco.LitiumKcoApi.CreateOrUpdateKcoOrder(OrderCarrier orderCarrier, ExecutePaymentArgs args)

Litium version: 5.6.10

It seems like our Litium application is sending (to Klarna) a negative value for the total_tax_amount as part of the “Rounding off” order item as part of the Create Order request:

"order_lines": [
  ...
  {
    "type": "physical",
    "reference": "1",
    "name": "Rounding off",
    "quantity": 1,
    "quantity_unit": "nos",
    "unit_price": 0,
    "tax_rate": 0,
    "total_amount": 0,
    "total_discount_amount": 0,
    "total_tax_amount": -2
  }
]

This is what the Klarna documentation says aboyt the total_tax_amount field:

“Must be within ±1 of total_amount - total_amount * 10000 / (10000 + tax_rate). Negative when type is discount.”
(https://developers.klarna.com/api/#checkout-api__create-a-new-order__order_lines__total_tax_amount)

So the values above won’t pass the validation: total_amount - total_amount * 10000 / (10000 + tax_rate) == 0 - 0 * 10000 / (10000 + 0) == 0 which is not within ±1 of 2.

Can anyone clarify this? Why is this happening and how can we solve this?

This is an know issue and is fixed in the supported Litium versions.