API v2 registrations and payments (1.51.1)

- v2: register, get, cancel and checkout a registration (owner/admin only).
- Registration create/cancel moved to src/services/registrations.ts and online checkout to
  src/services/payments.ts; v1 controllers call the same services (ServiceError carries status).
- Typed frontend calls: npm run api:types writes openapi.json and schema.d.ts; apiV2() helper.
  Register page, Pay now and My Events cancel use v2; apiFetch reads v2 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
2026-10-29 09:09:09 +02:00
co-authored by Claude Opus 5.5
parent 966fa256b6
commit 310684a563
29 changed files with 4117 additions and 741 deletions
+838
View File
@@ -0,0 +1,838 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
export interface paths {
"/events": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* Upcoming public events
* @description Events anyone can see (active, not hidden, live) that have not ended, soonest first.
*
* **Who:** Anyone.
*/
get: operations["getEvents"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/events/{id}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* One public event
* @description With its ticket options (internal kids check-in and volunteer tickets left out) and sessions. Hidden events can be fetched by id (they are unlisted, not private).
*
* **Who:** Anyone.
*/
get: operations["getEventsId"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/registrations": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Register for an event
* @description Signed in, or as a guest for a free event that allows it (`guest` then required), or with a waitlist link (`waitlistToken`).
*
* Registering again for the same event adds to the existing registration. When nothing is owed it is marked paid and tickets are issued; otherwise pay with `POST /registrations/{id}/checkout`.
*
* A coupon that was valid when checked but used up a moment later is reported in `couponError`; the registration is still made.
*
* **Who:** Anyone; signed-in staff may see more.
*/
post: operations["postRegistrations"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/registrations/{id}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* One of my registrations
* @description **Who:** Any signed-in person.
*/
get: operations["getRegistrationsId"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/registrations/{id}/cancel": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Cancel my registration
* @description Not after the event has ended, and not once anything has been paid (the church can do that). Its places go to the waitlist.
*
* **Who:** Any signed-in person.
*/
post: operations["postRegistrationsIdCancel"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/registrations/{id}/checkout": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Pay what I owe online
* @description Starts a payment with the church's provider (Yoco or PayFast) and returns where to send the person (`redirectUrl`).
*
* If an early-bird price ran out since the registration was made, nothing is started: `priceUpdated` is true with the new amount owing — show it, then call again.
*
* **Who:** Any signed-in person.
*/
post: operations["postRegistrationsIdCheckout"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/me": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* The signed-in person
* @description **Who:** Any signed-in person.
*/
get: operations["getMe"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/me/registrations": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* My registrations
* @description Newest first. By default only ones for events that have not ended, and not cancelled; `past=true` lists everything.
*
* **Who:** Any signed-in person.
*/
get: operations["getMeRegistrations"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
}
export type webhooks = Record<string, never>;
export interface components {
schemas: {
Error: {
error: {
/** @enum {string} */
code: "VALIDATION_FAILED" | "UNAUTHENTICATED" | "FORBIDDEN" | "NOT_FOUND" | "CONFLICT" | "RATE_LIMITED" | "READ_ONLY" | "INTERNAL";
message: string;
/** @description Per-field problems (VALIDATION_FAILED only) */
fields?: {
[key: string]: string;
};
};
};
};
responses: never;
parameters: never;
requestBodies: never;
headers: never;
pathItems: never;
}
export type $defs = Record<string, never>;
export interface operations {
getEvents: {
parameters: {
query?: {
/** @description Page number, from 1 */
page?: number;
/** @description Items per page (at most 100) */
limit?: number;
/** @description Search the title */
q?: string;
/** @description A campus id or slug (its events plus church-wide ones), or 'all' for church-wide events only */
campus?: string;
/** @description A series slug */
series?: string;
};
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
id: string;
title: string;
/** Format: date-time */
startDate: string;
/** Format: date-time */
endDate: string;
location: string | null;
/** @description The headline price in rand (0 = free) */
price: number;
pictureUrl: string | null;
requiresRegistration: boolean;
/** @enum {string} */
scheduleType: "single" | "sessions";
/** @description null = for all campuses (or campuses are off) */
campus: {
id: string;
name: string;
slug: string;
} | null;
series: {
id: string;
name: string;
slug: string;
} | null;
}[];
meta: {
page: number;
limit: number;
/** @description Items across all pages */
total: number;
/** @description Number of pages (at least 1) */
pages: number;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
getEventsId: {
parameters: {
query?: never;
header?: never;
path: {
/** @description The id */
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
id: string;
title: string;
/** Format: date-time */
startDate: string;
/** Format: date-time */
endDate: string;
location: string | null;
/** @description The headline price in rand (0 = free) */
price: number;
pictureUrl: string | null;
requiresRegistration: boolean;
/** @enum {string} */
scheduleType: "single" | "sessions";
/** @description null = for all campuses (or campuses are off) */
campus: {
id: string;
name: string;
slug: string;
} | null;
series: {
id: string;
name: string;
slug: string;
} | null;
description: string | null;
registrationDeadline: string | null;
ticketOptions: {
id: string;
name: string;
/** @description The normal price in rand */
price: number;
/** @description What it costs now (an early-bird price while one runs) */
currentPrice: number;
isMainTicket: boolean;
/**
* @description "pick" = the buyer chooses sessions
* @enum {string}
*/
sessionMode: "all" | "pick";
}[];
/** @description Multi-day events only; empty otherwise */
sessions: {
id: string;
label: string | null;
/** Format: date-time */
startsAt: string;
/** Format: date-time */
endsAt: string;
location: string | null;
cancelled: boolean;
}[];
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not found (NOT_FOUND) */
404: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
postRegistrations: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
eventId: string;
options: {
eventOptionId: string;
quantity: number;
variantId?: string | null;
/** @description "Pick sessions" tickets: the sessions chosen */
sessionIds?: string[];
}[];
guest?: {
name: string;
/** Format: email */
email: string;
phone?: string;
};
couponCode?: string;
/** @description Names for the places (events that collect them) */
attendees?: {
eventOptionId: string;
variantId?: string | null;
name: string;
email?: string | null;
phone?: string | null;
/** @description YYYY-MM-DD (youth events) */
dateOfBirth?: string | null;
gender?: string | null;
parentName?: string | null;
parentEmail?: string | null;
parentPhone?: string | null;
}[];
/**
* @description With attendees: tickets to the payer, or to each attendee
* @enum {string}
*/
ticketDelivery?: "payer" | "each";
waitlistToken?: string;
analyticsSessionId?: string;
};
};
};
responses: {
/** @description OK */
201: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
id: string;
/** @enum {string} */
status: "pending" | "confirmed" | "partial_paid" | "paid" | "cancelled";
/** Format: date-time */
createdAt: string;
event: {
id: string;
title: string;
/** Format: date-time */
startDate: string;
/** Format: date-time */
endDate: string;
};
items: {
ticket: string;
variant: string | null;
quantity: number;
unitPrice: number;
}[];
/** @description In rand, after discounts */
totalDue: number;
/** @description In rand (refunds subtracted) */
amountPaid: number;
/** @description totalDue − amountPaid; 0 or less = nothing owing */
balance: number;
/** @description false = added to an existing registration */
isNew: boolean;
couponError: string | null;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
getRegistrationsId: {
parameters: {
query?: never;
header?: never;
path: {
/** @description The id */
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
id: string;
/** @enum {string} */
status: "pending" | "confirmed" | "partial_paid" | "paid" | "cancelled";
/** Format: date-time */
createdAt: string;
event: {
id: string;
title: string;
/** Format: date-time */
startDate: string;
/** Format: date-time */
endDate: string;
};
items: {
ticket: string;
variant: string | null;
quantity: number;
unitPrice: number;
}[];
/** @description In rand, after discounts */
totalDue: number;
/** @description In rand (refunds subtracted) */
amountPaid: number;
/** @description totalDue − amountPaid; 0 or less = nothing owing */
balance: number;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not found (NOT_FOUND) */
404: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
postRegistrationsIdCancel: {
parameters: {
query?: never;
header?: never;
path: {
/** @description The id */
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
id: string;
/** @enum {string} */
status: "pending" | "confirmed" | "partial_paid" | "paid" | "cancelled";
/** Format: date-time */
createdAt: string;
event: {
id: string;
title: string;
/** Format: date-time */
startDate: string;
/** Format: date-time */
endDate: string;
};
items: {
ticket: string;
variant: string | null;
quantity: number;
unitPrice: number;
}[];
/** @description In rand, after discounts */
totalDue: number;
/** @description In rand (refunds subtracted) */
amountPaid: number;
/** @description totalDue − amountPaid; 0 or less = nothing owing */
balance: number;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not found (NOT_FOUND) */
404: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
postRegistrationsIdCheckout: {
parameters: {
query?: never;
header?: never;
path: {
/** @description The id */
id: string;
};
cookie?: never;
};
requestBody: {
content: {
"application/json": {
/** @description An optional donation added on top, in rand */
donationAmount?: number;
/** @description yoco or payfast (default: the first one switched on) */
provider?: string;
/** Format: uri */
successUrl?: string;
/** Format: uri */
cancelUrl?: string;
/** Format: uri */
failureUrl?: string;
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/** @constant */
priceUpdated: true;
newBalance: number;
message: string;
} | {
/** @constant */
priceUpdated: false;
checkoutId: string;
redirectUrl: string;
provider: string;
/** @description Charged now, in rand (with any donation) */
amount: number;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not found (NOT_FOUND) */
404: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
getMe: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
id: string;
name: string;
email: string;
phone: string | null;
/** @enum {string} */
role: "admin" | "supervisor" | "staff" | "user";
twoFactorEnabled: boolean;
/** Format: date-time */
createdAt: string;
};
};
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
getMeRegistrations: {
parameters: {
query?: {
/** @description Page number, from 1 */
page?: number;
/** @description Items per page (at most 100) */
limit?: number;
/** @description Include past and cancelled registrations */
past?: "true" | "false";
};
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
id: string;
/** @enum {string} */
status: "pending" | "confirmed" | "partial_paid" | "paid" | "cancelled";
/** Format: date-time */
createdAt: string;
event: {
id: string;
title: string;
/** Format: date-time */
startDate: string;
/** Format: date-time */
endDate: string;
};
items: {
ticket: string;
variant: string | null;
quantity: number;
unitPrice: number;
}[];
/** @description In rand, after discounts */
totalDue: number;
/** @description In rand (refunds subtracted) */
amountPaid: number;
/** @description totalDue − amountPaid; 0 or less = nothing owing */
balance: number;
}[];
meta: {
page: number;
limit: number;
/** @description Items across all pages */
total: number;
/** @description Number of pages (at least 1) */
pages: number;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
}