# Order Summary

> The checkout sidebar with line items, discount codes and totals. Handles estimated taxes, unknown shipping and prices that changed since the cart was built.

Canonical: https://hextaui.com/blocks/order-summary
Last updated: 2026-10-29

## Overview

OrderSummary is the column next to a checkout form. It takes a Cart in the same shape the cart block uses and shows each line with a small thumbnail, a quantity badge on the image corner, the variant and the line total. Lists longer than five lines fold behind “Show 3 more”, so the totals stay in view.

Totals come in the order shoppers expect: subtotal, one line per discount with its code as a chip, shipping, taxes and the total with its currency code, “USD $339.78”. Shipping reads “Calculated at next step” until you know it, shows a skeleton while it is being worked out and reads Free when it costs nothing. Taxes are labelled Estimated until you mark them final, with an optional basis such as “Estimated for 94110”. Store sales, discounts and free shipping add up to a “You saved” line.

Discount codes sit behind an “Add discount code” link. Codes are trimmed and uppercased, the Apply button turns into a spinner and then a check, and applied codes become chips you can remove. Automatic discounts show as chips without a remove button. Throw from onApplyCode and your message appears under the field. DiscountCodeError builds the common ones: expired with the date, the amount still needed to reach a minimum, codes that can’t be combined, and codes that don’t exist. The block catches codes that are already applied and the code limit without calling you.

Every amount uses Price, so when a code lands only the digits that changed roll, and nothing counts up on first render. New discount and savings lines grow in before their text fades in. If a line’s price changed since the last render, the row flashes once and keeps a note such as “Price dropped to $58”. With collapsible set, phones get a “Show order summary” bar that keeps the total visible and flashes it when it changes.

## Installation

### Step 1: Get HextaUI Pro

One payment unlocks every block, including future ones. [See pricing](https://hextaui.com/pricing).

### Step 2: Add the Pro registry to components.json

```json title="components.json"
{
  "registries": {
    "@hextaui-pro": {
      "url": "https://hextaui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
      }
    }
  }
}
```

### Step 3: Add your token

Create a token on your [account page](https://hextaui.com/account) and put it in `.env.local` as `HEXTAUI_PRO_TOKEN`.

### Step 4: Add the block

```bash
npx shadcn@latest add @hextaui-pro/order-summary
```

## Usage

### Shopify discount codes

Send the full list of codes through cartDiscountCodesUpdate, refetch the cart and map it to Cart. Shopify accepts codes it can’t apply and marks them applicable: false, so the example removes those again and shows a specific error instead of a silent no-op.

```tsx
"use client"

import type { Cart } from "../cart/cart"
import { OrderSummary } from "@/components/blocks/order-summary/order-summary"
import { DiscountCodeError } from "@/components/blocks/order-summary/summary"

type ShopifyMoney = { amount: string; currencyCode: string }

type ShopifyCart = {
  id: string
  discountCodes: { code: string; applicable: boolean }[]
  discountAllocations: {
    discountedAmount: ShopifyMoney
    code?: string
    title?: string
  }[]
  cost: { subtotalAmount: ShopifyMoney; totalTaxAmount: ShopifyMoney | null }
  lines: {
    nodes: {
      id: string
      quantity: number
      cost: { amountPerQuantity: ShopifyMoney; compareAtAmountPerQuantity: ShopifyMoney | null }
      merchandise: {
        id: string
        title: string
        image: { url: string; altText: string | null } | null
        product: { id: string; title: string }
      }
    }[]
  }
}

const mutation = `
  mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]) {
    cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
      cart { id discountCodes { code applicable } }
      userErrors { field message }
    }
  }
`

function toCart(cart: ShopifyCart): Cart {
  return {
    id: cart.id,
    currencyCode: cart.cost.subtotalAmount.currencyCode,
    tax: cart.cost.totalTaxAmount,
    lines: cart.lines.nodes.map((line) => ({
      id: line.id,
      quantity: line.quantity,
      price: line.cost.amountPerQuantity,
      compareAtPrice: line.cost.compareAtAmountPerQuantity,
      merchandise: {
        id: line.merchandise.id,
        productId: line.merchandise.product.id,
        productTitle: line.merchandise.product.title,
        variantTitle: line.merchandise.title,
        image: line.merchandise.image
          ? {
              id: line.merchandise.image.url,
              src: line.merchandise.image.url,
              alt: line.merchandise.image.altText ?? "",
            }
          : undefined,
      },
    })),
    discounts: cart.discountAllocations.map((allocation) => ({
      code: allocation.code ?? allocation.title ?? "Discount",
      label: allocation.title,
      automatic: !allocation.code,
      amount: allocation.discountedAmount,
    })),
  }
}

export function ShopifyOrderSummary({
  cart,
  storefront,
  refetch,
}: {
  cart: ShopifyCart
  storefront: <T>(query: string, variables: Record<string, unknown>) => Promise<T>
  refetch: () => Promise<ShopifyCart>
}) {
  const codes = cart.discountCodes.map((item) => item.code)

  const update = async (discountCodes: string[]) => {
    const result = await storefront<{
      cartDiscountCodesUpdate: { userErrors: { message: string }[] }
    }>(mutation, { cartId: cart.id, discountCodes })
    const error = result.cartDiscountCodesUpdate.userErrors[0]
    if (error) throw new Error(error.message)
    return refetch()
  }

  return (
    <OrderSummary
      cart={toCart(cart)}
      collapsible
      onApplyCode={async (code) => {
        const next = await update([...codes, code])
        const added = next.discountCodes.find((item) => item.code.toUpperCase() === code)
        if (!added?.applicable) {
          await update(codes)
          throw DiscountCodeError.notFound(code)
        }
        return toCart(next)
      }}
      onRemoveCode={async (code) =>
        toCart(await update(codes.filter((item) => item !== code)))
      }
    />
  )
}
```

