accesscodes/src/lib/donations.ts

33 lines
1.8 KiB
TypeScript

export type TierId = "iron" | "gold" | "diamond" | "patron" | "custom";
export const TIERS = {
iron: { id: "iron" as const, label: "Iron", price: 300, group: "iron", weight: 10, perks: ["Iron prefix & grey name", "/hat cosmetics", "Supporter role"], popular: false },
gold: { id: "gold" as const, label: "Gold", price: 500, group: "gold", weight: 20, perks: ["All Iron perks", "Gold prefix & particles", "/nick + join effects"], popular: true },
diamond: { id: "diamond" as const, label: "Diamond", price: 700, group: "diamond", weight: 30, perks: ["All Gold perks", "Diamond prefix & aqua glow", "All pets, hats & morphs"], popular: false },
patron: { id: "patron" as const, label: "Patron", price: 500, group: "patron", weight: 40, subscription: true, perks: ["All Diamond perks", "Patron badge & extras", "Ongoing support"], popular: false },
} as const;
export const TIER_ORDER: TierId[] = ["iron", "gold", "diamond"];
export function upgradePrice(from: TierId, to: TierId): number | null {
const f = (TIERS as any)[from]?.price;
const t = (TIERS as any)[to]?.price;
if (f == null || t == null) return null;
const diff = t - f;
return diff > 0 ? diff : null;
}
// One-time custom: highest tier affordable in that payment.
// Recurring custom: >=£5/mo acts as Patron, <£5 cumulative unlocks tiers.
export function tierForAmount(pence: number): TierId | null {
if (pence >= TIERS.diamond.price) return "diamond";
if (pence >= TIERS.gold.price) return "gold";
if (pence >= TIERS.iron.price) return "iron";
return null;
}
export function tierForCumulative(pence: number): TierId | null {
return tierForAmount(pence);
}
export function tierForCustom(pence: number, recurring?: boolean): TierId | null {
if (recurring && pence >= TIERS.patron.price) return "patron";
return tierForAmount(pence);
}