From fa053b4d1f87a67fa40b100fb8d76c9efbc2d40d Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 24 Oct 2024 01:10:17 -0600 Subject: [PATCH] refactor(dokploy): remove stripe from global scope --- apps/dokploy/pages/api/stripe/webhook.ts | 10 +++++----- apps/dokploy/server/utils/stripe.ts | 6 ------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/apps/dokploy/pages/api/stripe/webhook.ts b/apps/dokploy/pages/api/stripe/webhook.ts index ffbb6736..96e414d9 100644 --- a/apps/dokploy/pages/api/stripe/webhook.ts +++ b/apps/dokploy/pages/api/stripe/webhook.ts @@ -6,11 +6,6 @@ import { asc, eq } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; import Stripe from "stripe"; -const stripe = new Stripe(process.env.STRIPE_SECRET_KEY || "", { - apiVersion: "2024-09-30.acacia", - maxNetworkRetries: 3, -}); - const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET || ""; export const config = { @@ -26,6 +21,11 @@ export default async function handler( if (!endpointSecret) { return res.status(400).send("Webhook Error: Missing Stripe Secret Key"); } + const stripe = new Stripe(process.env.STRIPE_SECRET_KEY || "", { + apiVersion: "2024-09-30.acacia", + maxNetworkRetries: 3, + }); + const buf = await buffer(req); const sig = req.headers["stripe-signature"] as string; diff --git a/apps/dokploy/server/utils/stripe.ts b/apps/dokploy/server/utils/stripe.ts index 26445af7..7044769d 100644 --- a/apps/dokploy/server/utils/stripe.ts +++ b/apps/dokploy/server/utils/stripe.ts @@ -1,14 +1,8 @@ -import Stripe from "stripe"; - export const WEBSITE_URL = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://app.dokploy.com"; -export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY || "", { - apiVersion: "2024-09-30.acacia", -}); - const BASE_PRICE_MONTHLY_ID = process.env.BASE_PRICE_MONTHLY_ID || ""; // $4.00 const BASE_ANNUAL_MONTHLY_ID = process.env.BASE_ANNUAL_MONTHLY_ID || ""; // $7.99