You’re building a custom storefront — your own Next.js / Nuxt / React app, your own design, your own product browsing flow. You want Shoppex to handle the cart, the checkout, and the payment, without writing any of that yourself. This tutorial covers theDocumentation Index
Fetch the complete documentation index at: https://docs.shoppex.io/llms.txt
Use this file to discover all available pages before exploring further.
@shoppexio/storefront SDK. By the end you’ll have a working
cart and a real checkout that redirects to checkout.shoppex.io for the actual payment.
What @shoppexio/storefront does
The SDK is a thin browser-side client around Shoppex’s public storefront API. It handles:
- Fetching products, categories, and variants from your shop.
- Local cart state with
addToCart/updateCartItem/removeFromCart. - Server-side cart pricing via
quoteCart(taxes, discounts, totals). - Creating a checkout: POST to Shoppex, get back a redirect URL.
- Render any checkout UI. The actual payment happens on
checkout.shoppex.io. - Use API keys. The SDK runs on public browser origins and is auth-less by design — Shoppex’s storefront endpoints are CORS-public and identified by the shop slug, not a key.
What you’ll need
- A Shoppex shop. Your shop slug (the part before
.shoppex.io). - A frontend project — anything that runs JavaScript. We’ll use Next.js for this tutorial, but the SDK works in Vite, Remix, Nuxt, plain HTML, etc.
Step 1 — Install the SDK
Step 2 — Initialize
In any client-side module (use"use client" if you’re in a Next.js App Router project):
Step 3 — Fetch and render products
id, title,
description, price, currency, images, variants.
For a single product detail page:
Step 4 — Add to cart
quoteCart calls Shoppex’s server — use it on the cart/checkout page where the buyer needs
to see real totals, not on every cart modification.
Step 5 — Checkout
When the buyer is ready to pay:- POSTs your current cart to
https://api.shoppex.io/v1/storefront/invoices/from-cart. - Receives an invoice ID and a checkout URL of the form
https://checkout.shoppex.io/invoice/{invoiceId}. - Returns it to you.
Step 6 — Post-payment
Shoppex hosts the success and failure pages. The buyer doesn’t come back to your app by default after paying — they’re oncheckout.shoppex.io looking at their order.
To bring them back, you have two options:
- Storefront-level setting — on
yourshop.shoppex.io, configure a custom post-checkout redirect URL in your shop settings. - Per-checkout — pass
success_url/cancel_urlvia the more advanced Developer API checkout session endpoint (see below).
Starter project
Shoppex publishesapps/storefront-starter/ — a working Next.js 16.2 example wired with the
SDK. It’s the fastest way to see the end-to-end flow in real code. Open the
shoppex.config.ts, point it at your shop slug via NEXT_PUBLIC_SHOPPEX_SHOP_SLUG, and
run bun dev.
What about the Developer API checkout endpoint?
The Storefront SDK uses Shoppex’s storefront API — auth-less, browser-safe, CORS-public. For server-to-server scenarios where you want Shoppex to act on a typed invoice spec, use the Developer API instead:POST /dev/v1/payments— create an invoice directly.POST /dev/v1/checkout/sessions— Stripe-style alias that returns{ id, url }.
Authorization: Bearer shx_...), and both redirect the buyer to
checkout.shoppex.io/invoice/{id} for the actual payment. See the
API Reference for the request/response shapes.
The choice between SDK and Developer API:
- SDK — you’re building a frontend on the buyer’s side. No server-side code. Public.
- Developer API — you’re acting from your own backend, possibly invoicing buyers without them ever seeing a storefront (e.g. a Discord bot collecting payments, an internal admin tool generating one-off invoices).
Common pitfalls
- No tree-shaking the SDK. It’s deliberately one client object (
shoppex) so all modules share state. Don’t try toimport { getCart }independently — call via the initialized client. - CORS errors during local dev. If you see
Access-Control-Allow-Originerrors, you’re probably hittinglocalhost:3000against a shop slug that doesn’t exist. Verify the slug. - Cart desync across tabs. The cart lives in localStorage. If a buyer has two tabs open, changes in one don’t auto-propagate to the other until they refresh.
Reference: Storefront SDK
Full method reference and types.