Skip to content

Pricing rules

Five mechanisms shape what a customer pays. Merchants configure them on the merchant surface; storefronts evaluate carts against them on the public surface. All money is integer cents, and percentage values are basis points (1–10000, i.e. 100 bps = 1%). Examples reuse the api() helper.

The shared discount type enum across coupons, auto-discounts, and bundles:

  • PERCENTAGE — value in basis points
  • FIXED_AMOUNT — value in cents off subtotal
  • FREE_SHIPPING — value ignored

Coupons

Code-based discounts. Merchant CRUD requires high-risk pricing:write; Owner/Admin retain broad access, and Staff needs that group. Soft-disable has a customer-visible blast radius and is included in the high-risk audit matrix.

A coupon with excludeOnSaleItems: true stays off every cart line that is already on sale: a line priced by an active sale window, or priced below its compare-at price. It discounts only the other lines, so a FIXED_AMOUNT coupon is capped at their total, while minimumSubtotalInCents still counts the whole cart. In a composed product's line, each package component counts on its own: components that are on sale are skipped, and the others still count toward what the coupon can discount. If everything in the cart is on sale, nothing is left to discount, and the checkout session skips the coupon as it skips any code that doesn't apply (discountSnapshot.appliedCoupon is null). The field is optional and defaults to false, which keeps the coupon applying to sale items too.

The flag never applies to FREE_SHIPPING: a FREE_SHIPPING coupon stores false even when you send true, a PATCH that changes the type to FREE_SHIPPING clears it, and changing the type back doesn't restore it. If the resulting type isn't FREE_SHIPPING, a PATCH that omits excludeOnSaleItems leaves it unchanged. Only literal JSON booleans are accepted: a string such as "false", or an explicit null, is a 400.

A preview sent to POST /public/cart/apply-coupon with the cart as server-priced lines honors the flag too, and answers valid: false when nothing is left to discount. A client-priced preview, such as the subtotalInCents body below, can't see which lines are on sale, so it previews the coupon against the whole subtotal and can over-promise.

await api("/merchant/coupons", { method: "POST", token,
  body: JSON.stringify({
    code: "WELCOME10",            // required, 1–50, alphanum/-/_; upper-cased server-side
    type: "PERCENTAGE",           // required
    value: 1000,                  // 1000 bps = 10%
    minimumSubtotalInCents: 5000, // optional, default 0
    maxUses: 500,                 // optional, null = unlimited
    expiresAt: "2026-07-01T00:00:00Z", // optional; must be > startsAt
    excludeOnSaleItems: true,     // optional, default false; skips lines already on sale
  }) });
 
// DELETE soft-disables (status → DISABLED, row kept); idempotent.

A storefront previews a code at the cart. Send the cart as server-priced lines, catalog references and quantities with no prices, so the API prices it the way the checkout session will (see server-priced or client-priced previews):

const result = await api("/public/cart/apply-coupon", {
  method: "POST",
  body: JSON.stringify({
    code: "WELCOME10",
    lines: [{ itemId: "…", variantId: "…", quantity: 2 }],
  }),
});
// → { valid: true, code, type, value, discountInCents } OR { valid: false, message: "…" }  (both 200)

The original client-priced body is unchanged. It previews only the subtotal you send:

await api("/public/cart/apply-coupon", {
  method: "POST",
  body: JSON.stringify({ code: "WELCOME10", subtotalInCents: 12000 }),
});

A Buy X, Get Y coupon, one with buyGet terms, is matched on the cart's items, so its code needs lines. The client-priced body carries no items: it answers the code as unavailable, valid: false, exactly as it answers an unknown code. With lines, the saving is discountInCents. type and value don't describe it: every Buy X, Get Y code answers PERCENTAGE and 0. A store may not be able to create one yet. The create then answers 409 with details.reason set to BUY_GET_NOT_READY while the offer is still rolling out (retry later), or to BUY_GET_UNAVAILABLE where it isn't available yet.

Apply is a pure preview in either shape — it does not consume a use. Usage is counted at order placement (with cartonium checkout, M3). CouponStatus: ACTIVE · DISABLED · EXPIRED.

Automatic discounts

Like coupons but no code — applied to any qualifying cart. Adds a scope and a priority (tie-breaker), drops code/maxUses.

excludeOnSaleItems works as it does on a coupon, in every scope, including ALL_ITEMS and ORDER_TOTAL: the discount applies only to lines and package components that aren't already on sale, while minimumSubtotalInCents still counts the whole cart. With nothing left to discount, it doesn't apply, and the next discount in priority order for the same scope (for ITEMS_BY_COLLECTION, the same collection) can apply instead. The default and the FREE_SHIPPING, PATCH and literal-boolean rules are the same as for coupons. Checkout and point-of-sale pricing honor the flag, and so does a preview sent to POST /public/auto-discounts/calculate with the cart as server-priced lines. A client-priced items body, like the one below, previews such a discount as if nothing were on sale.

