The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
use similar approach as checkout-session-completed
Steven Tey14039cb72804
diff --git a/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.tsindex 615896abb3..fcd9fb312e 100644--- a/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts+++ b/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts@@ -161,7 +161,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {}try {- // Update customer with stripe customerId if exists+ // Update customer with stripeCustomerId if exists – for future eventscustomer = await prisma.customer.update({where: {projectConnectId_externalId: {diff --git a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts b/apps/web/app/api/stripe/integration/webhook/invoice-paid.tsindex 9983bf5097..93bb17435b 100644--- a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts+++ b/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts@@ -32,16 +32,26 @@ export async function invoicePaid(event: Stripe.Event) {stripeCustomerId,stripeAccountId,});-- if (connectedCustomer?.metadata.dubCustomerId) {- customer = await prisma.customer.findUnique({- where: {- projectConnectId_externalId: {- projectConnectId: stripeAccountId,- externalId: connectedCustomer.metadata.dubCustomerId,+ const dubCustomerId = connectedCustomer?.metadata.dubCustomerId;++ if (dubCustomerId) {+ try {+ // Update customer with stripeCustomerId if exists – for future events+ customer = await prisma.customer.update({+ where: {+ projectConnectId_externalId: {+ projectConnectId: stripeAccountId,+ externalId: dubCustomerId,+ },},- },- });+ data: {+ stripeCustomerId,+ },+ });+ } catch (error) {+ console.error(error);+ return `Customer with dubCustomerId ${dubCustomerId} not found, skipping...`;+ }}}@@ -187,17 +197,5 @@ export async function invoicePaid(event: Stripe.Event) {}),);- // update customer with stripeCustomerId for future events- waitUntil(- prisma.customer.update({- where: {- id: customer.id,- },- data: {- stripeCustomerId,- },- }),- );-return `Sale recorded for customer ID ${customer.id} and invoice ID ${invoiceId}`;}