ogutdgn

payload booking

by ogutdgn
Other
v3
^3.84.1
MIT

Overview

Summary generated from the README

Adds appointment booking to Payload 3.x. Visitors pick a real time slot, the appointment appears in the admin, and both sides receive email. A unique lock key in the database prevents the same slot from being booked twice on PostgreSQL or MongoDB. Requires a token secret, access functions and your own booking and cancel pages that render the exported components.

Features

  • Unique database lock key per slot so concurrent requests get one success and one conflict
  • Cancellation as a status change with signed magic-link tokens for customers
  • Server-side time computation in the business timezone with configurable weekly schedule and capacity
  • Exported BookingForm and CancelView components plus useBookingFlow and useCancelFlow hooks
  • Spam protection with honeypot, signed time-trap token, per-IP and per-email caps, and optional challenge verification
  • Admin overrides for labels, fields and columns without weakening booking guarantees

Use cases

  • Let visitors book showroom or office visits from a Payload-powered site without double bookings
  • Build a custom booking wizard on top of the headless booking hooks and endpoints
  • Give staff an admin view to cancel appointments or mark them completed or no-show

From the author

Appointment booking for Payload CMS 3.x: database-enforced slot uniqueness, magic-link cancellation, and exported booking UI.

Installation

npm i @ogutdgn/payload-booking

0

Stars

0

Forks

0

Open Issues

2 months ago

Last Updated

8

Weekly Downloads

v0.1.2

npm Version

666.0 KB

Unpacked Size

4

Dependencies

GitHub stars

00 since Sep 13

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
Oct 24, 20260
Oct 23, 20260
Oct 22, 20260
Oct 21, 20260
Oct 20, 20260
Oct 19, 20260
Oct 18, 20260
Oct 17, 20260
Oct 16, 20260
Oct 15, 20260
Oct 14, 20260
Oct 13, 20260
Oct 12, 20260
Oct 11, 20260
Oct 10, 20260
Oct 9, 20260
Oct 8, 20260
Oct 7, 20260
Oct 6, 20260
Oct 5, 20260
Oct 4, 20260
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20260
Sep 25, 20260
Sep 24, 20260
Sep 23, 20260
Sep 22, 20260
Sep 21, 20260
Sep 20, 20260
Sep 19, 20260
Sep 18, 20260
Sep 17, 20260
Sep 16, 20260
Sep 15, 20260
Sep 14, 20260
Sep 13, 20260
npm weekly downloads

9−80 since Sep 19

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20269
Dec 4, 202612
Dec 3, 202612
Dec 2, 20268
Dec 1, 202613
Nov 30, 202611
Nov 29, 202610
Nov 28, 20269
Nov 27, 20266
Nov 26, 20266
Nov 25, 20268
Nov 24, 20264
Nov 23, 20267
Nov 22, 20269
Nov 21, 20269
Nov 20, 202610
Nov 19, 202610
Nov 18, 202611
Nov 17, 202613
Nov 16, 202612
Nov 15, 202613
Nov 14, 202613
Nov 13, 202614
Nov 12, 202615
Nov 11, 202611
Nov 10, 202610
Nov 9, 202611
Nov 8, 202611
Nov 7, 202611
Nov 6, 202610
Nov 5, 202610
Nov 4, 202616
Nov 3, 202614
Nov 2, 202614
Nov 1, 202613
Oct 31, 202615
Oct 30, 202615
Oct 29, 202614
Oct 28, 20268
Oct 27, 202614
Oct 26, 202613
Oct 25, 202613
Oct 24, 202613
Oct 23, 202612
Oct 22, 202614
Oct 21, 202617
Oct 20, 202614
Oct 19, 202615
Oct 18, 202614
Oct 17, 202613
Oct 16, 202615
Oct 15, 202617
Oct 14, 202614
Oct 13, 202614
Oct 12, 202611
Oct 11, 202612
Oct 10, 202613
Oct 9, 202613
Oct 8, 202610
Oct 7, 202614
Oct 6, 202613
Oct 5, 202614
Oct 4, 202613
Oct 3, 202615
Oct 2, 202621
Oct 1, 202625
Sep 30, 202629
Sep 29, 202637
Sep 28, 202666
Sep 27, 202690
Sep 26, 2026415
Sep 25, 2026496
Sep 24, 2026491
Sep 23, 2026483
Sep 22, 2026473
Sep 21, 2026443
Sep 20, 2026418
Sep 19, 202689

