JavaScript / TypeScript
@shoppable/checkout is Shoppable’s checkout SDK (software development kit). It runs in the browser and in Node, ships ESM (ECMAScript modules), CommonJS
and TypeScript types, and has no dependencies: it uses the platform’s fetch. For a walkthrough,
start with the Quickstart.
Install
npm install https://developer.shoppable.com/sdk/shoppable-checkout-0.2.1.tgzpnpm add https://developer.shoppable.com/sdk/shoppable-checkout-0.2.1.tgz<script src="https://developer.shoppable.com/sdk/checkout@0/index.global.js"></script>Script tag
For pages without a bundler, the script build puts every export on window.Shoppable. Use
checkout@0 to follow the latest 0.x release, or pin one, for example checkout@0.2.1:
<script src="https://developer.shoppable.com/sdk/checkout@0/index.global.js"></script><script> const { ShoppableCheckout, cheapestOffer, ShoppablePaymentError } = window.Shoppable; const client = new ShoppableCheckout({ token: "pk_test_..." });</script>@0 follows the latest 0.x release. Pin an exact version in production.
Constructor
new ShoppableCheckout(options: ShoppableCheckoutOptions)| Option | Type | Default | Description |
|---|---|---|---|
token | string | Publishable token. Test tokens start with pk_test_; the live token has no prefix. Required unless you pass sessionToken. See Get your keys. | |
origin | string | the page’s origin | Your site’s origin, checked against the token’s allowed domains. In an iframe it defaults to the embedding page’s origin. Required in Node. |
baseUrl | string | https://ps.shoppable.com | Base URL of the Shoppable API (application programming interface). The default serves both test and live tokens; override it only if Shoppable asks you to. |
sessionToken | string | A session token you already hold. Skips the first handshake. See Authentication. | |
onSessionToken | (token: string) => void | Called whenever the SDK obtains or refreshes a session token. | |
timeout | number | 30000 | Per-request timeout in milliseconds. 0 disables it. |
maxRetries | number | 2 | Retries for network errors, timeouts, 429 and 5xx responses. |
apiVersion | string | "2026-06-16" | API version, sent as the Shoppable-Version header. |
fetch | typeof fetch | global fetch | A custom fetch for runtimes without one. |
Methods
Every method takes an optional last argument, options?: RequestOptions:
{ signal, timeout, idempotencyKey, headers }. See Errors & reliability.
| Method | Returns | Description |
|---|---|---|
getCartConfiguration() | Promise<CartConfiguration> | Checks the token and origin, starts the session, and returns the cart’s settings. |
getSessionToken() | string | undefined | The current session token, if any. |
lookupProducts(upcs, opts?) | Promise<ProductAvailability[]> | Products and their retailer offers. opts.includeVariations adds other sizes and colors. |
prepareCheckout(request) | Promise<PricedCheckout> | Creates or re-prices a checkout from the shopper’s items. |
updateCheckout(checkoutId, patch) | Promise<PricedCheckout> | Sets email, addresses, opt-ins or coupons. Returns the checkout re-priced. |
placeOrder(checkoutId, options) | Promise<CompletedCheckout> | Authorizes, confirms and places the order in one call. |
validateAddress(address) | Promise<AddressValidationResult> | Checks and normalizes an address. Never throws for an invalid one. |
createIntent(checkoutId, body?) | Promise<PaymentIntentResponse> | The authorize step of placeOrder, on its own. |
completeCheckout(checkoutId) | Promise<CompletedCheckout> | The complete step of placeOrder, on its own. |
validateCoupon(input) | Promise<CouponResult> | Deprecated. Checks one single-use coupon on its own; see below. |
The client also has getCustomer() and lander.* methods, used by Shoppable’s own hosted cart
and AI shopping connector. Checkout integrations do not need them.
prepareCheckout
prepareCheckout(request: PrepareCheckoutRequest, options?: RequestOptions): Promise<PricedCheckout>const priced = await client.prepareCheckout({ _id: existingCheckoutId, // optional: re-price this checkout items: [{ upc, merchantId, quantity: 1 }], coupons: [{ code: "SAVE10" }],});Every field of the request and the response is described in
Cart and pricing. Rejects with
ShoppableValidationError when an item is out of stock or a retailer minimum is not met.
updateCheckout
updateCheckout(checkoutId: string, patch: CheckoutPatch, options?: RequestOptions): Promise<PricedCheckout>CheckoutPatch takes at least one of email, shipping and billing (each an Address),
isMarketingOpted, isSecondaryMarketingOpted, isSubstitutionOpted, and coupons (replaces
the list; [] clears it). Any other field is rejected with a 422. Items cannot be changed here;
call prepareCheckout.
Address is { firstName, lastName, streetAddress1, streetAddress2?, city, state, country, zipCode }.
The order itself is shipped to the address on the payment, so setting shipping here does not
replace confirmParams.shipping.
placeOrder
placeOrder( checkoutId: string, options: { confirmPayment: (clientSecret: string) => Promise<PaymentConfirmation>; paymentMethod?: string; }, requestOptions?: RequestOptions,): Promise<CompletedCheckout>Runs createIntent, then your confirmPayment(clientSecret), then completeCheckout.
confirmPayment usually returns stripe.confirmPayment(...) as is: a result with error set
means the payment was not confirmed. paymentMethod names an express wallet (for example
apple_pay) for reporting.
Resolves with { status, orderNumber }. Throws ShoppablePaymentError when confirmation fails
(no order, nothing charged), or a ShoppableApiError when authorizing or placing the order
fails (any authorization is released). Full code is in Payments.
validateAddress
validateAddress(address: AddressInput, options?: RequestOptions): Promise<AddressValidationResult>AddressInput is { address, addressTwo?, city, state?, zipCode, countryCode }; build it from
a Stripe Address Element with fromStripeAddress. Resolves with { valid: true, address }
(the normalized address) or { valid: false, message } (a message to show the shopper).
createIntent and completeCheckout
placeOrder calls these for you; call them yourself only if you need something between the
steps.
createIntent(checkoutId, { paymentMethod? })authorizes the checkout’sauthorizationAmountand resolves with{ clientSecret }forstripe.confirmPayment.completeCheckout(checkoutId)places the order once the payment is confirmed and resolves with{ status, orderNumber }. On failure the authorization is released and the error carries a supportref.
validateCoupon
Deprecated: send coupon codes to prepareCheckout and read coupons on the response instead,
as in Coupons. The server matches codes in any case, and
returns them uppercase:
const code = input.value.trim().toUpperCase();const priced = await client.prepareCheckout({ items, coupons: [{ code }] });const applied = priced.coupons?.some((c) => c.code === code);validateCoupon({ couponCode, email, customerId, usageType }) still exists for single-use
codes tied to an email. It resolves { valid: true } only when the server confirms the coupon,
{ valid: false, message } when it rejects it, and throws on session or server failures.
Helpers
| Helper | Description |
|---|---|
cheapestOffer(product) | The offer with the lowest salePrice, or undefined if none has a price. Shipping is not considered. |
fromStripeAddress(value, countryCode?) | Converts a Stripe Address Element value to AddressInput for validateAddress. countryCode overrides the address’s own country; pass config.country. |
toStripeShipping(value) | Converts a Stripe Address Element (or wallet) value to the shipping that stripe.confirmPayment takes in confirmParams. Required: the order is placed from that address. It drops a missing line 2, which Stripe reports as null but its TypeScript types do not accept. |
toCheckoutAddress(value) | Converts a Stripe Address Element value to an Address for updateCheckout. The last word of the name is the last name, the same rule Shoppable uses when it places the order. |
Types
Every request and response is typed. The main ones, all exported from the package:
| Type | Description |
|---|---|
ShoppableCheckoutOptions, RequestOptions | Constructor and per-call options. |
CartConfiguration | getCartConfiguration() result: id, token, stripePublishableKey, isTestMode, isActive, currency, language, country, primaryColor, logo, merchants, and more. |
ProductAvailability, Offer | Products and retailer offers. |
CheckoutItem, PrepareCheckoutRequest | What you send to prepareCheckout. |
PricedCheckout, PricedMerchant, PricedLine, AppliedCoupon | What the server prices. |
CheckoutPatch, Address | What updateCheckout accepts. |
PlaceOrderOptions, PaymentConfirmation, CompletedCheckout | placeOrder input and result. |
AddressInput, AddressValidationResult, ValidatedAddress | Address validation. |
StripeAddressValue, StripeShipping | The Stripe Address Element value the helpers accept, and toStripeShipping’s result. |
CreateIntentInput, PaymentIntentResponse | createIntent input and result. |
LookupProductsOptions | lookupProducts options (includeVariations). |
CouponInput, CouponResult | The deprecated validateCoupon. |
Checkout is a deprecated alias of PricedCheckout. The package also exports VERSION (the
SDK version) and API_VERSION (the API version it pins).
Errors
Every failure throws one of these classes, all exported from the package:
ShoppableApiError and its subclasses ShoppableAuthError, ShoppableValidationError,
ShoppableNotFoundError, ShoppableRateLimitError, ShoppableServerError,
ShoppableNetworkError and ShoppableTimeoutError, plus ShoppablePaymentError and
ShoppableConfigError. Errors & reliability says when each is thrown
and how to handle it, along with retries, idempotency and timeouts.