juntekim.com/stripe_to_invoice/lib/stripe/service.ts
Jun-te Kim 6b35b91ab1 stripe
2026-01-20 23:25:03 +00:00

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;
}