await api("/merchant/auto-discounts", { method: "POST", token,
  body: JSON.stringify({
    name: "Summer 15% off packs",
    scope: "ITEMS_BY_COLLECTION",     // ALL_ITEMS | ITEMS_BY_COLLECTION | ORDER_TOTAL
    scopeCollectionId: "…",           // required iff scope is ITEMS_BY_COLLECTION
    type: "PERCENTAGE",
    value: 1500,
    priority: 10,                     // optional tie-breaker, default 0
    excludeOnSaleItems: true,         // optional, default false; skips lines already on sale
  }) });

Storefront evaluates a cart (cart + PDP both call this). With server-priced lines, the API also resolves each line's collection memberships itself:

await api("/public/auto-discounts/calculate", {
  method: "POST",
  body: JSON.stringify({
    lines: [{ itemId: "…", variantId: "…", quantity: 1 }],
  }),
});
// → { appliedDiscounts: [{ autoDiscountId, name, scope, type, appliedToInCents, discountInCents }],
//     totalDiscountInCents, finalSubtotalInCents }

The original client-priced body, which carries your own prices and collection memberships, is unchanged:

await api("/public/auto-discounts/calculate", {
  method: "POST",
  body: JSON.stringify({
    subtotalInCents: 12000,
    items: [{ itemId: "…", variantId: "…", quantity: 1, unitPriceInCents: 12000, collectionIds: ["…"] }],
  }),
});
// → every ACTIVE matching discount with its per-discount saving in cents

Either way, finalSubtotalInCents subtracts automatic discounts only. Coupons, bundles and package savings are not in it, so it is not the checkout total.

Server-priced or client-priced previews

Both cart previews take the cart in exactly one of two shapes. A request that sends lines together with a client-priced field, or sends neither shape, is a 400.

Server-priced lines (recommended)Client-priced (original)
Coupon body{ code, lines }{ code, subtotalInCents }
Automatic-discount body{ lines }{ items, subtotalInCents }
Who prices the cartThe API, from the catalog, as the checkout session doesYou: the API trusts the numbers you send
Items already on saleSeen, so a rule that excludes them discounts only the rest of the cartNot seen, so such a rule can over-promise
A Buy X, Get Y codeMatched on the cart's itemsAnswered as unavailable
Can return 409Yes, see belowNever

lines is the checkout session's own line shape, the one you send to create a checkout session. Each line names a catalog row and a quantity, never a price or collectionIds:

  • itemId — required.
  • variantId — the exact variant the line targets, which must belong to itemId. Leave it out, or send null, to price the line at the item's own price. A SALE item that has ever had a variant can't be priced that way: name one of its live variants, or the line is a 400.
  • quantity — a whole number, 1 or more.
  • expectedCompositionRevision — only on a package line: the item's current composition.revision from the public catalog. Leave the property out of every other line. An explicit null is not treated as left out, and is refused.

The API prices lines through the same pricing the checkout session runs: catalog prices, active sale windows, collection membership and the cart's other active promotions. That makes it the only shape that honors a coupon or automatic discount that excludes items already on sale (excludeOnSaleItems), and the only one that can preview a Buy X, Get Y code. An item or variant is on sale when an active sale window lowers its price, or when its compare-at price is above its regular price.

The client-priced bodies preview your own numbers instead. The API trusts the subtotal, unit prices and collection memberships you send and cannot see sale state, so it previews such a rule as if nothing were on sale. They remain for existing callers; prefer lines. A storefront whose cart still checks codes with a subtotal refuses every Buy X, Get Y code, even one that checkout accepts.

Previews stay previews

Neither shape reserves anything or quotes a final price. The checkout session prices the cart again whenever it is created, repriced or bound, and the total it binds is what the customer pays.

Each lines preview also answers for its own offer only. The coupon's discountInCents is allocated together with the cart's other active promotions, so it can be less than the coupon's own math. The automatic-discount amounts are what the session would bind with no coupon applied, and they too can be less than each discount's own math when promotions share lines. Don't add preview amounts together into a cart total. For a combined summary, use the totals from the checkout session's create or reprice response.

When a lines preview returns 409

Because lines runs the checkout session's pricing, it fails where checkout would. A 400 on a line means checkout would refuse that line too, such as an item that is not purchasable or a variant of another item. Each declared 409 has its own recovery:

