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.

use sendWorkspaceWebhook on stripe webhook

Kiran Keea0b4448173
diff --git a/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.ts
index 09e27b8438..61f48cd25b 100644
--- a/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.ts
+++ b/apps/web/app/api/stripe/connect/webhook/checkout-session-completed.ts
@@ -1,7 +1,7 @@
import { prisma } from "@/lib/prisma";
import { getLeadEvent, recordSale } from "@/lib/tinybird";
import { redis } from "@/lib/upstash";
-import { sendLinkWebhook } from "@/lib/webhook/publish";
+import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import { transformSaleEventData } from "@/lib/webhook/transform";
import { nanoid } from "@dub/utils";
import { Customer } from "@prisma/client";
@@ -121,18 +121,30 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
]);
waitUntil(
- sendLinkWebhook({
- trigger: "sale.created",
- linkId,
- data: transformSaleEventData({
- ...saleData,
- link,
- customerId: customer.externalId,
- customerName: customer.name,
- customerEmail: customer.email,
- customerAvatar: customer.avatar,
- }),
- }),
+ (async () => {
+ const workspace = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: customer.projectId,
+ },
+ select: {
+ id: true,
+ webhookEnabled: true,
+ },
+ });
+
+ sendWorkspaceWebhook({
+ trigger: "sale.created",
+ workspace,
+ data: transformSaleEventData({
+ ...saleData,
+ link,
+ customerId: customer.externalId,
+ customerName: customer.name,
+ customerEmail: customer.email,
+ customerAvatar: customer.avatar,
+ }),
+ });
+ })(),
);
return `Checkout session completed for customer with external ID ${dubCustomerId} and invoice ID ${invoiceId}`;
diff --git a/apps/web/app/api/stripe/connect/webhook/customer-created.ts b/apps/web/app/api/stripe/connect/webhook/customer-created.ts
index d9583b9d75..5ef2401b6a 100644
--- a/apps/web/app/api/stripe/connect/webhook/customer-created.ts
+++ b/apps/web/app/api/stripe/connect/webhook/customer-created.ts
@@ -1,6 +1,6 @@
import { prisma } from "@/lib/prisma";
import { getClickEvent, recordCustomer, recordLead } from "@/lib/tinybird";
-import { sendLinkWebhook } from "@/lib/webhook/publish";
+import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import { transformLeadEventData } from "@/lib/webhook/transform";
import { clickEventSchemaTB } from "@/lib/zod/schemas/clicks";
import { nanoid } from "@dub/utils";
@@ -104,18 +104,30 @@ export async function customerCreated(event: Stripe.Event) {
]);
waitUntil(
- sendLinkWebhook({
- trigger: "lead.created",
- linkId,
- data: transformLeadEventData({
- ...leadData,
- link,
- customerId: customer.externalId,
- customerName: customer.name,
- customerEmail: customer.email,
- customerAvatar: customer.avatar,
- }),
- }),
+ (async () => {
+ const workspace = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: customer.projectId,
+ },
+ select: {
+ id: true,
+ webhookEnabled: true,
+ },
+ });
+
+ sendWorkspaceWebhook({
+ trigger: "lead.created",
+ workspace,
+ data: transformLeadEventData({
+ ...leadData,
+ link,
+ customerId: customer.externalId,
+ customerName: customer.name,
+ customerEmail: customer.email,
+ customerAvatar: customer.avatar,
+ }),
+ });
+ })(),
);
return `Customer created: ${customer.id}`;
diff --git a/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts b/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts
index 34dbb469f6..43404c2ece 100644
--- a/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts
+++ b/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts
@@ -1,7 +1,7 @@
import { prisma } from "@/lib/prisma";
import { getLeadEvent, recordSale } from "@/lib/tinybird";
import { redis } from "@/lib/upstash";
-import { sendLinkWebhook } from "@/lib/webhook/publish";
+import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import { transformSaleEventData } from "@/lib/webhook/transform";
import { nanoid } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
@@ -104,18 +104,30 @@ export async function invoicePaid(event: Stripe.Event) {
]);
waitUntil(
- sendLinkWebhook({
- trigger: "sale.created",
- linkId,
- data: transformSaleEventData({
- ...saleData,
- link,
- customerId: customer.externalId,
- customerName: customer.name,
- customerEmail: customer.email,
- customerAvatar: customer.avatar,
- }),
- }),
+ (async () => {
+ const workspace = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: customer.projectId,
+ },
+ select: {
+ id: true,
+ webhookEnabled: true,
+ },
+ });
+
+ sendWorkspaceWebhook({
+ trigger: "sale.created",
+ workspace,
+ data: transformSaleEventData({
+ ...saleData,
+ link,
+ customerId: customer.externalId,
+ customerName: customer.name,
+ customerEmail: customer.email,
+ customerAvatar: customer.avatar,
+ }),
+ });
+ })(),
);
return `Sale recorded for customer ID ${customer.id} and invoice ID ${invoiceId}`;