Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

move stripe integration URL to its own file

Steven Tey20e2bb7e0aa9
diff --git a/apps/web/lib/actions/get-integration-install-url.ts b/apps/web/lib/actions/get-integration-install-url.ts
index 41b09ae3e1..5adca255c5 100644
--- a/apps/web/lib/actions/get-integration-install-url.ts
+++ b/apps/web/lib/actions/get-integration-install-url.ts
@@ -1,8 +1,7 @@
"use server";
-import { nanoid } from "@dub/utils";
import { getFeatureFlags } from "../edge-config";
-import { redis } from "../upstash";
+import { getStripeInstallationUrl } from "../integrations/stripe";
import z from "../zod";
import { authActionClient } from "./safe-action";
@@ -23,33 +22,16 @@ export const getIntegrationInstallUrl = authActionClient
// TODO:
// Move the installation URL logic to the respective integration specific file
if (integrationSlug === "stripe") {
- url = await stripeInstallationUrl(workspace.id);
+ const flags = await getFeatureFlags({ workspaceId: workspace.id });
+
+ if (!flags.conversions) {
+ throw new Error("Conversions feature is not enabled.");
+ }
+
+ url = await getStripeInstallationUrl(workspace.id);
} else {
throw new Error("Invalid integration slug");
}
return { url };
});
-
-// Stripe installation URL
-const stripeInstallationUrl = async (workspaceId: string) => {
- const flags = await getFeatureFlags({ workspaceId });
-
- if (!flags.conversions) {
- throw new Error("Conversions feature is not enabled.");
- }
-
- const state = nanoid(16);
- await redis.set(`stripe:install:state:${state}`, workspaceId, {
- ex: 30 * 60,
- });
-
- const url = new URL(`${process.env.STRIPE_APP_INSTALL_URL}`);
- url.searchParams.set("state", state);
- url.searchParams.set(
- "redirect_uri",
- `${process.env.APP_DOMAIN_WITH_NGROK}/api/stripe/connect/callback`,
- );
-
- return url.toString();
-};
diff --git a/apps/web/lib/integrations/stripe.ts b/apps/web/lib/integrations/stripe.ts
new file mode 100644
index 0000000000..da5aa192ed
--- /dev/null
+++ b/apps/web/lib/integrations/stripe.ts
@@ -0,0 +1,18 @@
+import { nanoid } from "nanoid";
+import { redis } from "../upstash";
+
+export const getStripeInstallationUrl = async (workspaceId: string) => {
+ const state = nanoid(16);
+ await redis.set(`stripe:install:state:${state}`, workspaceId, {
+ ex: 30 * 60,
+ });
+
+ const url = new URL(`${process.env.STRIPE_APP_INSTALL_URL}`);
+ url.searchParams.set("state", state);
+ url.searchParams.set(
+ "redirect_uri",
+ `${process.env.APP_DOMAIN_WITH_NGROK}/api/stripe/connect/callback`,
+ );
+
+ return url.toString();
+};