### Stripe promotion codes

Look up the promotion code on your server and turn Stripe’s restrictions into DiscountCodeError messages: the expiry date, or how much more the shopper needs to spend to reach the minimum amount.

```tsx
import { fromMinorUnits, toMinorUnits, type Money } from "../price/money"
import { DiscountCodeError } from "@/components/blocks/order-summary/summary"

type StripePromotionCode = {
  code: string
  active: boolean
  expires_at: number | null
  restrictions: { minimum_amount: number | null; minimum_amount_currency: string | null }
  coupon: { percent_off: number | null; amount_off: number | null; valid: boolean }
}

type StripeClient = {
  promotionCodes: {
    list: (params: { code: string; limit: number }) => Promise<{ data: StripePromotionCode[] }>
  }
}

export async function checkPromotionCode(
  stripe: StripeClient,
  code: string,
  subtotal: Money
): Promise<Money> {
  const { data } = await stripe.promotionCodes.list({ code, limit: 1 })
  const promotion = data[0]
  if (!promotion) throw DiscountCodeError.notFound(code)

  if (promotion.expires_at && promotion.expires_at * 1000 < Date.now()) {
    throw DiscountCodeError.expired(code, new Date(promotion.expires_at * 1000))
  }
  if (!promotion.active || !promotion.coupon.valid) {
    throw DiscountCodeError.notFound(code)
  }

  const minimum = promotion.restrictions.minimum_amount
  if (minimum && toMinorUnits(subtotal) < minimum) {
    throw DiscountCodeError.minimum(
      code,
      fromMinorUnits(minimum - toMinorUnits(subtotal), subtotal.currencyCode)
    )
  }

  const { percent_off, amount_off } = promotion.coupon
  const off = percent_off
    ? Math.round((toMinorUnits(subtotal) * percent_off) / 100)
    : (amount_off ?? 0)
  return fromMinorUnits(off, subtotal.currencyCode)
}
```

### With a server action

Next.js hides thrown error messages from server actions in production, so the action returns { ok: false, message } and the client throws it. The message then shows under the field, and a returned cart updates the totals right away.

```tsx
"use client"

import type { Cart } from "../cart/cart"
import { OrderSummary } from "@/components/blocks/order-summary/order-summary"

type DiscountResult =
  | { ok: true; cart: Cart }
  | { ok: false; message: string }

export function CheckoutSummary({
  cart,
  applyDiscount,
  removeDiscount,
}: {
  cart: Cart
  applyDiscount: (cartId: string, code: string) => Promise<DiscountResult>
  removeDiscount: (cartId: string, code: string) => Promise<DiscountResult>
}) {
  const run = async (result: Promise<DiscountResult>) => {
    const outcome = await result
    if (!outcome.ok) throw new Error(outcome.message)
    return outcome.cart
  }

  return (
    <OrderSummary
      cart={cart}
      shipping="pending"
      tax={{ amount: cart.tax ?? null, estimated: true, basis: "Estimated for your location" }}
      collapsible
      onApplyCode={(code) => run(applyDiscount(cart.id, code))}
      onRemoveCode={(code) => run(removeDiscount(cart.id, code))}
    />
  )
}
```

## Anatomy

The parts you compose, from the outside in.

| Part | Description |
| --- | --- |
| `OrderSummary` | Lines, discount code field, totals and the mobile summary bar. |
| `PromoCode` | The discount code link, field, error message and code chips. Works on its own in a cart drawer. |
| `OrderSummarySkeleton` | A loading placeholder with the same layout. |
| `DiscountCodeError` | An Error with a reason and helpers for specific messages: expired, minimum, combination, notFound, alreadyApplied, limit. |
| `getSummaryTotals` | The math behind the totals: discounts, shipping, tax, total and savings in minor units. |

