The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
final changes
Steven Tey503f8f01ad37
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 5bcd05a4e0..615896abb3 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@@ -154,7 +154,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {});if (!connectedCustomer || !connectedCustomer.metadata.dubCustomerId) {- return `Customer ID not found in Stripe checkout session metadata (nor is it available on the connected customer ${stripeCustomerId}) and client_reference_id is not a dub_id, skipping...`;+ return `dubCustomerId not found in Stripe checkout session metadata (nor is it available on the connected customer ${stripeCustomerId}) and client_reference_id is not a dub_id, skipping...`;}dubCustomerId = connectedCustomer.metadata.dubCustomerId;diff --git a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts b/apps/web/app/api/stripe/integration/webhook/invoice-paid.tsindex a8fec6b53d..9983bf5097 100644--- a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts+++ b/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts@@ -26,7 +26,7 @@ export async function invoicePaid(event: Stripe.Event) {},});- // if customer is not found, we try to find it on the connected customer+ // if customer is not found, we check if the connected customer has a dubCustomerIdif (!customer) {const connectedCustomer = await getConnectedCustomer({stripeCustomerId,@@ -47,7 +47,7 @@ export async function invoicePaid(event: Stripe.Event) {// if customer is still not found, we skip the eventif (!customer) {- return `Customer with stripeCustomerId ${stripeCustomerId} not found on Dub (nor is it available on the connected customer ${stripeCustomerId}), skipping...`;+ return `Customer with stripeCustomerId ${stripeCustomerId} not found on Dub (nor does the connected customer ${stripeCustomerId} have a valid dubCustomerId), skipping...`;}// Skip if invoice id is already processed@@ -187,5 +187,17 @@ 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}`;}diff --git a/apps/web/app/api/stripe/integration/webhook/utils.ts b/apps/web/app/api/stripe/integration/webhook/utils.tsindex 4bd89690e0..b323a58aa4 100644--- a/apps/web/app/api/stripe/integration/webhook/utils.ts+++ b/apps/web/app/api/stripe/integration/webhook/utils.ts@@ -133,21 +133,16 @@ export async function getConnectedCustomer({stripeCustomerId: string;stripeAccountId: string;}) {- try {- const connectedCustomer = await stripeAppClient.customers.retrieve(- stripeCustomerId,- {- stripeAccount: stripeAccountId,- },- );-- if (connectedCustomer.deleted) {- return null;- }+ const connectedCustomer = await stripeAppClient.customers.retrieve(+ stripeCustomerId,+ {+ stripeAccount: stripeAccountId,+ },+ );- return connectedCustomer;- } catch (error) {- console.error(error);+ if (connectedCustomer.deleted) {return null;}++ return connectedCustomer;}