> ## 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 Order

> Completes checkout and places an order with encrypted payment information

## Overview

Completes the checkout process by placing an order with the merchant. This endpoint requires an existing cart with items and shipping information.

## 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., "staging.luma.gift")
</ParamField>

## Request Body

<ParamField body="encrypted_card" type="string" required>
  JWE-encrypted credit card data using the public key from [Get Public Key](/api-reference/payment/get-public-key) endpoint
</ParamField>

<ParamField body="billing_info" type="object" required>
  Billing address information

  **Required fields:**

  * `first_name` (string): Customer's first name
  * `last_name` (string): Customer's last name
  * `email` (string): Email address
  * `phone` (string): Phone number
  * `address1` (string): Primary address line
  * `city` (string): City name
  * `state_or_province` (string): State/province code
  * `country` (string): Country name or code
  * `postal_code` (string): ZIP or postal code

  **Optional fields:**

  * `address2` (string): Secondary address line
  * `company` (string): Company name
</ParamField>

<ParamField body="captcha_token" type="string">
  Captcha verification token when required by merchant
</ParamField>

## Response

Returns an order confirmation object with:

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

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

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

<ResponseField name="total" type="object">
  Final order total with currency information
</ResponseField>

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

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

## Credit Card Encryption

The credit card must be encrypted as a JWE token with the following structure:

```json theme={null}
{
  "number": "4111111111111111",
  "name": "John Smith",
  "verification_value": "123",
  "month": "08",
  "year": "2025"
}
```

## Code Example

```javascript theme={null}
// 1. Get public key
const keyResponse = await fetch('https://cc.firmly.work/api/v1/payment/key');
const publicKey = await keyResponse.json();

// 2. Encrypt card data (using jose or similar library)
const encryptedCard = await encryptCardData(cardData, publicKey);

// 3. Complete order
const response = await fetch('https://cc.firmly.work/api/v1/payment/domains/staging.luma.gift/complete-order', {
  method: 'POST',
  headers: {
    'x-firmly-authorization': authToken,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    encrypted_card: encryptedCard,
    billing_info: {
      first_name: 'John',
      last_name: 'Smith',
      email: 'john@staging.luma.gift',
      phone: '2065551212',
      address1: '123 Main St',
      city: 'Seattle',
      state_or_province: 'WA',
      country: 'US',
      postal_code: '98101'
    }
  })
});

const order = await response.json();
```

## Prerequisites

Before calling this endpoint:

1. Cart must have at least one item
2. Shipping information must be set
3. Shipping method must be selected

## Error Responses

| Code                             | Description                      |
| -------------------------------- | -------------------------------- |
| `ErrorInvalidInputBody`          | Request validation failed        |
| `ErrorMissingRequiredParameters` | Cart missing required data       |
| `ErrorCartNotFound`              | No cart found for domain         |
| `ErrorPaymentDeclined`           | Payment was declined             |
| `ErrorStoreUnavailable`          | Merchant temporarily unavailable |

## Related Endpoints

* [Get Public Key](/api-reference/payment/get-public-key) - Get encryption key
* [Set Shipping Info](/api-reference/checkout/set-shipping-info) - Add delivery address
* [Add Line Item](/api-reference/simple-cart-api/cart/add-item) - Add products to cart
