Skip to content

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

Terminal window
npm install https://developer.shoppable.com/sdk/shoppable-checkout-0.2.1.tgz

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)
OptionTypeDefaultDescription
tokenstringPublishable token. Test tokens start with pk_test_; the live token has no prefix. Required unless you pass sessionToken. See Get your keys.
originstringthe page’s originYour site’s origin, checked against the token’s allowed domains. In an iframe it defaults to the embedding page’s origin. Required in Node.
baseUrlstringhttps://ps.shoppable.comBase URL of the Shoppable API (application programming interface). The default serves both test and live tokens; override it only if Shoppable asks you to.
sessionTokenstringA session token you already hold. Skips the first handshake. See Authentication.
onSessionToken(token: string) => voidCalled whenever the SDK obtains or refreshes a session token.
timeoutnumber30000Per-request timeout in milliseconds. 0 disables it.
maxRetriesnumber2Retries for network errors, timeouts, 429 and 5xx responses.
apiVersionstring"2026-06-16"API version, sent as the Shoppable-Version header.
fetchtypeof fetchglobal fetchA custom fetch for runtimes without one.

Methods

Every method takes an optional last argument, options?: RequestOptions: { signal, timeout, idempotencyKey, headers }. See Errors & reliability.

MethodReturnsDescription
getCartConfiguration()Promise<CartConfiguration>Checks the token and origin, starts the session, and returns the cart’s settings.
getSessionToken()string | undefinedThe 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’s authorizationAmount and resolves with { clientSecret } for stripe.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 support ref.

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

HelperDescription
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:

TypeDescription
ShoppableCheckoutOptions, RequestOptionsConstructor and per-call options.
CartConfigurationgetCartConfiguration() result: id, token, stripePublishableKey, isTestMode, isActive, currency, language, country, primaryColor, logo, merchants, and more.
ProductAvailability, OfferProducts and retailer offers.
CheckoutItem, PrepareCheckoutRequestWhat you send to prepareCheckout.
PricedCheckout, PricedMerchant, PricedLine, AppliedCouponWhat the server prices.
CheckoutPatch, AddressWhat updateCheckout accepts.
PlaceOrderOptions, PaymentConfirmation, CompletedCheckoutplaceOrder input and result.
AddressInput, AddressValidationResult, ValidatedAddressAddress validation.
StripeAddressValue, StripeShippingThe Stripe Address Element value the helpers accept, and toStripeShipping’s result.
CreateIntentInput, PaymentIntentResponsecreateIntent input and result.
LookupProductsOptionslookupProducts options (includeVariations).
CouponInput, CouponResultThe 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.