import 'server-only'; import Stripe from 'stripe'; import { env } from './env'; let cached: Stripe | null = null; export function stripe(): Stripe { if (!cached) { cached = new Stripe(env.stripe.secretKey(), { typescript: true, // Fail fast on a stalled connection instead of the 80s SDK default — // a hung refund call here used to freeze the admin cancel UI. Network // retries are safe: the SDK auto-attaches an idempotency key per retry, // so a refund can't be double-issued. timeout: 20000, maxNetworkRetries: 2, }); } return cached; }