-
Notifications
You must be signed in to change notification settings - Fork 3.2k
invoiceId dedupe key between stripe and /track/sale #4225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
efc3927
43133df
b651902
89e94bb
17f7e46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // TODO: remove after 2026-08-10 (10 days after rollout) once the transition | ||
| // window has elapsed and no keys written under the old Stripe-only format | ||
| // remain (they carry a 7-day TTL). | ||
|
|
||
| export const invoiceDedupeKey = (workspaceId: string, invoiceId: string) => | ||
| `trackSale:${workspaceId}:invoiceId:${invoiceId}`; | ||
|
|
||
| export const legacyStripeInvoiceDedupeKey = (invoiceId: string) => | ||
| `trackSale:stripe:invoiceId:${invoiceId}`; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ import * as z from "zod/v4"; | |
| import { createId } from "../create-id"; | ||
| import { syncPartnerLinksStats } from "../partners/sync-partner-links-stats"; | ||
| import { executeWorkflows } from "../workflows/execute-workflows"; | ||
| import { | ||
| invoiceDedupeKey, | ||
| legacyStripeInvoiceDedupeKey, | ||
| } from "./invoice-idempotency"; | ||
|
|
||
| type TrackSaleParams = z.input<typeof trackSaleRequestSchema> & { | ||
| workspace: Pick<WorkspaceProps, "id" | "stripeConnectId" | "webhookEnabled">; | ||
|
|
@@ -62,11 +66,19 @@ export const trackSale = async ({ | |
|
|
||
| // Return idempotent response if invoiceId is already processed | ||
| if (invoiceId) { | ||
| const cachedResponse = await redis.get( | ||
| `trackSale:${workspace.id}:invoiceId:${invoiceId}`, | ||
| ); | ||
| const [cachedResponse, legacyRecord] = await redis.mget([ | ||
| invoiceDedupeKey(workspace.id, invoiceId), | ||
| legacyStripeInvoiceDedupeKey(invoiceId), | ||
| ]); | ||
|
|
||
| if (cachedResponse) { | ||
| return cachedResponse; | ||
|
Comment on lines
65
to
70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major Restore cached-response validation before returning. Line 69 returns any value stored under the shared invoice key, including Stripe webhook marker objects. Restore 🤖 Prompt for AI Agents🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Preserve the legacy Stripe-key read during migration. This lookup only checks 🤖 Prompt for AI Agents |
||
| } else if (legacyRecord) { | ||
| return { | ||
| eventName, | ||
| customer: null, | ||
| sale: null, | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -703,13 +715,9 @@ const _trackSale = async ({ | |
|
|
||
| if (invoiceId) { | ||
| waitUntil( | ||
| redis.set( | ||
| `trackSale:${workspace.id}:invoiceId:${invoiceId}`, | ||
| trackSaleResponse, | ||
| { | ||
| ex: 60 * 60 * 24 * 7, // cache for 1 week | ||
| }, | ||
| ), | ||
| redis.set(invoiceDedupeKey(workspace.id, invoiceId), trackSaleResponse, { | ||
| ex: 60 * 60 * 24 * 7, // cache for 1 week | ||
| }), | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.