From 7f921103b3f18c6108968c96deac899948c91597 Mon Sep 17 00:00:00 2001 From: Rajpreet0 Date: Fri, 15 May 2026 02:07:08 +0200 Subject: [PATCH] fixed build --- src/lib/stripe.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lib/stripe.ts b/src/lib/stripe.ts index ca3d339..a8f6520 100644 --- a/src/lib/stripe.ts +++ b/src/lib/stripe.ts @@ -1,12 +1,23 @@ import Stripe from "stripe"; -if (!process.env.STRIPE_SECRET_KEY) { - throw new Error("STRIPE_SECRET_KEY ist nicht gesetzt"); +let _stripe: Stripe | null = null; + +function getStripeClient(): Stripe { + if (_stripe) return _stripe; + if (!process.env.STRIPE_SECRET_KEY) { + throw new Error("STRIPE_SECRET_KEY ist nicht gesetzt"); + } + _stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { + apiVersion: "2026-04-22.dahlia", + typescript: true, + }); + return _stripe; } -export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: "2026-04-22.dahlia", - typescript: true, +export const stripe = new Proxy({} as Stripe, { + get(_target, prop) { + return Reflect.get(getStripeClient(), prop, getStripeClient()); + }, }); export const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET ?? "";