diff --git a/apps/web/src/app/api/webhook/stripe/route.ts b/apps/web/src/app/api/webhook/stripe/route.ts index 02c7282..d6d34a7 100644 --- a/apps/web/src/app/api/webhook/stripe/route.ts +++ b/apps/web/src/app/api/webhook/stripe/route.ts @@ -2,12 +2,7 @@ import { headers } from "next/headers"; import { NextResponse } from "next/server"; import Stripe from "stripe"; import { env } from "~/env"; -import { syncStripeData } from "~/server/billing/payments"; -import { db } from "~/server/db"; - -const stripe = new Stripe(env.STRIPE_SECRET_KEY!, { - apiVersion: "2025-01-27.acacia", -}); +import { getStripe, syncStripeData } from "~/server/billing/payments"; const allowedEvents: Stripe.Event.Type[] = [ "checkout.session.completed", @@ -44,6 +39,8 @@ export async function POST(req: Request) { return new NextResponse("No webhook secret", { status: 400 }); } + const stripe = getStripe(); + try { const event = stripe.webhooks.constructEvent( body, diff --git a/apps/web/src/server/billing/payments.ts b/apps/web/src/server/billing/payments.ts index 66ec850..f1a0296 100644 --- a/apps/web/src/server/billing/payments.ts +++ b/apps/web/src/server/billing/payments.ts @@ -2,7 +2,7 @@ import Stripe from "stripe"; import { env } from "~/env"; import { db } from "../db"; -function getStripe() { +export function getStripe() { if (!env.STRIPE_SECRET_KEY) { throw new Error("STRIPE_SECRET_KEY is not set"); }