codeWhat happenedRecovery
COMPOSITION_REVISION_STALEA package line's expectedCompositionRevision is missing or no longer current, or a line sends one for an item that is no longer a package. details.reason says which.Re-read the item from the public catalog (GET /public/items/:slug, or POST /public/items/resolve for a saved cart) and retry with its current composition.revision, or without one when its composition is now null.
RESOURCE_CONFLICTA line can't be priced as sent: the item is sold through booking availability, or a package has booking capacity or a component that is unavailable or no longer resolves. details.itemId names the line.Remove or replace that line.

The client-priced bodies never return 409.

To branch on code, read the error envelope before you throw. The api() helper throws on any non-2xx status without reading the body, so code and details never reach your handler. In your copy of the helper, swap its error line for one that keeps them:

class ApiError extends Error {
  constructor(
    readonly status: number,
    readonly code: string | undefined,
    readonly details: Record<string, unknown> | undefined,
    message: string,
  ) {
    super(message);
  }
}
 
// In api(), replace the `if (!res.ok) throw …` line with:
if (!res.ok) {
  const body = await res.json().catch(() => ({})); // { code, message, details }
  throw new ApiError(res.status, body.code, body.details,
    `${res.status} ${body.code ?? res.statusText}`);
}

Then branch on the status and the code:

try {
  const result = await api("/public/cart/apply-coupon", {
    method: "POST",
    body: JSON.stringify({ code: "WELCOME10", lines }),
  });
  // … show the preview
} catch (err) {
  if (!(err instanceof ApiError) || err.status !== 409) throw err;
  if (err.code === "COMPOSITION_REVISION_STALE") {
    // Re-read the package from the public catalog, then retry with its current composition.revision.
  } else if (err.code === "RESOURCE_CONFLICT") {
    // Remove or replace the line named by err.details?.itemId, then retry.
  } else {
    throw err; // A 409 code this page doesn't list: fall back on the status.
  }
}

Sale windows

A scheduled price change on an item or variant — no code, no cart call. The public catalog read reflects an active window's price automatically, so there's no public sale-window endpoint.

await api("/merchant/sale-windows", { method: "POST", token,
  body: JSON.stringify({
    itemId: "…",                  // required (item-level unless variantId set)
    variantId: "…",               // optional; null = item-level
    salePriceInCents: 14900,      // required
    startsAt: "2026-07-04T00:00:00Z",
    endsAt: "2026-07-08T00:00:00Z", // required; must be > startsAt
  }) });

Windows use a half-open interval [startsAt, endsAt) — back-to-back windows don't overlap — and overlapping windows on the same (itemId, variantId) are rejected. Unlike coupons, sale windows hard-delete (DELETE), since there's no usage history to preserve. itemId isn't editable — delete and recreate to move a window.

Bundles

Composition-based: buy a set of items together, get a discount. Merchant CRUD (≥2 component items required).

await api("/merchant/bundles", { method: "POST", token,
  body: JSON.stringify({
    name: "Pack + rain cover",
    type: "FIXED_AMOUNT",
    value: 2000,                  // $20 off when the set is in the cart
    items: [                      // ≥2 required
      { itemId: "…", minQuantity: 1 },               // variantId omitted = any variant
      { itemId: "…", variantId: "…", minQuantity: 1 },
    ],
  }) });

Storefront checks a cart for satisfied bundles:

await api("/public/cart/check-bundles", {
  method: "POST",
  body: JSON.stringify({
    cartLines: [{ itemId: "…", variantId: "…", quantity: 1, unitPriceInCents: 18900 }],
  }),
});
// → every ACTIVE bundle whose slots are satisfied + per-bundle saving

A product page can also read the bundles a given item belongs to — keyed by the item's slug, so the storefront can surface them before anything is in the cart (a "part of the Trail Kit set — add X to save Y" module, or a "one item away from savings" nudge):

const { bundles } = await api(`/public/items/${slug}/bundles`);
// → { bundles: [{ id, name, type, value, discountInCents, slots: [...] }] }
// A published item that's in no bundle returns { bundles: [] }.

Each slot carries the component's itemId, slug, name, priceInCents, minQuantity, and variantId (plus a variant: { name, options, priceInCents } when the slot is variant-specific) — enough to render and deep-link the rest of the set. discountInCents is the minimum qualifying saving (current catalog prices × minQuantity); the real cart saving scales with quantity and is finalized by check-bundles and the order path.

Where check-bundles is reactive (the items must already be in the cart), this read is proactive and returns catalog detail — so it surfaces only published items and ACTIVE bundles, never draft or archived ones.

A slot with no variantId matches any variant of the item; with one, it requires an exact match. PATCH with items replaces the composition wholesale. Soft-disables on DELETE.

Compare-at pricing

The simplest one: compareAtPriceInCents is an optional field on items and variants (see Catalog). Set it above the live price to render a "was / now" strike-through; it's data on the product, not a rule.