Start here to build a shop on Lynkow: what the site needs before the first call, the pages a shop needs and the guide that builds each one, then the webhooks that keep pages fresh and react to orders. Previous: Guide 24 | Next: Guide 18
Reference - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
Prerequisites
Lynkow SDK installed (Quick Start, or Add Lynkow to an Existing Project)
A Lynkow site that sells, with published products
Before the first call
A publishable key on the client
Every commerce call needs the site's publishable key (lkw_pk_...), shown under Settings > Developers > Storefront. Without it, a call throws a LynkowError with code 'UNAUTHORIZED'. The key is safe to ship to the browser. Pass it to the client of Guide 22:
// lib/lynkow.ts
import { createClient } from 'lynkow'
export const lynkow = createClient({
siteId: process.env.NEXT_PUBLIC_LYNKOW_SITE_ID!,
publishableKey: process.env.NEXT_PUBLIC_LYNKOW_PUBLISHABLE_KEY,
})Cart, checkout and account pages create one buyer client per request instead (Guide 24).
A server key on your server
When your server calls the API for a buyer, from a Server Action for example, set LYNKOW_SERVER_KEY to the site's server key (lkw_srv_...), from the same page. Without it, all your buyers share one counter for sign-in, checkout and cart changes. The key is a secret: never ship it to the browser. See Server Key and Buyer IP.
When e-commerce is not enabled on the site
The commerce calls answer 404 when e-commerce is not enabled on the site, with the same apiCode as a missing record: PRODUCT_NOT_FOUND on catalog reads, CART_NOT_FOUND on the cart and on checkout, ORDER_NOT_FOUND on order reads. Your code cannot tell the two apart, so render the not-found page for both:
// app/products/page.tsx (excerpt)
import { notFound } from 'next/navigation'
import { isLynkowError } from 'lynkow'
import { lynkow } from '@/lib/lynkow'
export default async function CatalogPage() {
try {
const { data: products } = await lynkow.products.list({ limit: 24 })
return <ProductGrid products={products} />
} catch (error) {
if (isLynkowError(error) && error.apiCode === 'PRODUCT_NOT_FOUND') notFound()
throw error
}
}A terms of sale page
The merchant chooses the terms page in Settings > E-commerce > Store (Terms page). Only a published page with the Terms of Service category can be chosen. Until one is chosen, or once the chosen page is no longer published, every checkout and every booking is refused with TERMS_PAGE_NOT_CONFIGURED. The checkout links that page next to the terms box (Guide 24).
Markets and shipping options, for delivery
A delivery order needs markets and shipping options set up by the merchant. A pickup order needs neither. Guide 23 covers the country list, shipping and VAT.
Online payment or offline methods
Checkout takes one of four paymentMethod values:
'card'takes an online payment (Guide 24). It works only when online payment is set up on the site. Otherwise checkout refuses it withPAYMENT_METHOD_UNAVAILABLE, and the cart stays open for another method.'on_site','cash_on_delivery'and'click_and_collect'settle offline. The order is placed unpaid, and the merchant marks it paid from the dashboard.
No storefront read lists the methods a shop accepts. Offer the ones the merchant set up.
The pages a shop needs
Page | Route | SDK calls | Built in |
|---|---|---|---|
Catalog, category and collection pages | your own |
| |
Product page | your own |
| |
Cart | your own |
| |
Checkout | your own |
| |
Payment return |
|
| |
Payment cancel |
| none | |
Order confirmation | your own | the result of | |
Guest order page |
|
| |
Account and order history | your own |
| |
Bookings, for bookable products | your own |
|
Lynkow sends buyers to the paths of the Route column, so serve them as written. The guest order page sits under the locale prefix of the order's language. Build product URLs from their path field, with a catch-all route if you like (Guide 9). Guide 15 adds a search box over the catalog.
Keep the shop in sync
Create the webhooks as in Guide 11: one for catalog events on your revalidation route, one for order and payment events on a route of their own.
Catalog events
Subscribe the revalidation route to the product, product_variant, product_category and product_collection events. Product, category and collection payloads carry path, the page's public URL, to revalidate as is (Guide 11). Variant payloads carry productId and no path, so revalidate your product reads by tag.
Stock after a sale
Checkout takes the units and a cancelled order returns them, without any product or variant event. Product reads are cached for up to five minutes, and a sale does not refresh them. A product page can therefore show availability: 'in_stock' after the last unit sold.
Treat availability as a hint and rely on the cart and the checkout, which read live stock. On a site that refuses overselling, cart.addLine() and checkout.placeOrder() refuse a quantity above the stock left with OUT_OF_STOCK, and nothing is sold (Guide 18). Order payloads name each line by variantId only, with no product id or path, so an order event cannot tell you which product page to revalidate.
Order and payment events
Event | Fires when | Use it to |
|---|---|---|
| Checkout places an order, whatever the payment method. An order placed with | Notify your team, sync the buyer to a CRM |
| An online payment is captured, or the merchant marks an offline order paid | Start fulfilment |
| The merchant cancels an order, or an order placed with | Stop fulfilment |
| An online payment is captured, for an order or a booking deposit | Reconcile payments |
| A captured order is cancelled, or a capture lands on an order already cancelled | Issue the refund, which is yours to make |
The order.* payloads carry the order's id (ord_...), orderNumber, email, status, paymentStatus, paymentMethod, currency, totalCents, locale and items, each with variantId, quantity, title and variantSku. The payment.* payloads carry their own id, orderId (or bookingId for a deposit), amountCents, currency and outcome, which reads 'refund_pending' when the money must go back.
A delivery can arrive more than once. Every order and payment delivery carries data.eventId, the same across repeats: record it, and skip an event you already handled.
// app/api/lynkow/orders/route.ts
import { verifySignature } from '@lynkow/next/server'
import { alreadyHandled, markHandled, startFulfilment } from '@/lib/fulfilment'
export const runtime = 'nodejs'
interface OrderPayload {
eventId: string
id: string
orderNumber: number
email: string
items: { variantId: string | null; quantity: number; variantSku: string | null }[]
}
export async function POST(request: Request) {
const secret = process.env.LYNKOW_ORDERS_WEBHOOK_SECRET
if (!secret) return Response.json({ error: 'Not configured' }, { status: 503 })
const rawBody = await request.text()
if (!verifySignature(rawBody, request.headers.get('x-webhook-signature'), secret)) {
return Response.json({ error: 'Unauthorized' }, { status: 401 })
}
const { event, data } = JSON.parse(rawBody) as { event: string; data: OrderPayload }
if (await alreadyHandled(data.eventId)) return Response.json({ duplicate: true })
switch (event) {
case 'order.paid':
await startFulfilment(data)
break
// Add 'order.cancelled', 'payment.refund_pending' and the others you subscribed to.
}
await markHandled(data.eventId)
return Response.json({ received: true })
}verifySignature checks the signature and the delivery's timestamp, as described in Guide 11. Answer 2xx only once the work is saved: any other answer is a failed delivery. When every webhook subscribed to the event fails, Lynkow sends it again later to all of them (Guide 11).
Next Steps
Guide 18: Product Catalog - the catalog, product pages and their public URLs.
Guide 24: Cart and Checkout - the cart, the checkout and the online payment pages.
Guide 11: Webhooks & Cache Revalidation - signatures, delivery and every event.