shopstack-sdk
v0.9.0
Published
What a store installs: the server client, the browser client, the payment frame, and recorded checkouts to build against.
Readme
shopstack-sdk
Shopstack is an API that buys a product from another merchant's website on behalf of your user. This package is its SDK: the calls on your server, and the checkout on your page.
npm install shopstack-sdkThe package has no root import: import … from 'shopstack-sdk' does not resolve. Import one of
its four entries: shopstack-sdk/server, shopstack-sdk/browser, shopstack-sdk/react and
shopstack-sdk/testing (what each holds is under What is in the package).
You need a key from the dashboard. Start with a test key
(ssk_test_…). If you use Shopstack's checkout frame, register your page's origin on the key.
A test key charges nothing, but only the instant script (product addresses at
https://merchant.example/…) and Stackables, Shopstack's own test shop, touch nothing outside
Shopstack. With a product from any other shop, a test key starts a real run at that shop: the
agent goes through the shop's real checkout, types the delivery details into it, and stops
before the order button (docs/testing.md).
Two ways to show the checkout
Shopstack's checkout frame. An iframe served by Shopstack that contains every screen of the checkout. Your page mounts it with the product's URL; the frame creates the checkout for your store, which it knows by the page's origin. Your server is not called.
import { mountCheckout } from 'shopstack-sdk/browser'
mountCheckout('#checkout', {
productUrl: 'https://merchant.example/p/tote', // the product's page at the merchant
user: userId, // your own id for the user
onDone: (outcome) => console.log('checkout ended:', outcome),
onClose: () => {}, // the user pressed close or Done; left out, the frame is taken away
onFailed: ({ code, message }) => {}, // the frame could not open (`forbidden`: the page's origin is not on a key); it shows why
})With React: <CheckoutFrame productUrl={productUrl} user={userId} onDone={…} /> from
shopstack-sdk/react. Unmounting it ends a checkout that has not reached payment
(docs/checkout-frame.md).
Your own screens. Your server creates the checkout, and your page follows the checkout object and draws each screen. The one screen Shopstack draws is the payment frame, which takes the card.
// Your server
const { checkout, checkoutToken } = await shopstack.createCheckout(
{ productUrl, options: { Size: 'M' }, user: { id: userId } },
{ idempotencyKey: `cart-${cartId}` },
)
// Your page
import { openCheckout, screenFor } from 'shopstack-sdk/browser'
const handle = openCheckout({ id, token })
handle.on('change', (checkout) => draw(screenFor(checkout), checkout))docs/own-screens.md has each screen, the bank's check among them: where the user's bank asks
them to confirm the payment, screenFor says bank_check, checkout.bankCheck says what the
bank asks, and handle.setBankCheck(answer) sends the user's answer. In both ways the card is entered in a frame Shopstack
serves, never on your page. How the frame takes it is the checkout's payment.method: card,
the user's own card, typed into Shopstack's own fields, encrypted in the browser for that
checkout's run and typed into the merchant's checkout (the merchant receives the card details);
or visa, Visa's card fields and Visa's window, where the user confirms with a passkey. The
key's Payment switch decides. A new key, test or live, starts at card where your store may pay
with the user's own card, else at visa; a test key made before 13 November 2026 stays at
visa until its switch is turned. On a test key card takes the networks' published test
numbers alone, and visa Visa's sandbox card. paymentMethod on createCheckout or
createCart sets it for one checkout or cart. A cart's card is typed once for all its items.
createCheckoutFrame({ productUrl }) on the server answers the same frame as the iframe to
paste (frame.html), for a page that mounts nothing itself.
The API takes HTTPS only (a call over http:// is 403; revoke a key sent that way). Every
reply carries X-Request-Id: quote it when you write to us.
The outcome, on your server
import { createShopstack, isShopstackError } from 'shopstack-sdk/server'
const shopstack = createShopstack({ secretKey: process.env.SHOPSTACK_SECRET_KEY! })
// Once: where checkouts of this key's mode report. Keep the secret, or read it in the dashboard.
const { endpoint, secret } = await shopstack.createNotificationEndpoint({ url: 'https://store.example/shopstack' })
// In that route: the raw body and the header.
try {
const notification = await shopstack.readNotification(rawBody, request.headers.get('Shopstack-Signature'), secret)
if (notification.type === 'product') notification.checkout // a product bought alone
else notification.cart // a cart, at an endpoint made with carts: true
notification.fee // the purchase's fee record, when it has a fee
} catch (error) {
if (isShopstackError(error) && error.code === 'invalid_signature') return answer(400) // not from Shopstack
if (!isShopstackError(error) || error.code !== 'unknown_notification') throw error
// Verified, but of a kind this version cannot read (error.rawBody holds it): answer 2xx below,
// or Shopstack sends it again.
}
return answer(204)isShopstackError comes from shopstack-sdk/server. verifyNotification takes the same three
and returns a product's checkout alone (invalid_reply for a cart's notification). A secret that
is missing or shorter than 32 characters is a TypeError. The create calls need their
{ idempotencyKey } (a TypeError without it), and createShopstack its secretKey.
// The platform fees of this key's mode, newest first; next is the after that goes on.
const { fees, next } = await shopstack.listFees({ status: 'collected', collectedAfter: new Date('2026-11-01') })
const fee = await shopstack.getFee(fees[0].id) // status, orderTotal, storeTake, collectedAtA product's details and choices
let { extraction } = await shopstack.extract('https://merchant.example/p/tote')
while (extraction.status === 'running') {
await new Promise((resolve) => setTimeout(resolve, 5000))
;({ extraction } = await shopstack.getExtraction(extraction.id))
}
// extraction.product: title, description, price, images, options (with each value's stock)A page is read once and kept: asking again for the same address answers at once.
A store catalogue: a whole shop on a page
const { catalogue } = await shopstack.createStoreCatalogue({ storeUrl: 'https://shop.example' })
// catalogue.html: an iframe and a script line for any page. The shop is read once; the frame fills as it goes.The frame shows the shop's best sellers as a row and opens into a search over the whole shop,
with Buy and a cart. Its checkouts are opened with the key that made it (docs/embeds.md).
Several items, paid for once
A cart is up to 8 checkouts, one per item, each with an agent of its own at its merchant. The
user enters delivery once and pays once: the user's own card typed once, or one Visa approval (once
per currency, for items priced in several: cart.totals).
// Your server: a new idempotency key for each press of Check out, not one per order
const { cart, cartToken, frameOrigin } = await shopstack.createCart(
{ items: [{ productUrl: toteUrl, options: { Size: 'M' } }, { productUrl: bagUrl }], user: { id: userId } },
{ idempotencyKey: `checkout-${attemptId}` },
)
// Your page: our checkout page for the cart, or your own screens with openCart({ id, token })
import { mountCart } from 'shopstack-sdk/browser'
mountCart('#checkout', {
cartId: cart.id,
cartToken: cartToken.value,
frameOrigin,
onDone: (outcome, items) => {}, // the cart's outcome, and each item's: read items for order_unknown
})In React: <CartFrame cartId={cart.id} cartToken={cartToken.value} frameOrigin={frameOrigin} onDone={…} />.
docs/carts.md has the rest.
What is in the package
| Import | Runs | Holds |
| --- | --- | --- |
| shopstack-sdk/server | Your server | The secret key |
| shopstack-sdk/browser | Your page | A checkout token, good for one checkout, or a cart token, good for one cart |
| shopstack-sdk/react | Your page | The same, as a hook and components |
| shopstack-sdk/testing | Your page and tests | Recorded checkouts to build against, no server |
The guides ship with the package, in node_modules/shopstack-sdk/docs/:
| File | Read it for |
| --- | --- |
| README.md | What Shopstack does, and how to get set up |
| keys.md | The account, test and live keys, the switches on a key |
| product-frames.md | A product with Buy now and Add to cart, pasted into a page |
| quickstart.md | The steps with code, both ways to check out |
| checkout-frame.md | The checkout frame in full |
| own-screens.md | Drawing the screens yourself |
| screens.md | What to show on each screen |
| payment.md | The payment frame |
| extract.md | Extraction in full |
| embeds.md | A row of products on any page |
| single-checkout.md | Personal agent purchases: a checkout with every detail in one call |
| carts.md | Several items, an agent each, paid for with one approval (one per currency) |
| testing.md | Test keys and recorded checkouts |
| paying.md | Whether a checkout places the order, the card's billing address, the bank's check, the platform fee |
| reference.md | Every call, field, code and limit |
Limits
- One item per checkout; up to 8 checkouts in a cart.
- Delivery to the countries
docs/reference.mdlists under the delivery call, E.164 phones, and the merchant's own currency among 54, for checkouts and carts alike. - 15 minutes per checkout.
- A checkout ends with the card entered in the merchant's form and no order placed, unless the
key's Place full orders switch is on and the merchant is one Shopstack places orders at
(
docs/paying.md).
Licence
MIT