Each point is npm's rolling 7-day download count.

Health Score

55/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1373499609-root.svg)](https://payloaddirectory.dev/plugins/1373499609-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1373499609-root"><img src="https://payloaddirectory.dev/badge/1373499609-root.svg" alt="Payload Directory"></a>
Updated Sep 17, 2026Created Sep 16, 2026Published Sep 17, 2026

README

@ogutdgn/payload-booking

Appointment booking for Payload CMS 3.x.

A visitor picks a real time slot on your site, the appointment appears in the Payload admin, both sides get email, either side can cancel, and the same slot can never be sold twice — enforced by a database uniqueness constraint, not by application logic.

Status: 0.1.0. In use but not yet proven in production, so the version stays below 1.0 until the first client site has run it for a while. The build specification is PLUGIN_BOOKING_SPEC.md, and it is the source of truth for every behaviour described here.

What it does

  • Never double-books. Each slot-holding appointment carries a unique lock key, so two visitors submitting the same second get one 201 and one 409. Verified on PostgreSQL and MongoDB.
  • Cancel is a status change, never a delete. Audit trail, slot release and emails all run through one code path.
  • All time is computed server-side in the business timezone. The browser receives labels and echoes opaque ISO strings.
  • Nothing in the package is host-specific. Hours, timezone, capacity, addresses and routes come from plugin options or the settings global.
  • No prices, no payments, no deposits.

Requirements

PackageRange
payload^3.84.1
@payloadcms/ui^3.84.1
react / react-dom^19.0.0

PostgreSQL or MongoDB, through Payload's own adapters. Node 20.9+.

Install

pnpm add @ogutdgn/payload-booking

Add it to your Payload config:

import { bookingPlugin } from '@ogutdgn/payload-booking'

export default buildConfig({
  plugins: [
    bookingPlugin({
      access: { configure: isAdmin, manage: isEditor },
      defaults: {
        resource: { name: 'Showroom' },
        settings: {
          bookingWindow: { mode: 'rolling-days', rollingDays: 14 },
          cancellationCutoffMinutes: 0,
          capacityPerSlot: 1,
          location: '2112 Rutland Dr #150, Austin, TX 78758',
          minNoticeMinutes: 120,
          notificationEmails: ['[email protected]'],
          phone: '(512) 555-0100',
          slotDurationMinutes: 60,
          timezone: 'America/Chicago',
          weeklySchedule: {
            monday: { open: true, sessionStarts: ['09:00', '10:00', '11:00'] },
            // …the rest of the week
          },
        },
      },
      email: { from: 'Vera <[email protected]>' },
      routes: { bookPath: '/schedule', cancelPath: '/appointments/cancel' },
      siteUrl: 'https://example.com',
      tokenSecret: process.env.BOOKING_TOKEN_SECRET!,
    }),
  ],
})

Then run payload generate:importmap.

These values are only the starting point. Everything in defaults.settings is written once, and the owner edits it in the admin afterwards.

Configuration

Required

OptionWhat it does
access.manageWho may read appointments and run the status actions (staff).
access.configureWho may edit settings, locations and closed dates (owner).
defaultsSeed values written once when the settings are empty, plus the first location.
email.fromThe address confirmations are sent from.
routes.bookPath / routes.cancelPathYour own page routes, used to build links in emails.
tokenSecretSigns cancellation links and the anti-bot token. At least 32 characters, and different from PAYLOAD_SECRET.

Optional

OptionDefaultWhat it does
siteUrlPayload's serverURLPublic origin for the links in emails. Set it: serverURL is often empty, and a relative cancel link cannot be opened from an inbox.
apiBasePath/bookingWhere the endpoints mount under Payload's API route.
slugssee belowRename any of the four collections and the global.
labels{ locale: 'en-US', hour12: true }How every time and date is written.
overridesnoneRename screens, add fields, change columns, swap admin components. See below.
supportedTimezonesPayload's own listExtend the timezone choices.
customerFieldsnoneExtra fields on the booking form. Text, textarea, email, number, select and checkbox.
bookingCaps5/hour per IP, 3/hour per email, 3 upcoming per emailPer-visitor limits.
verifyChallengenoneCalled with the challenge token on every booking. See below.
trustProxyfalseWhether to believe X-Forwarded-For. True on Vercel, Cloudflare and most managed hosts. On bare Node the header is client-supplied, so leaving it false keeps the per-IP cap honest.
getClientIpnoneResolve the client IP yourself instead.
honeypotFieldwebsiteName of the hidden field bots fill in.
email.replyTo, email.templatesnoneReply-to address, and per-event template overrides.
onAppointmentChangenoneCalled after a booking or status change commits, for revalidation or analytics.
disabledfalseTurn off the endpoints, emails and seeding while leaving the database schema untouched.

Default slugs: appointments, booking-resources, booking-blackout-dates, booking-settings.

Environment

VariableNotes
BOOKING_TOKEN_SECRETRequired, at least 32 characters, different from PAYLOAD_SECRET. Generate with openssl rand -base64 32.

Spam protection

Four layers, three of them on by default: a hidden honeypot field, a signed time-trap token measured from page load, and caps per email and per IP. The fourth is yours to add: pass a verifyChallenge function and the plugin calls it with the token from whatever widget you render in the form's challenge slot.

verifyChallenge: async (token, ip) => {
  const response = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
    body: JSON.stringify({ remoteip: ip, response: token, secret: process.env.TURNSTILE_SECRET }),
    headers: { 'Content-Type': 'application/json' },
    method: 'POST',
  })
  const result = await response.json()
  return result.success === true
}

