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:
| Field | Description |
|---|---|
upc | The product’s UPC. Use this exact value in checkout items. |
name, brand, description, images | Catalog details for your product page or cart. |
color, size, variantLabel | Variant details, for example variantLabel: "Navy, M". |
availability | Offer[]: 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:
| Field | Description |
|---|---|
merchantId | The retailer. Goes into the checkout item. |
name, logo | The retailer’s name and logo, to show the shopper who ships it. |
salePrice | The price the shopper pays. |
price | List price before any sale (for a strikethrough). |
shippingCost | The retailer’s shipping fee per order. |
freeShippingThreshold | Retailer subtotal at which shipping becomes free. |
minimumOrderAmount | Smallest retailer subtotal the retailer accepts. |
productName, image | The 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
| Field | Type | Description |
|---|---|---|
items | CheckoutItem[] | 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. |
_id | string | Re-price this existing checkout instead of creating a new one. See Re-pricing. |
coupons | { code }[] | Coupon codes the shopper entered. See Coupons. |
email | string | The shopper’s email, if you already have it. |
isMarketingOpted | boolean | Shopper opted into marketing. Offer this when config.showMarketingOptIn is true, with config.marketingOptInCopyText (HTML from your Cart Builder settings) as the label. |
isSecondaryMarketingOpted | boolean | A second opt-in, when config.showSecondaryMarketingOptIn is true. |
isSubstitutionOpted | boolean | Shopper accepts a substitute if an item is unavailable. Offer this when config.allowSubstitution is true. |
Response: PricedCheckout
| Field | Description |
|---|---|
_id | The checkout id. Keep it: you re-price, update and pay for this checkout by id. |
currency | Lowercase currency code, for example usd. |
merchants | One entry per retailer, below. |
coupons | The coupons that applied, each with code, discountType (FIXED or PERCENTAGE), discountValue and the computed discountAmount. |
subTotal | Sum of line prices. |
shippingTotal | Shipping across all retailers. |
discountTotal | Coupon discounts, never more than subTotal. |
estimatedTax | A display estimate. See Tax. |
total | subTotal - discountTotal + shippingTotal + estimatedTax. The number to show as the order total. |
authorizationAmount | What the card is authorized for. See Authorization. |
Each entry in merchants:
| Field | Description |
|---|---|
merchantId, name | The retailer. |
products | The lines from this retailer: id, upc, name, salePrice, quantity, images, color, size. |
subTotal | This retailer’s line total. |
shippingCost | The retailer’s shipping fee. |
freeShippingThreshold | Subtotal at which this retailer ships free, or null if it never does. |
shippingTotal | Shipping 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 })),});itemsreplaces the checkout’s items. Send the whole cart every time.- Send
couponsevery time too. A call without them removes the checkout’s coupons. - Reusing
_idkeeps 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 uppercaseconst 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.couponsto tell the shopper whether a code worked. FIXEDcoupons takediscountValueoff the order.PERCENTAGEcoupons 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 nextprepareCheckoutuses 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:
reason | Example message | What 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:
| Status | Example message | What 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.