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.

Merge branch 'main' into staging-sandbox

Kiran K939dbe0f41a8
diff --cc apps/web/app/(ee)/api/stripe/integration/webhook/account-application-deauthorized.ts
index d076ff132a,fed4f31f86..1edff813b1
--- 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,15 -1,19 +1,30 @@@
import { prisma } from "@/lib/prisma";
import { STRIPE_INTEGRATION_ID } from "@dub/utils";
- import { StripeWebhookInput, StripeWebhookOutput } from "./utils/types";
-import type Stripe from "stripe";
++import Stripe from "stripe";
+ import { WebhookHandlerInput, WebhookHandlerResponse } from "./types";
+
++// Handle event "account.application.deauthorized"
++// export async function accountApplicationDeauthorized({
++// mode,
++// workspace,
++// }: StripeWebhookInput): Promise<StripeWebhookOutput> {
++// if (mode === "test") {
++// return {
++// response: `Stripe Connect account ${workspace.stripeConnectId} deauthorized in test mode. Skipping...`,
++// import type Stripe from "stripe";
++// import { WebhookHandlerInput, WebhookHandlerResponse } from "./types";
+
// Handle event "account.application.deauthorized"
export async function accountApplicationDeauthorized({
+ event,
mode,
workspace,
- }: StripeWebhookInput): Promise<StripeWebhookOutput> {
+ }: WebhookHandlerInput<Stripe.AccountApplicationDeauthorizedEvent>): Promise<WebhookHandlerResponse> {
- const stripeAccountId = event.account;
++ const stripeAccountId = workspace.stripeConnectId!;
+
if (mode === "test") {
return {
- response: `Stripe Connect account ${workspace.stripeConnectId} deauthorized in test mode. Skipping...`,
+ response: `Stripe Connect account ${stripeAccountId} deauthorized in test mode. Skipping...`,
};
}
diff --cc apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
index 5d1ce939f4,225934e111..18b14c1be4
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
@@@ -24,12 -24,10 +24,10 @@@ export async function invoicePaid(
event,
mode,
workspace,
- }: StripeWebhookInput & {
- event: Stripe.InvoicePaidEvent;
- }): Promise<StripeWebhookOutput> {
+ }: WebhookHandlerInput<Stripe.InvoicePaidEvent>): Promise<WebhookHandlerResponse> {
const invoice = event.data.object;
- const stripeAccountId = event.account as string;
const stripeCustomerId = invoice.customer as string | null;
+ const stripeAccountId = event.account as string;
const invoiceId = invoice.id;
if (!invoiceId) {
diff --cc apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
index 9a9a6e218b,26f2a6552b..26cf74ccf6
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
@@@ -13,9 -14,10 +13,11 @@@ import { customerSubscriptionCreated }
import { customerSubscriptionDeleted } from "./customer-subscription-deleted";
import { invoicePaid } from "./invoice-paid";
import { promotionCodeUpdated } from "./promotion-code-updated";
+ import { WebhookHandlerResponse } from "./types";
+import { resolveWebhookWorkspace } from "./utils/resolve-webhook-workspace";
import { syncCustomer } from "./utils/sync-customer";
- import { StripeWebhookOutput } from "./utils/types";
+
+ export const dynamic = "force-dynamic";
const relevantEvents = new Set([
"account.application.deauthorized",
@@@ -89,20 -104,27 +104,22 @@@ export const POST = withAxiom(async (re
});
}
+ // Find the workspace
- const workspace = await prisma.project.findUnique({
- where: {
- stripeConnectId: event.account,
- },
- select: {
- id: true,
- stripeConnectId: true,
- defaultProgramId: true,
- webhookEnabled: true,
- },
+ const workspace = await resolveWebhookWorkspace({
+ stripeAccountId: event.account,
+ mode,
});
- // Workspace not found
- if (workspace === null) {
- return NextResponse.json({
+ if (!workspace) {
+ return logAndRespond({
eventType: event.type,
response: `Workspace not found for Stripe account ${event.account}, skipping...`,
});
}
- let result: StripeWebhookOutput = {
++ console.log("Workspace found", workspace);
++
+ let result: WebhookHandlerResponse = {
response: "OK",
};