> ## Documentation Index
> Fetch the complete documentation index at: https://developers.firmly.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Complete Klarna Order

> Finalizes the order using the Klarna authorization token

## Overview

Completes the checkout process by placing an order with the merchant using the Klarna authorization. This is the final step in the Klarna checkout flow. The endpoint validates the authorization token, places the order, and returns the order confirmation with the merchant's order number.

<Note>
  If the authorize step was skipped, this endpoint will automatically call authorize before completing the order, as long as the `authorization_token` is provided.
</Note>

## Authentication

<ParamField header="x-firmly-authorization" type="string" required>
  Device authentication token from Browser Session
</ParamField>

## Path Parameters

<ParamField path="domain" type="string" required>
  The merchant domain (e.g., "merchant.example.com")
</ParamField>

## Request Body

<ParamField body="attributes" type="object" required>
  Klarna payment attributes

  <Expandable title="Attributes">
    <ParamField body="authorization_token" type="string" required>
      The Klarna authorization token. Can be provided here or retrieved from the session if the authorize endpoint was already called.
    </ParamField>
  </Expandable>
</ParamField>

## Response

Returns the order confirmation object.

<ResponseField name="cart_id" type="string">
  Unique identifier for the cart
</ResponseField>

<ResponseField name="platform_order_number" type="string">
  The order number from the merchant platform
</ResponseField>

<ResponseField name="cart_status" type="string">
  Status of the cart (e.g., "submitted")
</ResponseField>

<ResponseField name="submitted_at" type="string">
  ISO timestamp when the order was submitted
</ResponseField>

<ResponseField name="display_name" type="string">
  Merchant's display name
</ResponseField>

<ResponseField name="platform_id" type="string">
  E-commerce platform identifier (e.g., "magento", "shopify")
</ResponseField>

<ResponseField name="shop_id" type="string">
  Merchant domain
</ResponseField>

<ResponseField name="urls" type="object">
  Relevant URLs for the order

  <Expandable title="URLs">
    <ResponseField name="thank_you_page" type="string">
      URL to the merchant's order confirmation page
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="line_items" type="array">
  Array of items in the order

  <Expandable title="Line Item Details">
    <ResponseField name="line_item_id" type="string">
      Unique identifier for the line item
    </ResponseField>

    <ResponseField name="sku" type="string">
      Product SKU
    </ResponseField>

    <ResponseField name="quantity" type="number">
      Quantity ordered
    </ResponseField>

    <ResponseField name="description" type="string">
      Product description
    </ResponseField>

    <ResponseField name="price" type="object">
      Unit price
    </ResponseField>

    <ResponseField name="line_price" type="object">
      Total price for this line item
    </ResponseField>

    <ResponseField name="image" type="object">
      Product image information
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="shipping_info" type="object">
  Delivery address details
</ResponseField>

<ResponseField name="billing_info" type="object">
  Billing address details
</ResponseField>

<ResponseField name="shipping_method" type="object">
  Selected shipping method with pricing
</ResponseField>

<ResponseField name="payment_summary" type="object">
  Summary of the Klarna payment

  <Expandable title="Payment Summary">
    <ResponseField name="payment_type" type="string">
      Always `"Klarna"` for this gateway
    </ResponseField>

    <ResponseField name="attributes" type="object">
      Klarna session details

      <Expandable title="Attributes">
        <ResponseField name="session_id" type="string">
          Klarna payment session identifier
        </ResponseField>

        <ResponseField name="authorization_token" type="string">
          The authorization token used for this order
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="total" type="object">
  Grand total including all costs
</ResponseField>

<ResponseField name="sub_total" type="object">
  Subtotal before shipping and tax
</ResponseField>

<ResponseField name="shipping_total" type="object">
  Shipping cost
</ResponseField>

<ResponseField name="tax" type="object">
  Tax amount
</ResponseField>

<ResponseField name="cart_discount" type="object">
  Total discount applied
</ResponseField>

