MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / cardOnFile

Function cardOnFile

apps/cloud/src/routes/app/billing.tsx:51–74  ·  view source on GitHub ↗
(paymentMethod: unknown)

Source from the content-addressed store, hash-verified

49};
50
51const cardOnFile = (paymentMethod: unknown): CardOnFile | null => {
52 if (typeof paymentMethod !== "object" || paymentMethod === null) return null;
53 const pm = paymentMethod as { id?: unknown; card?: unknown };
54 if (typeof pm.id !== "string" || typeof pm.card !== "object" || pm.card === null) return null;
55 const card = pm.card as {
56 brand?: unknown;
57 last4?: unknown;
58 exp_month?: unknown;
59 exp_year?: unknown;
60 expMonth?: unknown;
61 expYear?: unknown;
62 };
63 const expMonth = card.expMonth ?? card.exp_month;
64 const expYear = card.expYear ?? card.exp_year;
65 if (
66 typeof card.brand !== "string" ||
67 typeof card.last4 !== "string" ||
68 typeof expMonth !== "number" ||
69 typeof expYear !== "number"
70 ) {
71 return null;
72 }
73 return { id: pm.id, brand: card.brand, last4: card.last4, expMonth, expYear };
74};
75
76const cardBrandLabel = (brand: string): string =>
77 CARD_BRANDS[brand] ?? (brand ? brand.charAt(0).toUpperCase() + brand.slice(1) : "Card");

Callers 1

BillingPageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected