Lumen & Gesso / website · lumengesso.com / app / lib / stripe.ts
| 1 | import 'server-only'; |
| 2 | import Stripe from 'stripe'; |
| 3 | import { env } from './env'; |
| 4 | |
| 5 | let cached: Stripe | null = null; |
| 6 | export 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 | } |