Skip to content

Cart and pricing

Your cart sends Shoppable what the shopper chose (products, retailers, quantities, coupon codes) and displays the totals that come back. It never computes money itself.

Why the server prices everything

Shoppable is the merchant of record: it charges the shopper’s card and places an order with each retailer. The amount it authorizes, the amount it quotes and the amount it sends to the retailer must be the same number, so there is one place that computes it: the server, from its own catalog prices, retailer shipping rules and coupon records. Any prices or totals a client sends are ignored.

For you this means less code: no tax tables, no shipping rules, no coupon math. Call prepareCheckout whenever the cart changes and render what it returns.

Products and retailer offers

lookupProducts(upcs) takes UPCs (Universal Product Codes) and returns one ProductAvailability per product found:

FieldDescription
upcThe product’s UPC. Use this exact value in checkout items.
name, brand, description, imagesCatalog details for your product page or cart.
color, size, variantLabelVariant details, for example variantLabel: "Navy, M".
availabilityOffer[]: one in-stock offer per retailer that sells this product on your cart. Empty when none does.

Each Offer is one retailer’s terms for the product:

FieldDescription
merchantIdThe retailer. Goes into the checkout item.
name, logoThe retailer’s name and logo, to show the shopper who ships it.
salePriceThe price the shopper pays.
priceList price before any sale (for a strikethrough).
shippingCostThe retailer’s shipping fee per order.
freeShippingThresholdRetailer subtotal at which shipping becomes free.
minimumOrderAmountSmallest retailer subtotal the retailer accepts.
productName, imageThe retailer’s own listing name and image, when it has one.

Pass { includeVariations: true } as the second argument to also return a product’s other sizes and colors.

Choosing a retailer

A checkout item names both the product and the retailer it comes from:

{ upc: product.upc, merchantId: offer.merchantId, quantity: 1 }

The simplest choice is the lowest price, which cheapestOffer(product) returns (or undefined when no offer has a price). It compares salePrice only; shipping is not considered, and the priced checkout shows what the shopper actually pays.

You can also show the offers and let the shopper pick, for example to keep everything with one retailer and qualify for its free shipping. The same product from two retailers is two separate lines.

Pricing the cart

const priced = await client.prepareCheckout({
items: [
{ upc: "00012345678905", merchantId: "6123abc...", quantity: 2 },
],
coupons: [{ code: "SAVE10" }],
});

Request

FieldTypeDescription
itemsCheckoutItem[]Required, at least one. Each is { upc, merchantId, quantity }; quantity is a whole number from 1 to 99 (default 1). Repeating a upc and merchantId pair adds the quantities.
_idstringRe-price this existing checkout instead of creating a new one. See Re-pricing.
coupons{ code }[]Coupon codes the shopper entered. See Coupons.
emailstringThe shopper’s email, if you already have it.
isMarketingOptedbooleanShopper opted into marketing. Offer this when config.showMarketingOptIn is true, with config.marketingOptInCopyText (HTML from your Cart Builder settings) as the label.
isSecondaryMarketingOptedbooleanA second opt-in, when config.showSecondaryMarketingOptIn is true.
isSubstitutionOptedbooleanShopper accepts a substitute if an item is unavailable. Offer this when config.allowSubstitution is true.

Response: PricedCheckout

FieldDescription
_idThe checkout id. Keep it: you re-price, update and pay for this checkout by id.
currencyLowercase currency code, for example usd.
merchantsOne entry per retailer, below.
couponsThe coupons that applied, each with code, discountType (FIXED or PERCENTAGE), discountValue and the computed discountAmount.
subTotalSum of line prices.
shippingTotalShipping across all retailers.
discountTotalCoupon discounts, never more than subTotal.
estimatedTaxA display estimate. See Tax.
totalsubTotal - discountTotal + shippingTotal + estimatedTax. The number to show as the order total.
authorizationAmountWhat the card is authorized for. See Authorization.

Each entry in merchants:

FieldDescription
merchantId, nameThe retailer.
productsThe lines from this retailer: id, upc, name, salePrice, quantity, images, color, size.
subTotalThis retailer’s line total.
shippingCostThe retailer’s shipping fee.
freeShippingThresholdSubtotal at which this retailer ships free, or null if it never does.
shippingTotalShipping charged for this retailer: shippingCost, or 0 once free.

Group your cart by merchants so shoppers see which retailer ships which items, and render salePrice from the response rather than from the offer you looked up: if a catalog price dropped since then, the checkout already uses the lower price.

