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.

Disconnect Stripe when a staging workspace uninstalls the app.

Kiran K23c952d1f3d8
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/account-application-deauthorized.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/account-application-deauthorized.ts
index 866c63efe1..42e06af4d5 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/account-application-deauthorized.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/account-application-deauthorized.ts
@@ -1,4 +1,5 @@
import { prisma } from "@/lib/prisma";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import { STRIPE_INTEGRATION_ID } from "@dub/utils";
import Stripe from "stripe";
import { WebhookHandlerInput, WebhookHandlerResponse } from "./types";
@@ -10,7 +11,7 @@ export async function accountApplicationDeauthorized({
}: WebhookHandlerInput<Stripe.AccountApplicationDeauthorizedEvent>): Promise<WebhookHandlerResponse> {
const stripeAccountId = workspace.stripeConnectId!;
- if (mode !== "live") {
+ if (mode !== "live" && isProductionEnvironment(workspace.environment)) {
return {
response: `Stripe Connect account ${stripeAccountId} deauthorized in ${mode} mode. Skipping...`,
};
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
index dd69d708e6..61742dbf06 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
@@ -114,6 +114,7 @@ export const POST = withAxiom(async (req: Request) => {
stripeConnectId: true,
defaultProgramId: true,
webhookEnabled: true,
+ environment: true,
stagingWorkspaceId: true,
},
});
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/types.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/types.ts
index e5f63cb197..94555d4c88 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/types.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/types.ts
@@ -11,6 +11,10 @@ export type WebhookHandlerInput<T extends Stripe.Event> = {
mode: StripeMode;
workspace: Pick<
Project,
- "id" | "stripeConnectId" | "defaultProgramId" | "webhookEnabled"
+ | "id"
+ | "stripeConnectId"
+ | "defaultProgramId"
+ | "webhookEnabled"
+ | "environment"
>;
};