The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update Stripe invoice deduplication to use `trackSale` key
Steven Tey4b7b80300a9c
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.tsindex 2e1569e65e..c06401b768 100644--- a/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts@@ -214,12 +214,13 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {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,- });+ // TODO: remove oldKeyValue stuff after 7 days (on Sep 23)+ const [newKeyValue, oldKeyValue] = await redis.mget([+ `trackSale:stripe:invoiceId:${invoiceId}`, // here we assume that Stripe's invoice ID is unique across all customers+ `dub_sale_events:invoiceId:${invoiceId}`,+ ]);- if (!ok) {+ if (newKeyValue || oldKeyValue) {console.info("[Stripe Webhook] Skipping already processed invoice.",invoiceId,diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.tsindex a9c388e049..782ee4e268 100644--- a/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts@@ -65,12 +65,13 @@ export async function invoicePaid(event: Stripe.Event) {}// 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,- });+ // TODO: remove oldKeyValue stuff after 7 days (on Sep 23)+ const [newKeyValue, oldKeyValue] = await redis.mget([+ `trackSale:stripe:invoiceId:${invoiceId}`, // here we assume that Stripe's invoice ID is unique across all customers+ `dub_sale_events:invoiceId:${invoiceId}`,+ ]);- if (!ok) {+ if (newKeyValue || oldKeyValue) {console.info("[Stripe Webhook] Skipping already processed invoice.",invoiceId,