> For the complete Lynkow documentation index in agent-friendly format, see [llms.txt](/llms.txt).

# Build a Shop

**Published**: 2026-11-30
**Category**: Features

> 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](/docs/sdk/features/commerce-cart-checkout) | Next: [Guide 18](/docs/sdk/features/commerce-products)

> **Reference** - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
> 
> - SDK: [`ProductsService`](/docs/sdk/services/sdk-products-service), [`CartService`](/docs/sdk/services/sdk-cart-service), [`PickupPointsService`](/docs/sdk/services/sdk-pickup-points-service), [`CheckoutService`](/docs/sdk/services/sdk-checkout-service), [`OrdersService`](/docs/sdk/services/sdk-orders-service), [`CustomersService`](/docs/sdk/services/sdk-customers-service), [`ReservationsService`](/docs/sdk/services/sdk-reservations-service)
> - Types: [SDK Types](/docs/sdk/types)
> - API: [Storefront: Commerce](/docs/storefront-api/storefront-commerce)

## Prerequisites

- Lynkow SDK installed ([Quick Start](/docs/sdk/getting-started/quick-start), or [Add Lynkow to an Existing Project](/docs/sdk/getting-started/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](/docs/sdk/getting-started/existing-project):

```typescript
// 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](/docs/sdk/features/commerce-cart-checkout#one-buyer-client-per-request)).

### 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](/docs/sdk/advanced/server-key-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:

```tsx
// 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](/docs/sdk/features/commerce-cart-checkout#the-terms-box)).

### Markets and shipping options, for delivery

A delivery order needs markets and shipping options set up by the merchant. A delivery to a pickup point also needs a carrier the merchant connected ([Carrier Connections](/docs/integrations/carrier-connections)). A pickup order, collected from the merchant, needs none of them. [Guide 23](/docs/sdk/features/commerce-markets-shipping-vat) 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](/docs/sdk/features/commerce-cart-checkout#online-payment)). It works only when online payment is set up on the site. Otherwise checkout refuses it with `PAYMENT_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 | `products.list()`, `productCategories.getBySlug()` | [Guide 18](/docs/sdk/features/commerce-products) |
| Product page | your own | `products.getBySlug()` | [Guide 18](/docs/sdk/features/commerce-products#get-one-product) |
| Cart | your own | `cart.addLine()`, `cart.retrieve()` | [Guide 24](/docs/sdk/features/commerce-cart-checkout#the-cart) |
| Checkout | your own | `cart.update()`, `pickupPoints.search()`, `checkout.placeOrder()` | [Guide 24](/docs/sdk/features/commerce-cart-checkout#checkout), [Guide 23](/docs/sdk/features/commerce-markets-shipping-vat) |
| Payment return | `/checkout/payment/return` | `checkout.refreshPayment()` | [Guide 24](/docs/sdk/features/commerce-cart-checkout#the-return-page) |
| Payment cancel | `/checkout/payment/cancel` | none | [Guide 24](/docs/sdk/features/commerce-cart-checkout#the-cancel-page) |
| Order confirmation | your own | the result of `placeOrder()` | [Guide 24](/docs/sdk/features/commerce-cart-checkout#place-the-order) |
| Guest order page | `/order/<token>` | `orders.getGuest()` | [Guide 20](/docs/sdk/features/commerce-customer-accounts#the-guest-order-page) |
| Account and order history | your own | `customers.login()`, `customers.orders()` | [Guide 20](/docs/sdk/features/commerce-customer-accounts) |
| Bookings, for bookable products | your own | `reservations.availability()`, `reservations.book()` | [Guide 19](/docs/sdk/features/commerce-reservations) |


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](/docs/sdk/advanced/catch-all-routes)). [Guide 15](/docs/sdk/features/search) adds a search box over the catalog.

## Keep the shop in sync

Create the webhooks as in [Guide 11](/docs/sdk/advanced/webhooks-revalidation): one for catalog events on your revalidation route, one for order, payment and shipment 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](/docs/sdk/advanced/webhooks-revalidation#4-events-and-payloads)). 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](/docs/sdk/features/commerce-products#when-stock-runs-out)). 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 |
| --- | --- | --- |
| `order.placed` | Checkout places an order, whatever the payment method. An order placed with `'card'` is still unpaid. | Notify your team, sync the buyer to a CRM |
| `order.paid` | An online payment is captured, or the merchant marks an offline order paid | Start fulfilment |
| `order.cancelled` | The merchant cancels an order, or an order placed with `'card'` is cancelled after its online payment failed or expired | Stop fulfilment |
| `payment.captured` | An online payment is captured, for an order or a booking deposit | Reconcile payments |
| `payment.refund_pending` | A captured order is cancelled, or a capture lands on an order already cancelled | Issue the refund, which is yours to make |
| `shipment.created` | The merchant creates a shipment for the order, with or without a carrier label | Update the order in your own systems |
| `shipment.in_transit`, `shipment.out_for_delivery`, `shipment.ready_for_pickup` | The carrier reports that status | Show the tracking status |
| `shipment.delivered` | The carrier reports the parcel delivered. A parcel collected at a pickup point arrives with `status: 'collected'`. | Close the order on your side |
| `shipment.failed` | The carrier reports a failed delivery | Contact the buyer |
| `shipment.cancelled` | The merchant cancels a shipment, or the carrier reports it cancelled | Count its items as left to ship |


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. The `shipment.*` payloads carry their own `id` (`shpt_...`), `orderId`, `orderNumber`, `status`, `carrierName`, `trackingNumber`, `trackingUrl`, `items`, each with `orderItemId`, `variantId` and `quantity`, and `destination`: an address, or the pickup point with the buyer's contact address. They carry no phone number and no email. Only a carrier reports a status, so a parcel the merchant ships by hand fires `shipment.created` and `shipment.cancelled` alone.

A delivery can arrive more than once. Every order, payment and shipment delivery carries `data.eventId`, the same across repeats: record it, and skip an event you already handled.

```typescript
// 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.
    // A shipment payload has its own shape: type it apart.
  }

  await markHandled(data.eventId)
  return Response.json({ received: true })
}
```

`verifySignature` checks the signature and the delivery's timestamp, as described in [Guide 11](/docs/sdk/advanced/webhooks-revalidation#3-write-your-own-handler). 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](/docs/sdk/advanced/webhooks-revalidation#5-delivery)).

## Next Steps

- [Guide 18: Product Catalog](/docs/sdk/features/commerce-products) - the catalog, product pages and their public URLs.
- [Guide 24: Cart and Checkout](/docs/sdk/features/commerce-cart-checkout) - the cart, the checkout and the online payment pages.
- [Guide 11: Webhooks & Cache Revalidation](/docs/sdk/advanced/webhooks-revalidation) - signatures, delivery and every event.