A provider that answers "no" rejects the booking. A provider that is unreachable or slow is logged and the booking goes through, because an outage at Cloudflare must not stop a showroom taking bookings while the other three layers still apply.

Endpoints

Mounted under Payload's API route, /api/booking by default.

Method and pathWhoPurpose
GET /availabilitypublicDays and slots, with labels already rendered in the business timezone.
GET /resourcespublicActive locations, id and name only.
GET /form-tokenpublicA fresh anti-bot token per page load.
POST /bookpublicMake a booking.
GET /appointment-by-tokenlink holderWhat the cancellation page shows. Never the customer's email or phone.
POST /cancel-by-tokenlink holderThe customer's own cancellation.
POST /appointments/:id/cancelstaffCancel and email the customer.
POST /appointments/:id/statusstaffMark completed or no-show.

Using it on a site

The plugin cannot own routes, so the host adds two thin pages and renders the exported components. Both are in dev/app/(frontend)/ as working references.

// app/(frontend)/schedule/page.tsx
import { toCustomerFieldDescriptors } from '@ogutdgn/payload-booking'
import { BookingForm } from '@ogutdgn/payload-booking/react'

export default function SchedulePage() {
  return <BookingForm apiUrl="/api/booking" fields={toCustomerFieldDescriptors(customerFields)} />
}
// app/(frontend)/appointments/cancel/[token]/page.tsx
import { CancelView } from '@ogutdgn/payload-booking/react'

export default async function CancelPage({ params }: { params: Promise<{ token: string }> }) {
  const { token } = await params
  return <CancelView apiUrl="/api/booking" token={token} />
}

Then run payload generate:importmap and set BOOKING_TOKEN_SECRET.

Designing your own booking page

The components are one possible shape, not the shape. Three levels of control, pick the one that fits the project.

Restyle them. Skip the stylesheet and name the parts yourself.

<BookingForm classNames={{ slot: 'rounded-xl border px-4 py-3',
                           slotSelected: 'bg-black text-white' }} />