## API reference

### OrderSummary

Also takes section props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `cart` | `Cart` | – | Lines, discounts and currency. Discounts with target "shipping" are listed under shipping. |
| `shipping` | `Money \| "pending" \| "calculating" \| "free"` | – | Shipping cost. Defaults to cart.shipping, or "pending" when that is empty. |
| `shippingMethod` | `string` | – | Shown under Shipping once the cost is known, such as “Standard · 3–5 business days”. |
| `tax` | `{ amount: Money \| null; estimated?: boolean; included?: boolean; calculating?: boolean; basis?: string }` | – | Taxes. estimated defaults to true. included shows “Including $X in taxes” under the total instead of adding it. |
| `onApplyCode` | `(code: string) => Promise<Cart \| void>` | – | Apply an uppercased, trimmed code. Throw to show the message under the field. Return a cart to show it before your own state updates. |
| `onRemoveCode` | `(code: string) => Promise<Cart \| void>` | – | Remove a code. The chip leaves right away and comes back if this throws. |
| `maxCodes` | `number` | `5` | How many codes one order can use. |
| `maxLines` | `number` | `4` | Lines shown before the rest fold behind “Show N more”. 0 shows every line. |
| `collapsible` | `boolean` | `false` | Below the md breakpoint, collapse the summary behind a bar that shows the total. |
| `open` | `boolean` | – | Whether the mobile summary is expanded, when controlled. |
| `defaultOpen` | `boolean` | `false` | Whether the mobile summary starts expanded. |
| `onOpenChange` | `(open: boolean) => void` | – | Called when the mobile bar is toggled. |
| `locale` | `Intl.LocalesArgument` | `"en-US"` | Locale for money. |
| `trailingZeros` | `boolean` | `true` | Set false to show $48 instead of $48.00. |
| `labels` | `Partial<OrderSummaryLabels>` | – | Every visible and announced string, plus promo for the PromoCode labels. |

### PromoCode

Also takes div props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `discounts` | `CartDiscount[]` | – | Applied codes and automatic discounts, shown as chips. |
| `onApply` | `(code: string) => unknown` | – | Apply a code. Throw an Error to show its message. A DiscountCodeError with reason "minimum" reads as a hint instead of an error. |
| `onRemove` | `(code: string) => unknown` | – | Remove a code. Without it, chips have no remove button. |
| `maxCodes` | `number` | `5` | How many codes one order can use. |
| `defaultOpen` | `boolean` | `false` | Start with the field shown instead of the link. |
| `disabled` | `boolean` | `false` | Disable the link and the field. |
| `labels` | `Partial<PromoCodeLabels>` | – | Words for the link, field, button, chips and announcements. |

### OrderSummarySkeleton

Also takes div props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `lines` | `number` | `3` | How many line placeholders to show. |
| `collapsible` | `boolean` | `false` | Match a collapsible summary: only the bar shows on phones. |

## Keyboard

| Key | Action |
| --- | --- |
| `Enter` | In the code field, apply the code. |
| `Escape` | In an empty code field, close it and return focus to the link. |
| `Backspace` | On a chip’s remove button, remove the code. Focus moves to the next chip. |
| `Space` `Enter` | On the summary bar or Show more, expand or collapse. |

## Accessibility

- Totals are a description list, so each amount is read with its label. Discounts read “Discount WELCOME10, minus $36.80”, and each line reads its quantity.
- Code errors are in a role="alert" region linked to the field with aria-describedby and aria-invalid. The text stays in the field and focus returns to it. Applied and removed codes, price changes and the new total are announced politely, the total after it settles.
- The mobile bar is a button with aria-expanded and aria-controls whose name includes the total. Collapsed content is hidden from screen readers and the tab order.
- Changes are never shown by color alone: price notes have text and an arrow, and flashes are decorative. With reduced motion, digits change without rolling and rows appear without growing.

## Built with

The free HextaUI components Order Summary is made from. Each one installs on its own.

- [Badge](https://hextaui.com/docs/badge) - Status labels with colored dots, removable tags that slide closed and counts that roll to their new value.
- [Button](https://hextaui.com/docs/button) - Buttons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- [Input](https://hextaui.com/docs/input) - A text input with three sizes, invalid and read-only states, native validation styling and a 16px touch font so phones never zoom in.
- [Separator](https://hextaui.com/docs/separator) - A hairline that divides content horizontally or vertically, with an optional label and a decorative mode for purely visual lines.
- [Skeleton](https://hextaui.com/docs/skeleton) - Placeholders that wait 150ms before showing, take the exact size of the content they wrap, and fade it in without moving anything.

## Code

7 files, added to components/blocks/order-summary.
