Branchwell

Lumen & Gesso / website · lumengesso.com / app / lib / stripe.ts

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