additional stripe settings

This commit is contained in:
Corey Blais
2026-04-16 21:04:08 -04:00
parent 96e5694b01
commit 53f9b09d28
4 changed files with 80 additions and 16 deletions
+24 -1
View File
@@ -262,6 +262,25 @@ const stripePriceByBillingPlanAndInterval: Partial<Record<Exclude<BillingPlan, '
yearly: process.env.STRIPE_PRICE_HOUSEHOLD_MACAW_YEARLY?.trim() ?? '',
},
};
const stripePriceEnvNamesByBillingPlanAndInterval: Record<Exclude<BillingPlan, 'rescue_free'>, Record<BillingInterval, string[]>> = {
household_basic: {
monthly: ['STRIPE_PRICE_HOUSEHOLD_CONURE_MONTHLY', 'STRIPE_PRICE_HOUSEHOLD_CONURE'],
yearly: ['STRIPE_PRICE_HOUSEHOLD_CONURE_YEARLY'],
},
household_plus: {
monthly: ['STRIPE_PRICE_HOUSEHOLD_INDIANRINGNECK_MONTHLY', 'STRIPE_PRICE_HOUSEHOLD_INDIANRINGNECK'],
yearly: ['STRIPE_PRICE_HOUSEHOLD_INDIANRINGNECK_YEARLY'],
},
household_macaw: {
monthly: ['STRIPE_PRICE_HOUSEHOLD_MACAW_MONTHLY', 'STRIPE_PRICE_HOUSEHOLD_MACAW'],
yearly: ['STRIPE_PRICE_HOUSEHOLD_MACAW_YEARLY'],
},
};
const stripePricePlanLabels: Record<Exclude<BillingPlan, 'rescue_free'>, string> = {
household_basic: 'Conure',
household_plus: 'Indian Ringneck',
household_macaw: 'Macaw',
};
const stripe = stripeSecretKey ? new Stripe(stripeSecretKey) : null;
const adminEmails = new Set(
(process.env.ADMIN_EMAILS ?? '')
@@ -573,7 +592,11 @@ const getStripePriceIdForBillingPlan = (billingPlan: BillingPlan, billingInterva
const priceId = stripePriceByBillingPlanAndInterval[billingPlan]?.[billingInterval]?.trim() ?? '';
if (!priceId) {
throw new Error(`Stripe price is not configured for ${billingPlan} (${billingInterval}).`);
const planLabel = stripePricePlanLabels[billingPlan] ?? billingPlan;
const envNames = stripePriceEnvNamesByBillingPlanAndInterval[billingPlan]?.[billingInterval] ?? [];
const envHint = envNames.length > 0 ? ` Set ${envNames.join(' or ')} in the backend environment.` : '';
throw new Error(`Stripe price is not configured for ${planLabel} ${billingInterval}.${envHint}`);
}
return priceId;