Apply payment method normalization consistently across user-facing views
Audited every place Payment.method reaches the UI. The main user dashboard's per-registration payment list (fed by GET /api/payments/registration/:id) was still showing the raw gateway string, since that endpoint is shared with the staff-facing supervisor payments page and wasn't touched by the earlier /mypayments fix. Extracted the cash/card/eft/voucher/other normalization (matching normalizeUserMethod on the backend) into frontend/src/lib/paymentMethod.ts and applied it to both user-facing payment displays. Staff-facing views (supervisor payments, at-the-door, reports, cashup) intentionally keep showing the raw method for reconciliation and were left unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// 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<string, string> = {
|
||||
cash: "Cash",
|
||||
card: "Card",
|
||||
eft: "EFT",
|
||||
voucher: "Voucher",
|
||||
other: "Other",
|
||||
};
|
||||
|
||||
export function normalizePaymentMethod(method: string | null | undefined): string {
|
||||
const m = 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)];
|
||||
}
|
||||
Reference in New Issue
Block a user