## Code Example

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://cc.firmly.work/api/v1/domains/merchant.example.com/express/klarna/complete-order',
    {
      method: 'POST',
      headers: {
        'x-firmly-authorization': authToken,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        attributes: {
          authorization_token: 'klarna_auth_token_from_widget'
        }
      })
    }
  );

  const order = await response.json();
  console.log('Order number:', order.platform_order_number);

  // Redirect to thank you page
  if (order.urls?.thank_you_page) {
    window.location.href = order.urls.thank_you_page;
  }
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://cc.firmly.work/api/v1/domains/merchant.example.com/express/klarna/complete-order',
      headers={
          'x-firmly-authorization': auth_token,
          'Content-Type': 'application/json'
      },
      json={
          'attributes': {
              'authorization_token': 'klarna_auth_token_from_widget'
          }
      }
  )

  order = response.json()
  print(f"Order placed: {order['platform_order_number']}")
  print(f"Thank you page: {order['urls']['thank_you_page']}")
  ```

  ```bash cURL theme={null}
  curl -X POST https://cc.firmly.work/api/v1/domains/merchant.example.com/express/klarna/complete-order \
    -H "x-firmly-authorization: YOUR_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"attributes": {"authorization_token": "klarna_auth_token_from_widget"}}'
  ```
</CodeGroup>

## Response Example

```json theme={null}
{
  "cart_id": "9cf76530-1344-420f-9ca6-c7a96fb6db45",
  "platform_order_number": "6800018416",
  "cart_status": "submitted",
  "submitted_at": "2024-07-22T18:58:25.000Z",
  "display_name": "Example Store",
  "platform_id": "magento",
  "shop_id": "merchant.example.com",
  "urls": {
    "thank_you_page": "https://merchant.example.com/checkout/onepage/success/"
  },
  "line_items": [
    {
      "line_item_id": "3e66bef5-43f5-4a80-8957-91c5c8233163",
      "sku": "MT12",
      "quantity": 1,
      "description": "Cassius Sparring Tank",
      "price": {
        "currency": "USD",
        "value": 18,
        "number": 1800,
        "symbol": "$"
      },
      "line_price": {
        "currency": "USD",
        "value": 18,
        "number": 1800,
        "symbol": "$"
      },
      "image": {
        "url": "https://merchant.example.com/pub/media/catalog/product/mt12-blue_main.jpg"
      }
    }
  ],
  "shipping_info": {
    "first_name": "John",
    "last_name": "Smith",
    "email": "john@example.com",
    "phone": "(206) 555-1212",
    "address1": "123 Main St",
    "city": "Seattle",
    "state_or_province": "Washington",
    "country": "US",
    "postal_code": "98101"
  },
  "billing_info": {
    "first_name": "John",
    "last_name": "Smith",
    "email": "john@example.com",
    "phone": "(206) 555-1212",
    "address1": "123 Main St",
    "city": "Seattle",
    "state_or_province": "Washington",
    "country": "US",
    "postal_code": "98101"
  },
  "shipping_method": {
    "id": "s2_2_day",
    "description": "2-Day Shipping",
    "price": {
      "currency": "USD",
      "value": 12,
      "number": 1200,
      "symbol": "$"
    }
  },
  "payment_summary": {
    "payment_type": "Klarna",
    "attributes": {
      "session_id": "kp_abc123def456",
      "authorization_token": "klarna_auth_token_from_widget"
    }
  },
  "total": {
    "currency": "USD",
    "value": 32,
    "number": 3200,
    "symbol": "$"
  },
  "sub_total": {
    "currency": "USD",
    "value": 18,
    "number": 1800,
    "symbol": "$"
  },
  "shipping_total": {
    "currency": "USD",
    "value": 12,
    "number": 1200,
    "symbol": "$"
  },
  "tax": {
    "currency": "USD",
    "value": 2,
    "number": 200,
    "symbol": "$"
  },
  "cart_discount": {
    "currency": "USD",
    "value": 0,
    "number": 0,
    "symbol": "$"
  }
}
```

## Error Responses

| Code                         | Description                             |
| ---------------------------- | --------------------------------------- |
| `ErrorCartNotFound`          | No active cart for this domain          |
| `ErrorBadRequest`            | Missing `authorization_token`           |
| `ErrorGatewayNotFound`       | Klarna is not enabled for this merchant |
| `ErrorPaymentDeclined`       | Klarna declined the payment             |
| `ErrorCheckout`              | Checkout failed at the merchant         |
| `ErrorMissingShippingMethod` | No shipping method selected             |
| `ErrorMissingTaxSync`        | Tax has not been calculated             |
| `ErrorStoreUnavailable`      | Merchant temporarily unavailable        |

## Related Endpoints

* [Start Klarna Checkout](/api-reference/payment/express-checkout/start-klarna) - Create Klarna session
* [Authorize Klarna Checkout](/api-reference/payment/express-checkout/authorize-klarna) - Confirm authorization
* [Complete Order (Credit Card)](/api-reference/payment/complete-order-v1) - Alternative credit card flow
