The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
search for both dubCustomerExternalId and stripeCustomerId
Steven Tey43fc1cbb1564
diff --git a/apps/web/app/api/stripe/integration/webhook/customer-created.ts b/apps/web/app/api/stripe/integration/webhook/customer-created.tsindex b88739532b..fb2eb5d7cd 100644--- a/apps/web/app/api/stripe/integration/webhook/customer-created.ts+++ b/apps/web/app/api/stripe/integration/webhook/customer-created.ts@@ -6,9 +6,9 @@ import { createNewCustomer } from "./utils";export async function customerCreated(event: Stripe.Event) {const stripeCustomer = event.data.object as Stripe.Customer;const stripeAccountId = event.account as string;- const externalId = stripeCustomer.metadata?.dubCustomerId;+ const dubCustomerExternalId = stripeCustomer.metadata?.dubCustomerId;- if (!externalId) {+ if (!dubCustomerExternalId) {return "External ID not found in Stripe customer metadata, skipping...";}@@ -18,7 +18,7 @@ export async function customerCreated(event: Stripe.Event) {where: {projectConnectId_externalId: {projectConnectId: stripeAccountId,- externalId,+ externalId: dubCustomerExternalId,},},});diff --git a/apps/web/app/api/stripe/integration/webhook/customer-updated.ts b/apps/web/app/api/stripe/integration/webhook/customer-updated.tsindex 3f9ca4d7e4..7c5c2512ef 100644--- a/apps/web/app/api/stripe/integration/webhook/customer-updated.ts+++ b/apps/web/app/api/stripe/integration/webhook/customer-updated.ts@@ -6,18 +6,23 @@ import { createNewCustomer } from "./utils";export async function customerUpdated(event: Stripe.Event) {const stripeCustomer = event.data.object as Stripe.Customer;const stripeAccountId = event.account as string;- const externalId = stripeCustomer.metadata?.dubCustomerId;+ const dubCustomerExternalId = stripeCustomer.metadata?.dubCustomerId;- if (!externalId) {+ if (!dubCustomerExternalId) {return "External ID not found in Stripe customer metadata, skipping...";}- const customer = await prisma.customer.findUnique({+ const customer = await prisma.customer.findFirst({where: {- projectConnectId_externalId: {- projectConnectId: stripeAccountId,- externalId,- },+ OR: [+ {+ projectConnectId: stripeAccountId,+ externalId: dubCustomerExternalId,+ },+ {+ stripeCustomerId: stripeCustomer.id,+ },+ ],},});@@ -27,7 +32,8 @@ export async function customerUpdated(event: Stripe.Event) {id: customer.id,},data: {- externalId,+ externalId: dubCustomerExternalId,+ stripeCustomerId: stripeCustomer.id,name: stripeCustomer.name,email: stripeCustomer.email,},