Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
14 KiB
Design
Product design: docs/superpowers/specs/2026-12-04-event-ticketing-design.md (approved 2026-12-04). This file holds the technical contracts for change 1 of 2.
Context
- Events, event leads, QR registration, landing pages (
cms_page) and the capacity count (EventHeadcountService) live insolvway-services-counter. solvway-mobile-apiis the only door for the portal:- admin endpoints are
/api/admin/**, gated by module and scoped by company throughloadEvent; - public endpoints are
/api/public/**, rate-limited in Redis throughPublicRegistrationService.limit.
- admin endpoints are
- The landing page FORM block is the model for TICKETS:
PublicPageService.pageenriches a block withformorclosed;PublicPageService.submitchecks the honeypot, appliesreg:submit:<event>:<ip>, and posts to the counter.
- The api-gateway opens only listed public counter paths.
- The legacy Tastefully tables
orders/orders_detailsexist and are unused. New tables use other names so the two are never confused.
Goals / Non-Goals
Goals:
- Ticket settings and types.
- The TICKETS block.
- Orders with seat locking.
- The order page.
- Order emails.
- The expiry job.
- Staff order screens.
- The buyer as an event lead.
- Held tickets in the capacity count.
Non-Goals (change 2, add-event-tickets):
- Ticket QR codes and the
/t/page. - Naming attendees and consent.
- Ticket emails.
- Door and self check-in for tickets.
- Invites counted as free tickets.
- Ticket numbers in attendance.
The ticket row and its code column are created now, so change 2 adds no table.
Decisions
1. Data (SQL in sql/)
01-event-ticket-orders.sql (service-counter, additive):
eventgains:tickets_enabledbit NOT NULL DEFAULT 0;payment_instructionsvarchar(1000) NULL;hold_daysint NOT NULL DEFAULT 3.
ticket_type:- Columns: id, company_id, event_uuid, name varchar(80), price_sen int, quantity int, sales_end_date date NULL, sort int, enabled bit, plus the created and updated fields.
- Unique key
(event_uuid, name).
shop_order:- Columns:
- id, company_id, event_uuid NULL (null is reserved for a later standalone shop);
- reference varchar(12), token varchar(32);
- buyer_name varchar(100), buyer_email varchar(254), buyer_mobile_e164 varchar(20) NULL, buyer_company varchar(150) NULL;
- lead_id, event_lead_id;
- status varchar(20), total_sen int, hold_until datetime;
- paid_at, paid_by, payment_ref varchar(100), cancelled_at, cancelled_by, expired_at;
- consent_at, consent_notice_id, page_path, utm_source, utm_medium, utm_campaign;
- last_email varchar(20), created_at.
- Unique keys
(company_id, reference)and(token). - Indexes
(event_uuid, status),(status, hold_until)and(event_uuid, buyer_email, status).
- Columns:
shop_order_line:- Columns: id, order_id, kind varchar(10) (
TICKET;PICKUPandSHIPare reserved), item_id (the ticket_type id), name varchar(80), unit_price_sen, quantity.
- Columns: id, order_id, kind varchar(10) (
ticket:- Columns: id, company_id, event_uuid, order_id, order_line_id, ticket_type_id, code varchar(32) NULL, attendee_name, attendee_mobile_e164, attendee_email, event_lead_id, status varchar(10) (
ACTIVEorCANCELLED), cancelled_at, cancelled_by, checked_in_at, checked_in_by. - Index
(ticket_type_id, status). codeand the attendee and check-in columns stay null until change 2.
- Columns: id, company_id, event_uuid, order_id, order_line_id, ticket_type_id, code varchar(32) NULL, attendee_name, attendee_mobile_e164, attendee_email, event_lead_id, status varchar(10) (
02-event-tickets-module.sql (service-system) inserts (41160000, 'BO_EVENT_TICKETS', 'Event tickets', 'BO', 'M', 40000000, NULL, NULL). No role gets it by default.
Both files are mirrored in local/seed/03-colite.sql. 99-rollback.sql drops the new tables and columns, and the module.
Money is integer sen everywhere; the portal formats it as RM 1,234.00. References are T- plus 6 characters from 23456789ABCDEFGHJKMNPQRSTUVWXYZ, retried on a unique-key clash. Tokens are 22 URL-safe base64 characters from SecureRandom, the same shape as invite tokens.
2. Seat locking
TicketOrderService.request runs in one transaction:
- Load the event
FOR UPDATE(@Lock(PESSIMISTIC_WRITE)). Every request for the event is serialised there. A request takes milliseconds, and per-event volume is low. - Check the event:
- the event is open;
- each type is enabled and within its sales end date;
- the awaiting-payment count for the email is below 3.
- Compute held seats per type with one grouped count over
ticketjoined toshop_orderwhere the ticket isACTIVEand the order isAWAITINGorPAID. - Check each type's seats, then the event capacity before the event days. Registered guests plus walk-ins come from
EventHeadcountService; held tickets come from the same count. - Insert the order, its lines and its tickets.
Staff "mark paid" on an Expired order, and a type's quantity edit, take the same event lock.
EventHeadcountService gains heldTickets, and the invite registration's capacity check adds it (the MODIFIED requirement).
- Rejected: optimistic version counters per type. There would be more retry code, for no benefit at this volume.
- Rejected: a stored seats-left column. It can drift, while a count is always right.
3. services-counter endpoints
All take JSON. companyId is always concrete and is set by mobile-api.
- Settings:
POST /counter/event/saveacceptsticketsEnabled,paymentInstructionsandholdDays. It returns 400 on the field when switching on with blank instructions or when hold days are outside 1 to 14. mobile-api passes these only for callers withBO_EVENT_TICKETS.
- Ticket types:
POST /counter/ticketType/list {companyId, eventUuid}returns[{id, name, priceSen, quantity, salesEndDate, sort, enabled, held, left}].POST /counter/ticketType/save {companyId, eventUuid, id?, name, priceSen, quantity, salesEndDate, sort, enabled, doneBy}returns 409QUANTITY_BELOW_HELDorNAME_TAKEN.POST /counter/ticketType/delete {companyId, eventUuid, id, doneBy}returns 409TYPE_HAS_ORDERS.
- Public request:
POST /counter/ticketOrder/request {companyId, eventUuid, lines:[{ticketTypeId, quantity}], buyerName, buyerEmail, buyerMobileE164, buyerCompany, consentNoticeId, consentAt, pagePath, utmSource, utmMedium, utmCampaign}.- It returns
{reference, token, status, totalSen, holdUntil, lines, paymentInstructions}. - It returns 409 with one of these codes:
TICKETS_CLOSED;TYPE_UNAVAILABLE {ticketTypeId, name, left};EVENT_FULL {left};TOO_MANY_AWAITING;BAD_QUANTITY.
- After the insert, it captures the buyer with
RegistrationService.register, using sourceTICKET, no salesperson, the page path and UTM, and anorderReferencethat is written to the notes when the event lead already existed. It then storeslead_idandevent_lead_idon the order. - A total of 0 sets the order
PAIDwithpaid_by = 'system'.
- Public order page:
GET /counter/ticketOrder/byToken/{token}returns{companyId, eventUuid, reference, status, buyerName, totalSen, holdUntil, createdAt, lines}, or 404.
- Staff:
POST /counter/ticketOrder/list {companyId, eventUuid, status?, q?, page, size≤50}returns a page of{id, reference, buyerName, buyerEmail, tickets, totalSen, status, createdAt}, newest first.POST /counter/ticketOrder/get {companyId, orderId}returns the full order with lines, tickets, buyer, payment and state history fields.POST /counter/ticketOrder/markPaid {companyId, orderId, paymentRef, doneBy}returns 409NOT_PAYABLEorSEATS_GONE.POST /counter/ticketOrder/cancel {companyId, orderId, doneBy}returns 409NOT_CANCELLABLE.POST /counter/ticketOrder/cancelTicket {companyId, orderId, ticketId, doneBy}returns 409LAST_TICKETorNOT_CANCELLABLE.POST /counter/ticketOrder/resend {companyId, orderId}.
- Expiry job:
TicketOrderExpiryJobruns@Scheduled(cron = "${tickets.expiry.cron:0 */10 * * * *}"), which is within the spec's 15 minutes.- It moves
AWAITINGorders withhold_until < nowtoEXPIREDin batches of 100. Each order is a conditional updateWHERE status='AWAITING', so it never races with mark paid. - It queues the expired email.
4. Order emails (services-counter)
- Sender:
TicketOrderMailersends the emails after commit (TransactionSynchronization.afterCommit, asStaffNotifierdoes) through the existing counterEmailService.send, which goes to services-email. They are recorded in Emails, withcompanyIdset to the event's company. - Content:
- Every user value is HTML-escaped.
- The text is English, then Bahasa Malaysia, as the invite email is.
- The link is
<app.admin-portal-base-url>/o/<token>. This is a new counter setting. Only the local profile has a default (http://localhost:3001); elsewhere it is required.
- Record:
last_emailrecords the latest kind (RECEIVED,PAID,EXPIREDorCANCELLED), so resend sends that kind again. - Failures: they are logged with the order id only, and never roll back the order.
5. Landing page block (services-counter and mobile-api)
CmsBlockValidatorTICKETS:eventUuidis required, belongs to the company, and is enabled, not ended andtickets_enabled.headingis at most 120 characters,textat most 1000.eyebrow,lookandanchorare allowed.- Every other field is refused with
PagesUnusedField.
PublicPageService.page: for a TICKETS block it addstickets: {eventName, startDate, endDate, location, notice, types:[{id, name, priceSen, left, state: ON_SALE|SOLD_OUT|ENDED}]}when the event accepts requests, elseclosed: true.POST /api/public/pages/{company}/{slug}/tickets/{block}:- It follows
submit: the samepage:loadandreg:submit:<event>:<ip>limits, the honeypot, and consent from the company's current notice. - It normalises the inputs with the
PublicRegistrationServicehelpers, then posts to counterticketOrder/request. - On the honeypot it returns a fake success without a token, and the portal shows the thank-you without a link.
- It follows
GET /api/public/orders/{token}:- It checks the token shape first, then applies
ord:load:<ip>at 120 per 10 minutes. - It returns the order with the event's name, dates and location, and the payment instructions only while
AWAITING. Otherwise it gives 404ORDER_INVALID.
- It checks the token shape first, then applies
- Public types:
GET /counter/ticketType/onSale/{eventUuid}returns only{ticketsOpen, paymentInstructions, types:[{id, name, priceSen, left, state}]}for enabled types.- mobile-api's public calls run without a user token, so they pass through the api-gateway's public path list, as
registration/registerandcmsPage/findPublisheddo. - The staff
ticketType/list, which needs a company, stays closed.
- Gateway: open these anchored pairs in
JWTAuthFilter:POST /counter/ticketOrder/request;GET /counter/ticketOrder/byToken/[A-Za-z0-9_-]{22};GET /counter/ticketType/onSale/\d{1,19}.
6. mobile-api admin
- Endpoints, gated by
BO_EVENT_TICKETS, with the company scope fromloadEventand@Audited:GETandPUT /api/admin/events/{uuid}/tickets/settings;GET,POST,PUTandDELETE /api/admin/events/{uuid}/ticket-types[/{id}];GET /api/admin/events/{uuid}/orders?status&q&page;GET /api/admin/events/{uuid}/orders/{orderId};POST /api/admin/events/{uuid}/orders/{orderId}/paid {paymentRef};POST .../cancel,POST .../tickets/{ticketId}/cancelandPOST .../resend.
- Scoping: the order is fetched with
companyIdand must belong to{uuid}, else 404. - Event GET: it gains
ticketsEnabledfor every reader, so the portal knows when to show the section.
7. Portal
- Event page:
- A Tickets section shows when the user has
BO_EVENT_TICKETS. It holds the settings form, the ticket types table (with add, edit and disable or delete), and a link to the orders. - Orders are at
/events/[uuid]/orders, a listing with a filter and search, and/events/[uuid]/orders/[orderId], the detail page with its actions and confirm dialogs. ROUTE_MODULESmaps both pages toBO_EVENT_TICKETS.
- A Tickets section shows when the user has
- TICKETS block:
- It is rendered in
CmsBlocks.tsxasTicketsBlock, with types, quantity steppers, the running total, the buyer fields and the consent. It reuses theRegistrationFormfield and consent pieces, plus a thank-you state. - The editors add it to
BLOCK_TYPES,emptyBlockandBlockFields, with an event picker limited to events with tickets on, usingticketsEnabledfrom the events list. - The canvas shows the real types through the preview data.
- It is rendered in
- Order page:
/o/[token]is public inrouteGuard, sharing the pattern for/r/,/i/and/c/. Its proxy isapp/api/public/orders/[token], which forwards the last X-Forwarded-For hop as the other proxies do. - Labels in
defaultMessages.tsandzh_CN.seed.json, plussql/03-*-labels.sqlcut fromnpm run i18n:sql.
Risks / Trade-offs
- Event row lock under a rush. Requests for one event are serialised. That is fine at the expected volume (tens per minute). If a big launch needs more, move to per-type locks.
- Seat hoarding. One email can hold up to 30 seats (3 orders × 10) for the hold days, and many emails can hold more. This is mitigated by the IP limit, the honeypot and staff cancel. A CAPTCHA is deferred.
- Emails in English and BM only, matching invites. The zh-CN email text is deferred with the rest of the email localisation.
- Expired orders may still be paid. Staff can rescue them only while their seats are free. This is refused clearly otherwise.
Migration Plan
- Run
sql/01andsql/02before the new images go live. Only new tables and defaulted columns are added, so the running images are unaffected. - Set
app.admin-portal-base-urlon services-counter. - Deploy services-counter, mobile-api, api-gateway and admin-portal together.
- A super admin grants Event tickets to the right roles.
- Rollback: deploy the previous images;
99-rollback.sqlonly if the data should go too.