The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Make Stripe Connect responses more verbose
Steven Tey83f51123ab29
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.tsindex 8a4b6621b3..bb17b4a457 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@@ -13,7 +13,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {const invoiceId = charge.invoice as string;if (!dubCustomerId) {- return;+ return "Customer ID not found in Stripe checkout session metadata, skipping...";}let customer;@@ -33,7 +33,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {} catch (error) {// Skip if customer not foundconsole.error(error);- return;+ return `Customer with external ID ${dubCustomerId} not found, skipping...`;}if (invoiceId) {@@ -48,14 +48,14 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {"[Stripe Webhook] Skipping already processed invoice.",invoiceId,);- return;+ return `Invoice with ID ${invoiceId} already processed, skipping...`;}}// Find leadconst leadEvent = await getLeadEvent({ customerId: customer.id });if (!leadEvent || leadEvent.data.length === 0) {- return;+ return `Lead event with customer ID ${customer.id} not found, skipping...`;}await Promise.all([@@ -82,4 +82,6 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {},}),]);++ 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.tsindex 897d52d9e7..93a876dde7 100644--- a/apps/web/app/api/stripe/connect/webhook/customer-created.ts+++ b/apps/web/app/api/stripe/connect/webhook/customer-created.ts@@ -13,13 +13,13 @@ export async function customerCreated(event: Stripe.Event) {// The client app should always send dclid via metadataif (!clickId) {- return;+ return "Click ID not found in Stripe customer metadata, skipping...";}// Find clickconst clickEvent = await getClickEvent({ clickId });if (!clickEvent || clickEvent.data.length === 0) {- return;+ return `Click event with ID ${clickId} not found, skipping...`;}// Check the customer is not already created@@ -32,11 +32,7 @@ export async function customerCreated(event: Stripe.Event) {});if (customerFound) {- console.info(- "[Stripe Webhook] Found existing customer with externalId",- externalId,- );- return;+ return `Customer with external ID ${externalId} already exists, skipping...`;}// Create customer@@ -91,4 +87,6 @@ export async function customerCreated(event: Stripe.Event) {},}),]);++ 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.tsindex a8e0c64b8d..dc9ec183e5 100644--- a/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts+++ b/apps/web/app/api/stripe/connect/webhook/invoice-paid.ts@@ -20,7 +20,7 @@ export async function invoicePaid(event: Stripe.Event) {});if (!customer) {- return;+ return `Customer with stripeCustomerId ${stripeCustomerId} not found, skipping...`;}// Skip if invoice id is already processed@@ -34,13 +34,13 @@ export async function invoicePaid(event: Stripe.Event) {"[Stripe Webhook] Skipping already processed invoice.",invoiceId,);- return;+ return `Invoice with ID ${invoiceId} already processed, skipping...`;}// Find leadconst leadEvent = await getLeadEvent({ customerId: customer.id });if (!leadEvent || leadEvent.data.length === 0) {- return;+ return `Lead event with customer ID ${customer.id} not found, skipping...`;}await Promise.all([@@ -67,4 +67,6 @@ export async function invoicePaid(event: Stripe.Event) {},}),]);++ return `Sale recorded for customer ID ${customer.id} and invoice ID ${invoiceId}`;}diff --git a/apps/web/app/api/stripe/connect/webhook/route.ts b/apps/web/app/api/stripe/connect/webhook/route.tsindex dfb1dacc8f..b1f680f719 100644--- a/apps/web/app/api/stripe/connect/webhook/route.ts+++ b/apps/web/app/api/stripe/connect/webhook/route.ts@@ -34,24 +34,26 @@ export const POST = async (req: Request) => {// Ignore unsupported eventsif (!relevantEvents.has(event.type)) {- return new Response("OK", {+ return new Response("Unsupported event, skipping...", {status: 200,});}+ let response = "OK";+switch (event.type) {case "customer.created":- await customerCreated(event);+ response = await customerCreated(event);break;case "checkout.session.completed":- await checkoutSessionCompleted(event);+ response = await checkoutSessionCompleted(event);break;case "invoice.paid":- await invoicePaid(event);+ response = await invoicePaid(event);break;}- return new Response("OK", {+ return new Response(response, {status: 200,});};