juntekim.com/stripe_to_invoice/lib/stripe/service.ts
2026-02-21 14:48:09 +00:00

37 lines
890 B
TypeScript

import Stripe from "stripe";
let stripe: Stripe | null = null;
let stripeBilling: Stripe | null = null;
/**
* Server-only Stripe client for main Stripe Connect.
* Lazy-initialised to avoid build-time crashes.
*/
export function getStripe(): Stripe {
if (!process.env.STRIPE_SECRET_KEY) {
throw new Error("STRIPE_SECRET_KEY missing");
}
if (!stripe) {
stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
}
return stripe;
}
/**
* Server-only Stripe client for billing/subscriptions.
* Uses a separate Stripe account for billing.
* Lazy-initialised to avoid build-time crashes.
*/
export function getStripeBilling(): Stripe {
if (!process.env.STRIPE_BILLING_SECRET_KEY) {
throw new Error("STRIPE_BILLING_SECRET_KEY missing");
}
if (!stripeBilling) {
stripeBilling = new Stripe(process.env.STRIPE_BILLING_SECRET_KEY);
}
return stripeBilling;
}