Every visible sentence is replaceable too, through messages.

Write your own markup on our behaviour. useBookingFlow gives you the state and the actions and draws nothing. This is what to reach for when a project needs a calendar grid, a wizard, or anything else that is not a list.

const flow = useBookingFlow({ apiUrl: '/api/booking' })

// flow.days, flow.select(slot), flow.selected, flow.values, flow.setValue(name, value),
// flow.submit(), flow.submitting, flow.fieldErrors, flow.errorCode, flow.success

It handles the parts that are easy to get subtly wrong: keeping availability fresh, fetching the anti-bot token on load and retrying when it expires, and recovering when someone takes the slot mid-form without losing a single field the visitor typed. It returns facts and actions, never wording or UI decisions, so it does not assume your layout. dev/app/(frontend)/wizard is a worked example in a completely different shape.

useCancelFlow does the same for the cancellation page: one state value out of five to branch on, plus confirm().

If even the hooks do not fit, the eight endpoints below constrain nothing.

Changing the admin

Pass overrides to rename screens, add your own fields, change the list columns, or swap a component for one of yours.

bookingPlugin({
  overrides: {
    resources: { labels: { plural: 'Rooms', singular: 'Room' } },
    appointments: {
      admin: { defaultColumns: ['slotStart', 'title', 'status'] },
      fields: ({ defaultFields }) => [
        ...defaultFields,
        { name: 'assignedTo', type: 'relationship', relationTo: 'users' },
      ],
    },
  },
})

Your fragment is merged on top of what the plugin built, and your hooks run after ours rather than replacing them.

What an override cannot do is weaken a guarantee. Remove the unique lock key, the status guard or a derived time field and the plugin refuses to start, naming the field and why it matters, rather than quietly making "never double-booked" optional.

The admin's look is Payload's own, not the plugin's. You restyle it once per project with Payload's admin stylesheet, and it applies to the whole panel.

Development

pnpm install
createdb payload_booking_dev          # or set DATABASE_URL to an existing database
cp dev/.env.example dev/.env          # then edit DATABASE_URL and BOOKING_TOKEN_SECRET
pnpm dev                              # http://localhost:3000/admin

The dev/ folder is a complete Payload site that mounts the plugin from src/. It is both the test bench and the reference implementation of everything a host has to do.

CommandWhat it does
pnpm devRun the test bench
pnpm typecheckType-check the plugin and the bench
pnpm lintESLint
pnpm test:unitPure unit specs, no database
pnpm test:intIntegration specs against PostgreSQL
pnpm test:int:mongoThe same specs against an in-memory MongoDB
pnpm test:e2ePlaywright browser flows (run npx playwright install chromium once first)
pnpm buildCompile src/ to dist/

The bench chooses its database with DB_ADAPTER (postgres by default, mongo for the adapter-parity suite). PostgreSQL creates the database and pushes the schema automatically outside production, so no migrations are needed locally.

How it avoids double-booking

Most booking systems ask "is this slot free?" and then write the appointment. Those are two steps, and two requests can both pass the check before either one writes.

Here, every slot-holding appointment stores a key built from the location, the exact start instant and a seat number, and that column is unique in the database. The second write is refused by the database itself, so there is no gap to race through. Capacity above one works by seat: the booking endpoint walks seats until one is free, and returns "that time has gone" when they all are.

Cancelling replaces the key with a per-appointment tombstone rather than emptying it. MongoDB indexes an explicitly empty value, so emptying it would let only the first cancellation in the whole system succeed.

Not included

No prices, payments or deposits, ever. Not in version 1: staff creating appointments from the admin, several locations in the booking form, reminder emails, rescheduling in place, partial-day closures, calendar sync, and appointment types with different lengths. The data model already carries the seams for locations and types.

Contributing

Issues and pull requests are welcome. Please run pnpm typecheck, pnpm lint, pnpm test:unit and pnpm test:int before opening one.

License

MIT. See LICENSE.

Similar plugins