Files
co-lite/openspec/changes/archive/2026-12-04-add-event-tickets/design.md
T

11 KiB

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/<code> 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 first calls the portal's /api/tickets/{code}, which answers 401 at once when there is no session and otherwise calls GET /api/admin/tickets/{code}. Only when that fails does it load the public view (GET /api/public/tickets/{code}), so a door scan never counts toward the public tkt:load limit. 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|<time>, NOT_VALID|<state> and NOT_EVENT_DAY. The update is conditional (checked_in_at IS NULL), so two scanners cannot both check a ticket in; the loser gets ALREADY_CHECKED_IN. The action is @Audited.

  7. Self check-in on a ticketed event. For tickets_enabled events only, EventCheckInService.lookup checks, in order:

    1. the oldest ACTIVE ticket on a PAID order of the event, not checked in, whose attendee mobile or email matches, or whose attendee is blank and whose order's buyer mobile or email matches. It is checked in with checked_in_by = 'self', and the lead is marked attended when the ticket has one;
    2. a registered guest of the event, as today;
    3. otherwise the result is SHOW_TICKET.

    The walk-in register path refuses a ticketed event with 409 TICKETS_ONLY. The welcome uses the attendee's first name, or the buyer's for an unnamed ticket.

  8. QR PNG in mobile-api. GET /api/public/tickets/{code}/qr.png:

    • checks the code shape and validity through counter ticket/byCode; an invalid or unknown code is 404;
    • encodes <admin-portal-base>/t/<code> with zxing QRCodeWriter at 300 px, written by ImageIO;
    • responds Cache-Control: private, max-age=300;
    • counts toward the tkt:load limit.

    The portal proxies it like the page images. Emails use the absolute portal URL in <img src>.

  9. Order page tickets. Counter byToken adds tickets: [{id, typeName, attendeeName, code, state, checkedInAt}] only when the order is PAID. mobile-api passes them through without attendee mobile or email: the counter does not return those to the public call at all.

  10. Emails. TicketOrderMailer:

    • PAID: gains one block per active ticket: the type, the QR <img> and the link. It ends with "Name your attendees: ".
    • New kind TICKET: sends one ticket to its attendee (or to the buyer, when staff resend an unnamed ticket), with the consent invitation link pointing to the ticket page.
    • All of them are sent after commit and are best effort, as today.
  11. Counts. EventHeadcountService.Headcount gains ticketsAwaiting, ticketsPaid and ticketsCheckedIn, from one grouped query over active tickets joined to their order status. The portal's GuestsCard shows them when the event sells tickets.

  12. Limits.

    • tkt:load:<ip> allows 120 per 10 minutes, for the ticket page and the QR together.
    • tkt:submit:<ip>:<event> allows 60 per 10 minutes, for naming and consent. Naming first looks up the order by its token, which counts toward the order page's ord:load:<ip> limit (120 per 10 minutes).
    • Staff check-in has no IP limit: it is an authenticated admin call.

Data

sql/01-ticket-attendees.sql (services-counter, additive):

ALTER TABLE `ticket`
  ADD COLUMN `attendee_named_at`   datetime NULL,
  ADD COLUMN `attendee_consent_at` datetime NULL,
  ADD COLUMN `attendee_notice_id`  bigint   NULL,
  ADD KEY `idx_ticket_event_mobile` (`event_uuid`, `attendee_mobile_e164`),
  ADD KEY `idx_ticket_event_email` (`event_uuid`, `attendee_email`);
  • sql/02-ticket-labels.sql holds the labels, cut from npm run i18n:sql.
  • sql/99-rollback.sql drops the three columns and two keys. Codes stay, because change 1 owns the column.

Endpoints

Layer Method and path Auth
counter GET ticket/byCode/{code} public via gateway
counter POST ticket/attendee (order token, ticket id, attendee, permission) public via gateway
counter POST ticket/consent (code, notice id) public via gateway
counter POST ticket/staff and POST ticket/checkin (company id and code in the body) JWT (from mobile-api admin)
counter POST ticketOrder/resendTicket (company, event, order and ticket ids in the body) JWT
mobile-api GET /api/public/tickets/{code}, GET .../qr.png, POST .../consent public
mobile-api POST /api/public/orders/{token}/tickets/{ticketId}/attendee public
mobile-api GET /api/admin/tickets/{code}, POST /api/admin/tickets/{code}/checkin BO_EVENTS
mobile-api POST /api/admin/events/{uuid}/orders/{orderId}/tickets/{ticketId}/resend BO_EVENT_TICKETS
gateway public: GET /counter/ticket/byCode/[A-Za-z0-9_-]{22}, POST /counter/ticket/attendee, POST /counter/ticket/consent
portal /t/[code] page (public in the route guard); proxies for each mobile-api path above

Risks / Trade-offs

  • Mobile-only attendees get no ticket message. The buyer shares the link. Mitigation: the order page shows each ticket's link with a copy button. WhatsApp delivery can follow once the business account is linked.
  • A forwarded ticket link works for whoever holds it. This is the same as any paper ticket; check-in is one-time. Mitigation: renaming replaces the code.
  • Staff view on a phone needs a signed-in session in that phone's browser. That is the existing portal login; the door staff sign in once.
  • New dependency com.google.zxing:core, MIT-style Apache 2.0, no transitive dependencies, used only for the email PNG.
  • Self check-in matching an unnamed ticket to its buyer lets the buyer check in once per unnamed ticket. Each lookup takes one ticket, which matches the buyer bringing friends whose names were never given. ponytail: no per-person cap; add one if abuse is seen.

Migration Plan

  1. Run sql/01-ticket-attendees.sql before the new services-counter starts. It is additive, and the old images ignore the columns.
  2. Deploy services-counter, mobile-api, api-gateway and the portal.
  3. Run sql/02-ticket-labels.sql.
  4. Orders paid before this release have tickets without codes. A one-off statement in 01 gives every active ticket on a PAID order a code, using REPLACE(TO_BASE64(RANDOM_BYTES(16)), ...) trimmed to the 22-character URL-safe form.
  5. Rollback: the previous images, then 99.

Open Questions

None for the owner. Builder calls are recorded above (decisions 4, 5 and 7) and in the release note.