diff --git a/openspec/changes/add-event-tickets/.openspec.yaml b/openspec/changes/add-event-tickets/.openspec.yaml new file mode 100644 index 0000000..2ad7578 --- /dev/null +++ b/openspec/changes/add-event-tickets/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-12-04 diff --git a/openspec/changes/add-event-tickets/design.md b/openspec/changes/add-event-tickets/design.md new file mode 100644 index 0000000..ea57035 --- /dev/null +++ b/openspec/changes/add-event-tickets/design.md @@ -0,0 +1,130 @@ +# Design + +Product design: `docs/superpowers/specs/2026-12-04-event-ticketing-design.md` (approved 2026-12-04). This file holds the technical contracts. Change 1 (`add-event-ticket-orders`) already built the `ticket` table with `code`, the attendee columns, `event_lead_uuid` and the `checked_in_*` columns, so this change mostly fills them in. + +## Context + +- **Tickets and orders:** + - Orders and tickets live in services-counter: `TicketOrderService` handles the request and `byToken`; `TicketOrderStaffService` handles mark paid, cancel and resend; `TicketOrderMailer` sends the order emails; `TicketOrderExpiryJob` expires holds. + - mobile-api's `PublicPageService` holds the public order endpoints and `AdminTicketService` the staff ones. + - The gateway's `JWTAuthFilter` lists the counter paths that are public. +- **Venue self check-in:** + - `EventCheckInService.lookup` returns `CHECKED_IN` or `FORM`. + - The walk-in form posts to the existing register path with `attend=true`. +- **Capacity:** "a registered invite counts toward capacity" already holds. `EventGuestService.register`, `TicketOrderService.create` and `EventHeadcountService` all add registered guests, walk-ins and held tickets. No work here. +- **Leads:** `RegistrationService.register(RegisterRequest)` does the QR-registration matching and takes `source`, `consentNoticeId`, `consentAt` and `attend`. It returns the event lead uuid. +- **Portal:** + - `clientApi` redirects to `/login` on a 401. + - `/api/auth/session` does not redirect, and tells whether a staff session exists. + - `qrcode.react` draws QRs in the browser only. + +## Goals / Non-Goals + +**Goals:** +- Ticket codes on payment. +- The `/t/` page with its public and staff views. +- Attendee naming on the order page. +- Attendee consent. +- The paid email with the tickets, the ticket email, and resend ticket. +- Door check-in. +- Self check-in rules on ticketed events. +- The ticket counts. + +**Non-Goals:** +- Payment gateway. +- Merch. +- Member accounts. +- WhatsApp ticket delivery: an attendee named with a mobile only gets no message; the buyer forwards the link. +- Transferring a ticket to another order. +- Printing tickets. + +## Decisions + +1. **Codes are issued when the order becomes Paid.** This happens inside the same transaction as the status change, at three places: `TicketOrderService.create` (free order), `TicketOrderStaffService.markPaid` (Awaiting payment or Expired), and nowhere else. Codes use the existing 22-character `RegistrationLinkService.newToken()`; `uk_ticket_code` guards uniqueness. Cancelling keeps the code, and validity is computed: the order is `PAID` and the ticket is `ACTIVE`. + - *Alternative:* codes at request time. Rejected, because an unpaid order would then carry QRs that look real. +2. **Ticket state, computed in one place.** `TicketState.of(order, ticket)` returns `VALID`, `CHECKED_IN`, `AWAITING`, `ORDER_CANCELLED`, `ORDER_EXPIRED` or `TICKET_CANCELLED`. The public page, the staff view, check-in and self check-in all use it. +3. **Renaming replaces the code.** The attendee save is `POST ticket/attendee` with the order token, ticket id, name, mobile, email and `permission`. In one transaction it: + - checks the order token and that the order is `PAID`; + - checks the ticket is `ACTIVE` and not checked in; + - sets a new code, `attendee_named_at`, the attendee fields, and clears `attendee_consent_at`, `attendee_notice_id` and `event_lead_uuid`; + - after commit, sends the Ticket email when an email is set. + - Normalisation and the `MOBILE_OR_EMAIL_REQUIRED`, name-length and email-format errors reuse the QR registration helpers in mobile-api. +4. **Consent creates the lead through `RegistrationService.register`.** It is called with source `TICKET`, no salesperson, the company's current notice and `attend=false`. At check-in it is called with `attend=true`. The returned event lead uuid is stored on the ticket. An attendee whose details match a lead is linked to it, as QR registration already does. + - **Unnamed tickets:** the consent needs a name and contact, so on the public page it is offered only for a named ticket. At the door, staff enter them first. +5. **Staff view detection.** The `/t/[code]` page always loads the public view (`GET /api/public/tickets/{code}`). When `/api/auth/session` reports a session, it also calls `GET /api/admin/tickets/{code}`. That call is guarded by `@AdminModule("BO_EVENTS")` and scoped by company in mobile-api with `loadEvent(uuid, null)`, so another company's event is a 404. On 401, 403 or 404 the page stays public. The admin call uses a plain `fetch`, not `clientApi`, so a signed-out visitor is never bounced to login. +6. **Check-in.** `POST /api/admin/tickets/{code}/checkin` takes optional `{name, mobile, email, consent}`, which are required when the ticket is unnamed. Refusals are 409 with the codes `ALREADY_CHECKED_IN|