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.
What this covers
Section titled “What this covers”- Onboard a studio as a Swft merchant via the agency API,
including Stripe Connect + a
cobalt-pilates.checkouts.unstack.co.uksubdomain. - Create checkout sessions with
extensions.bookingcarrying the class id, customer id, reformer assignment, and payment type. - Pre-confirmation hook that verifies class capacity right before Stripe charges.
- Webhook handlers for
order.completed(single bookings),subscription.created/renewed(monthly memberships → grant credits), andsubscription.cancelled(revoke access). - Refund/cancellation flows that round-trip through Swft.
File layout
Section titled “File layout”| File | Purpose |
|---|---|
lib/swft.ts | Tiny typed client around /v2/agencies/* |
app/api/studios/onboard/route.ts | POST /api/studios/onboard — calls Swft to mint a merchant |
app/api/bookings/new/route.ts | Server action that creates a session with booking extensions |
app/api/swft/capacity-check/route.ts | The pre-confirmation hook |
app/api/swft/webhooks/route.ts | The unified Standard Webhooks consumer |
lib/membership-credits.ts | Grants/refreshes class credits from subscription events |
Environment
Section titled “Environment”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