19 lines
382 B
TypeScript
19 lines
382 B
TypeScript
import Stripe from "stripe";
|
|
|
|
let stripe: Stripe | null = null;
|
|
|
|
/**
|
|
* Server-only Stripe client.
|
|
* 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;
|
|
}
|