// Payment.method is free-text — online checkouts get tagged with whatever wallet type the // gateway reports (apple_pay, google_pay, ...), not just the manual-entry methods below. // Mirrors normalizeUserMethod in backend/src/controllers/paymentController.js: card-network // wallets count as "card" (same settlement, no separate float); anything else is "other". const USER_FACING_METHODS = ["cash", "card", "eft", "voucher"]; const CARD_ALIASES = ["apple_pay", "google_pay"]; const METHOD_LABELS: Record = { cash: "Cash", card: "Card", eft: "EFT", voucher: "Voucher", other: "Other", }; // Refund methods are recorded as "-refund" (e.g. "card-refund") so a refund nets // against the same bucket its original payment counted under. Strip that suffix before // bucketing so a card refund still displays as "Card", not "Other" — the negative amount // already signals it's a refund. function stripRefundSuffix(method: string): string { return method.endsWith("-refund") ? method.slice(0, -"-refund".length) : method; } export function normalizePaymentMethod(method: string | null | undefined): string { const m = stripRefundSuffix(String(method || "").toLowerCase()); if (USER_FACING_METHODS.includes(m)) return m; if (CARD_ALIASES.includes(m)) return "card"; return "other"; } export function formatPaymentMethod(method: string | null | undefined): string { if (!method) return "Payment"; return METHOD_LABELS[normalizePaymentMethod(method)]; }