Skip to content

Unstack × Swft — Pilates booking quickstart

End-to-end Next.js + Supabase integration that uses Swft as headless checkout for a multi-tenant Pilates booking platform. Every file in this directory is a stand-alone copy-paste recipe — adapt names but keep the structure.

  1. Onboard a studio as a Swft merchant via the agency API, including Stripe Connect + a cobalt-pilates.checkouts.unstack.co.uk subdomain.
  2. Create checkout sessions with extensions.booking carrying the class id, customer id, reformer assignment, and payment type.
  3. Pre-confirmation hook that verifies class capacity right before Stripe charges.
  4. Webhook handlers for order.completed (single bookings), subscription.created/renewed (monthly memberships → grant credits), and subscription.cancelled (revoke access).
  5. Refund/cancellation flows that round-trip through Swft.
FilePurpose
lib/swft.tsTiny typed client around /v2/agencies/*
app/api/studios/onboard/route.tsPOST /api/studios/onboard — calls Swft to mint a merchant
app/api/bookings/new/route.tsServer action that creates a session with booking extensions
app/api/swft/capacity-check/route.tsThe pre-confirmation hook
app/api/swft/webhooks/route.tsThe unified Standard Webhooks consumer
lib/membership-credits.tsGrants/refreshes class credits from subscription events
SWFT_PARTNER_KEY=swft_ak_live_…
SWFT_WEBHOOK_SECRET=whsec_…
SWFT_PRECONFIRM_SECRET=whsec_…
SWFT_WORKSPACE_ID=<your workspace uuid>
SWFT_API_URL=https://api.swft.co.uk