When I add a configurable product to the map and go to the second checkout step and after loading it again I reload it, I get this error: 'Order line totals do not total order_amount - 17311 != 17310'

This error is from the method validate that is in the file: vendor/klarna/module-kp/Model/Api/Request/Builder.php


    public function validate($requiredAttributes, $type)
    $missingAttributes = [];
    foreach ($requiredAttributes as $requiredAttribute) {
        if (null === $this->$requiredAttribute) {
            $missingAttributes[] = $requiredAttribute;
        if (is_array($this->$requiredAttribute) && count($this->$requiredAttribute) === 0) {
            $missingAttributes[] = $requiredAttribute;
    if (!empty($missingAttributes)) {
        throw new KlarnaApiException(
                'Missing required attribute(s) on %1: "%2".',
                implode(', ', $missingAttributes)
    $total = 0;
    foreach ($this->orderlines as $orderLine) {
        $total += (int)$orderLine->getTotal();

    if ($total !== $this->order_amount) {
        throw new KlarnaApiException(
            __('Order line totals do not total order_amount - %1 != %2', $total, $this->order_amount)

    return $this;

I get into the method validate from here vendor/klarna/module-kp/Model/Api/Builder/Kasper.php


    private function generateCreateUpdate()
    $requiredAttributes = [

    /** @var \Magento\Quote\Model\Quote $quote */
    $quote = $this->getObject();
    $store = $quote->getStore();
    $options = array_map('trim', array_filter($this->configHelper->getCheckoutDesignConfig($store)));

     * Pre-fill customer details
    $this->prefillAddresses($quote, $store);

    $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();

    $tax = $address->getBaseTaxAmount();
    if ($this->configHelper->isFptEnabled($store) && !$this->configHelper->getDisplayInSubtotalFpt($store)) {
        $fptResult = $this->rate->getFptTax($quote);
        $tax += $fptResult['tax'];

    $country = $address->getCountryId();
    if ($country === null) {
        $country = $this->directoryHelper->getDefaultCountry($store);
        ->setLocale(str_replace('_', '-', $this->configHelper->getLocaleCode()))
        ->validate($requiredAttributes, self::GENERATE_TYPE_CREATE);

    return $this;

My problem is that ($total !== $this->order_amount) = true I always have a difference of 1.

But I can't figure out why this is happening and how to fix it. Tell me, please, what could be the problem and how to fix it? If suddenly someone faced this behavior, how did you fix it?

  • This is really strange logic convert each line item to int. Imagine A = 0.01 and B = 0.99. Total = 1.00, (int)0.01 + (int)0.99 = 0. Total with this logic can be different from Magento Total. Aug 13, 2022 at 20:17
  • Did you find a solution to this?
    – codedge
    Sep 29, 2022 at 14:19
  • Yes, I found. Today I don't have free time to describe what I did, but I can do it tomorrow morning @codedge Sep 29, 2022 at 15:23
  • That would be great. Thanks @DavidYoung
    – codedge
    Sep 29, 2022 at 19:50
  • @codedge you can check out my answer to this problem, I didn't describe it in code snippets because for me this is an exceptional problem that hasn't happened anywhere else. Sep 30, 2022 at 12:25

2 Answers 2


I found a solution to this problem.

In my case, this was due to the fact that I have a very strong modification of the current types of products: configurable and bundle, in particular.

Because of these modifications, I was getting this behavior because the pricing was changed and the price was affected by the logic that applies to my modified products.

If you do not have modified products, there are no custom product types, then my case will not suit you, but it can lead to the right solution in search of a problem.

And so, I found the problem in the class: Klarna\Core\Model\Checkout\Orderline\Items, methods: collect and processItem, shouldSkip.

  1. In the method collect i had a problem that shouldSkip missed the products needed for pricing, therefore, I had to modify this method for the changed logic.
  2. In the method processItem I had to change the logic that relates to getting data like: total_amount, unit_price
  3. You need to check that in the processItem everything was correct so that the products that need to be skipped for pricing are skipped.

After these changes, checking in the file no longer gave an error: vendor/klarna/module-kp/Model/Api/Request/Builder.php

I want to reiterate, my case is an exception, I don't claim that this is the right way to fix the problem, but it worked for me.

  • Seems like a very special case, but thanks for explaining.
    – codedge
    Sep 30, 2022 at 16:19
  • Yes it is @codedge Oct 3, 2022 at 11:37


private function processItem($product, $item, $qtyMultiplier)

Modify the processItem function

private function processItem($product, $item, $qtyMultiplier)

    if ($this->klarnaConfig->isSeparateTaxLine($item->getStore())) {
    } else {
          $_item['total_amount'] = $this->helper->toApiFloat(
           ($item->getBaseRowTotal() - $item->getBaseDiscountAmount()) + $item->getBaseTaxAmount()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.