Summarize a payment event
Node · Node · intermediate · greenfield
Adds the payment-event summarizer: switches on the event kind and returns a readable line for each. Covers the payment kinds with a default for safety.
Requirements
- Return a human-readable summary string for each payment event kind.
- Handle every kind the PaymentEvent union declares.
- Adding a new event kind later must force this function to be updated (compile error), not silently fall through.
Files touched
- src/payments/summarize.ts
--- src/payments/summarize.ts
+type PaymentEvent =
+ | { kind: 'authorized'; amountCents: number }
+ | { kind: 'captured'; amountCents: number }
+ | { kind: 'refunded'; amountCents: number }
+ | { kind: 'disputed'; reason: string };
+
+export function summarize(event: PaymentEvent): string {
+ switch (event.kind) {
+ case 'authorized':
+ return `Authorized ${event.amountCents} cents`;
+ case 'captured':
+ return `Captured ${event.amountCents} cents`;
+ case 'refunded':
+ return `Refunded ${event.amountCents} cents`;
+ default:
+ return 'Unknown event';
+ }
+}