Re-pricing as the cart changes

Every time the shopper adds, removes or changes the quantity of an item, call prepareCheckout again with the full item list and the _id you got back the first time:

priced = await client.prepareCheckout({
_id: priced._id,
items: cartItems, // the whole cart, not just the change
coupons: couponCodes.map((code) => ({ code })),
});
  • items replaces the checkout’s items. Send the whole cart every time.
  • Send coupons every time too. A call without them removes the checkout’s coupons.
  • Reusing _id keeps one checkout per shopper instead of creating one per change, and keeps details such as the email you set.
  • Requests can finish out of order. Render only the response to your latest request.
  • After an order is placed, start the next cart without _id.

updateCheckout cannot change items; use prepareCheckout for that.

Coupons

Send the codes the shopper typed and let the server decide:

const code = codeInput.value.trim().toUpperCase(); // applied codes come back uppercase
const priced = await client.prepareCheckout({ _id, items, coupons: [{ code }] });
const applied = priced.coupons?.some((c) => c.code === code);
if (!applied) showMessage("That code isn't valid for this order.");
  • Codes are not case sensitive. Applied codes come back uppercase.
  • Unknown and inactive codes are dropped without an error. Check priced.coupons to tell the shopper whether a code worked.
  • FIXED coupons take discountValue off the order. PERCENTAGE coupons take that percent of the item subtotal (shipping is not discounted).
  • updateCheckout(id, { coupons }) also works and replaces the list; send [] to remove all. Keep your coupon list in your cart state either way, since the next prepareCheckout uses whatever you send.

Free shipping

Shipping is charged per retailer. Each retailer in merchants has a shippingCost; once that retailer’s subTotal reaches its freeShippingThreshold, its shippingTotal drops to 0. The threshold is measured before coupon discounts.

To nudge shoppers toward free shipping, compare subTotal with freeShippingThreshold for each retailer (“Add $12.00 more from Acme for free shipping”). The amount charged always comes from shippingTotal.

Estimated tax and actual tax

estimatedTax is an estimate for display, so label it “Estimated tax”. The actual tax is calculated for the shipping address when the order is placed, and the shopper is charged that amount, which can be higher or lower than the estimate.

authorizationAmount and total

Shoppable takes payment with manual capture: when the shopper pays, the card is authorized, not charged. The authorization is for authorizationAmount, which is the total before tax plus headroom to cover the actual tax. When the order is placed, only the final amount (with actual tax) is captured and the rest of the authorization is released.

Show total as the order total. Shoppers may briefly see a pending authorization for the higher amount on their card; if your support team gets questions, that is why. You do not pass either amount anywhere: Stripe Elements uses total for display (see Payments), and the server sets the authorization itself.

When pricing fails

prepareCheckout rejects with a ShoppableValidationError whose message says what is wrong in words you can show the shopper.

When specific lines are the problem, the error’s body also lists them, so you can mark each failing line in your cart:

import { ShoppableValidationError } from "@shoppable/checkout";
try {
priced = await client.prepareCheckout({ _id, items, coupons });
} catch (err) {
if (!(err instanceof ShoppableValidationError)) throw err;
showCartError(err.message);
const { errors = [] } = (err.body ?? {}) as {
errors?: { upc: string; merchantId: string; reason: string; message: string }[];
};
for (const line of errors) markLine(line.upc, line.merchantId, line.reason, line.message);
}

Each entry in errors is { upc, merchantId, reason, message }, where reason is one of:

reasonExample messageWhat to do
out_of_stock”Trail Jacket gone out of stock”Remove the line, or look the product up again and offer another retailer.
quantity_unavailable”Trail Jacket has an unavailable Amazon quantity”Lower the quantity or remove the line.
price_increased”Trail Jacket’s price went up”Look the product up again so the shopper sees the new price, then re-price.
invalid_line”Trail Jacket has invalid data”Remove the line; the product cannot be sold right now.

With several failing lines, message joins their messages with commas. Other failures carry a message and no errors list:

StatusExample messageWhat to do
422”Minimum order amount for Acme is $25”Ask the shopper to add more from that retailer, or remove its items.
422”items[0].quantity must be a whole number from 1 to 99”A bug in the request; fix the items you send.
400”no such merchant”The merchantId is not a retailer on your cart. Use one from availability.

A failed call does not change the checkout, so the last successful PricedCheckout still describes what is stored. Do not take payment until the cart prices successfully.

See Errors & reliability for the full error model.