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.

check the customer is not already created

Kiran K72106d2b677c
diff --git a/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts b/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts
index 0c964b00e4..68c3ce0593 100644
--- a/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts
+++ b/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts
@@ -22,9 +22,21 @@ export async function customerCreated(event: Stripe.Event) {
return;
}
- const clickData = clickEventSchemaTB
- .omit({ timestamp: true })
- .parse(clickEvent.data[0]);
+ // Check the customer is not already created
+ const customerFound = await prisma.customer.findFirst({
+ where: {
+ projectConnectId: stripeAccountId,
+ externalId,
+ },
+ });
+
+ if (customerFound) {
+ console.info(
+ "[Stripe Webhook] Found existing customer with externalId",
+ externalId,
+ );
+ return;
+ }
// Create customer
const customerId = nanoid(16);
@@ -44,6 +56,10 @@ export async function customerCreated(event: Stripe.Event) {
},
});
+ const clickData = clickEventSchemaTB
+ .omit({ timestamp: true })
+ .parse(clickEvent.data[0]);
+
await Promise.all([
// Record customer
recordCustomer({