Payment processing with Stripe and Square.

A provider-agnostic payment interface with adapters for Stripe and Square. Handles checkout sessions, webhook verification, refunds, and idempotent payment processing.

Provider Interface

PaymentProvider defines the common contract:

  • Create single and multi-event checkout sessions
  • Verify webhook signatures
  • Retrieve session details and process refunds

Classes

c
PaymentUserError(message: string)

Error subclass for user-facing payment validation errors (e.g. invalid phone number). These propagate through safeAsync so the message can be shown to the user.

Functions

f
buildItemsMetadata(intent: CheckoutIntent): Record<string, string>

Build checkout metadata from a CheckoutIntent (converts items to compact form).

f
buildMetadata(intent: MetadataInput): Record<string, string>

Build checkout session metadata from booking data (items already compact).

f
createWithClient<Client>(getClient: () => Client | null | Promise<Client | null>)

Create a withClient helper that runs an operation with a lazily-resolved client. Returns null if the client is not available or the operation fails.

f
errorMessage(err: unknown): string

Extract a human-readable message from an unknown caught value

f
extractSessionMetadata(metadata: SessionMetadata): ValidatedPaymentSession["metadata"]

Normalize validated session metadata into the canonical SessionMetadata shape.

f
getActivePaymentProvider(): Promise<PaymentProvider | null>

Resolve the active payment provider based on admin settings. Lazy-loads the provider module to avoid importing unused SDKs. Returns null if no provider is configured.

f
isPaymentStatus(s: string): s is PaymentStatus

Type guard: check if a string is a valid PaymentStatus

f
safeAsync<T>(
fn: () => Promise<T>,
errorCode: ErrorCodeType
): Promise<T | null>

Safely execute async operation, returning null on error. Re-throws PaymentUserError so user-facing messages propagate.

f
singleEventAnswerIds(
eventId: number,
answerIds?: number[]
): Record<string, number[]> | undefined

Convert single-event answerIds to the per-event format used in metadata

f
toBookingItems(items: CheckoutIntent["items"]): BookingItem[]

Convert registration line items to compact booking items

f
toCheckoutResult(
sessionId: string | undefined,
url: string | undefined | null,
label: LogCategory
): CheckoutSessionResult

Convert a provider-specific checkout result to a CheckoutSessionResult. Returns null if session ID or URL is missing.

f
withCheckoutError(op: () => Promise<CheckoutSessionResult>): Promise<CheckoutSessionResult>

Wrap a checkout operation, converting PaymentUserError to { error } result and swallowing unexpected errors as null. Used by both provider adapters.

Interfaces

I
PaymentProvider

Payment provider interface.

Type Aliases

T
BookingItem = { e: number; q: number; p: number; }

Compact booking item stored in session metadata (serialized/deserialized as JSON)

T
PaymentProviderType = "stripe" | "square"

Supported payment provider identifiers

T
PaymentProviderType = "stripe" | "square"

Supported payment provider identifiers

Variables

v
SQUARE_METADATA_MAX_VALUE_LENGTH: 255

Square metadata constraint: each value max 255 characters

v
STRIPE_METADATA_MAX_VALUE_LENGTH: 500

Stripe metadata constraint: each value max 500 characters