25 lines
643 B
TypeScript
25 lines
643 B
TypeScript
import Stripe from "stripe";
|
|
|
|
// Centralized Stripe client. All Stripe requests should use this instance.
|
|
// The SDK automatically uses the latest API version configured for your account.
|
|
const secretKey = process.env.STRIPE_SECRET_KEY;
|
|
|
|
function missingKeyError() {
|
|
return new Error(
|
|
"Missing STRIPE_SECRET_KEY. Add it to your environment before starting the server."
|
|
);
|
|
}
|
|
|
|
export const stripeClient: Stripe = secretKey
|
|
? new Stripe(secretKey, {
|
|
// No explicit apiVersion needed per requirements.
|
|
})
|
|
: (new Proxy(
|
|
{},
|
|
{
|
|
get() {
|
|
throw missingKeyError();
|
|
},
|
|
}
|
|
) as Stripe);
|