The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix checkout.session.completed connect webhook
Steven Teyf46c2ff1ee96
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 2ac167ee92..06d7f601d3 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@@ -66,22 +66,6 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {return `Customer with dubCustomerId ${dubCustomerId} not found, skipping...`;}- if (invoiceId) {- // Skip if invoice id is already processed- const ok = await redis.set(`dub_sale_events:invoiceId:${invoiceId}`, 1, {- ex: 60 * 60 * 24 * 7,- nx: true,- });-- if (!ok) {- console.info(- "[Stripe Webhook] Skipping already processed invoice.",- invoiceId,- );- return `Invoice with ID ${invoiceId} already processed, skipping...`;- }- }-// Find leadleadEvent = await getLeadEvent({ customerId: customer.id }).then((res) => res.data[0],@@ -164,8 +148,10 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {});}+ // remove timestamp from clickEvent+ const { timestamp, ...rest } = clickEvent;leadEvent = {- ...clickEvent,+ ...rest,event_id: nanoid(16),event_name: "Checkout session completed",customer_id: customer.id,@@ -187,6 +173,22 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {return `Checkout session completed for Stripe customer ${stripeCustomerId} with invoice ID ${invoiceId} but amount is 0, skipping...`;}+ if (invoiceId) {+ // Skip if invoice id is already processed+ const ok = await redis.set(`dub_sale_events:invoiceId:${invoiceId}`, 1, {+ ex: 60 * 60 * 24 * 7,+ nx: true,+ });++ if (!ok) {+ console.info(+ "[Stripe Webhook] Skipping already processed invoice.",+ invoiceId,+ );+ return `Invoice with ID ${invoiceId} already processed, skipping...`;+ }+ }+// support for Stripe Adaptive Pricing: https://docs.stripe.com/payments/checkout/adaptive-pricingif (charge.currency !== "usd" && charge.currency_conversion) {charge.amount_total = charge.currency_conversion.amount_total;