> ## Documentation Index
> Fetch the complete documentation index at: https://firmly.mintlify.site/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]
>
> Klarna has two client flows, selected per merchant. **Widget flow**: [Start](https://firmly.mintlify.site/api-reference/payment/express-checkout/start-klarna.md) returns a `client_token`, the Klarna Payments SDK produces an `authorization_token`, and you send it here. **Redirect flow**: Start returns a `url` instead; the buyer completes Klarna there and is sent back to the return URL with a `redirectResult` query parameter, which you send here as `transaction_token`. Send exactly one of the two.

## Authentication

**x-firmly-authorization** `string` *required*

Device authentication token from Browser Session

## Path Parameters

**domain** `string` *required*

The merchant domain (e.g., "merchant.example.com")

## Request Body

**attributes** `object` *required*

Klarna payment attributes

**Attributes**

**authorization\_token** `string`

Widget flow. The Klarna authorization token from the Klarna Payments SDK. Can be provided here or retrieved from the session if the authorize endpoint was already called. Required unless `transaction_token` is sent.

**transaction\_token** `string`

Redirect flow. The `redirectResult` value from the query string of the return URL after the buyer completes Klarna. URL-encoded values are accepted. Required unless `authorization_token` is sent.

**redirect\_result** `string` *deprecated*

Deprecated alias of `transaction_token`.

## Response

Returns the order confirmation object.

**cart\_id** `string`

Unique identifier for the cart

**platform\_order\_number** `string`

The order number from the merchant platform

**cart\_status** `string`

Status of the cart (e.g., "submitted")

**submitted\_at** `string`

ISO timestamp when the order was submitted

**display\_name** `string`

Merchant's display name

**platform\_id** `string`

E-commerce platform identifier (e.g., "magento", "shopify")

**shop\_id** `string`

Merchant domain

**urls** `object`

Relevant URLs for the order

**URLs**

**thank\_you\_page** `string`

URL to the merchant's order confirmation page

**line\_items** `array`

Array of items in the order

**Line Item Details**

**line\_item\_id** `string`

Unique identifier for the line item

**sku** `string`

Product SKU

**quantity** `number`

Quantity ordered

**description** `string`

Product description

**price** `object`

Unit price

**line\_price** `object`

Total price for this line item

**image** `object`

Product image information

**shipping\_info** `object`

Delivery address details

**billing\_info** `object`

Billing address details

**shipping\_method** `object`

Selected shipping method with pricing

**payment\_summary** `object`

Summary of the Klarna payment

**Payment Summary**

**payment\_type** `string`

Always `"Klarna"` for this gateway

**attributes** `object`

Klarna session details

**Attributes**

**session\_id** `string`

Klarna payment session identifier

**authorization\_token** `string`

The authorization token used for this order

**total** `object`

Grand total including all costs

**sub\_total** `object`

Subtotal before shipping and tax

**shipping\_total** `object`

Shipping cost

**tax** `object`

Tax amount

**fees** `array`

Merchant-imposed fees (e.g. recycle, regulatory), if any

**fee\_total** `object`

Total of all fees

**cart\_discount** `object`

Total discount applied

## Code Example

```javascript JavaScript theme={null}
const response = await fetch(
  'https://api.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://api.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://api.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"}}'
```

## 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": 34,
    "number": 3400,
    "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": "$"
  },
  "fees": [
    {
      "description": "Recycle fee",
      "currency": "USD",
      "value": 2,
      "number": 200,
      "symbol": "$"
    }
  ],
  "fee_total": {
    "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` | Neither `authorization_token` (widget flow) nor `transaction_token` (redirect flow) was provided |
| `ErrorGatewayNotFound` | Klarna is not enabled for this merchant |
| `ErrorPaymentMethodNotAvailable` | Klarna is not available for this cart |
| `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 |
| `ErrorRateLimited` | Too many requests |

## Related Endpoints

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.