File tree Expand file tree Collapse file tree 5 files changed +51
-15
lines changed
app/(ee)/api/stripe/integration/webhook Expand file tree Collapse file tree 5 files changed +51
-15
lines changed Original file line number Diff line number Diff line change @@ -341,7 +341,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
341
341
livemode : event . livemode ,
342
342
} ) ;
343
343
344
- const commission = await createPartnerCommission ( {
344
+ await createPartnerCommission ( {
345
345
event : "sale" ,
346
346
programId : link . programId ,
347
347
partnerId : link . partnerId ,
@@ -362,15 +362,25 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
362
362
} ,
363
363
} ) ;
364
364
365
- if ( commission ) {
366
- waitUntil (
365
+ waitUntil (
366
+ Promise . allSettled ( [
367
367
executeWorkflows ( {
368
368
trigger : WorkflowTrigger . saleRecorded ,
369
369
programId : link . programId ,
370
370
partnerId : link . partnerId ,
371
371
} ) ,
372
- ) ;
373
- }
372
+ // same logic as lead.created webhook below:
373
+ // if the clickEvent variable exists and there was no existing customer before,
374
+ // we need to trigger the leadRecorded workflow
375
+ clickEvent &&
376
+ ! existingCustomer &&
377
+ executeWorkflows ( {
378
+ trigger : WorkflowTrigger . leadRecorded ,
379
+ programId : link . programId ,
380
+ partnerId : link . partnerId ,
381
+ } ) ,
382
+ ] ) ,
383
+ ) ;
374
384
}
375
385
376
386
waitUntil (
Original file line number Diff line number Diff line change @@ -209,15 +209,13 @@ export async function invoicePaid(event: Stripe.Event) {
209
209
} ,
210
210
} ) ;
211
211
212
- if ( commission ) {
213
- waitUntil (
214
- executeWorkflows ( {
215
- trigger : WorkflowTrigger . saleRecorded ,
216
- programId : link . programId ,
217
- partnerId : link . partnerId ,
218
- } ) ,
219
- ) ;
220
- }
212
+ waitUntil (
213
+ executeWorkflows ( {
214
+ trigger : WorkflowTrigger . saleRecorded ,
215
+ programId : link . programId ,
216
+ partnerId : link . partnerId ,
217
+ } ) ,
218
+ ) ;
221
219
}
222
220
223
221
// send workspace webhook
Original file line number Diff line number Diff line change 3
3
import { isFirstConversion } from "@/lib/analytics/is-first-conversion" ;
4
4
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw" ;
5
5
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw" ;
6
+ import { executeWorkflows } from "@/lib/api/workflows/execute-workflows" ;
6
7
import { createPartnerCommission } from "@/lib/partners/create-partner-commission" ;
7
8
import { getLeadEvent } from "@/lib/tinybird" ;
8
9
import { recordClick } from "@/lib/tinybird/record-click" ;
@@ -15,6 +16,7 @@ import { leadEventSchemaTB } from "@/lib/zod/schemas/leads";
15
16
import { prisma } from "@dub/prisma" ;
16
17
import { nanoid } from "@dub/utils" ;
17
18
import { COUNTRIES_TO_CONTINENTS } from "@dub/utils/src" ;
19
+ import { WorkflowTrigger } from "@prisma/client" ;
18
20
import { waitUntil } from "@vercel/functions" ;
19
21
import { authActionClient } from "../safe-action" ;
20
22
@@ -200,6 +202,12 @@ export const createCommissionAction = authActionClient
200
202
} ,
201
203
} ,
202
204
} ) ,
205
+
206
+ executeWorkflows ( {
207
+ trigger : WorkflowTrigger . leadRecorded ,
208
+ programId,
209
+ partnerId,
210
+ } ) ,
203
211
] ) ;
204
212
}
205
213
@@ -238,6 +246,12 @@ export const createCommissionAction = authActionClient
238
246
} ,
239
247
} ,
240
248
} ) ,
249
+
250
+ executeWorkflows ( {
251
+ trigger : WorkflowTrigger . saleRecorded ,
252
+ programId,
253
+ partnerId,
254
+ } ) ,
241
255
] ) ;
242
256
}
243
257
Original file line number Diff line number Diff line change 1
1
import { isFirstConversion } from "@/lib/analytics/is-first-conversion" ;
2
2
import { includeTags } from "@/lib/api/links/include-tags" ;
3
+ import { executeWorkflows } from "@/lib/api/workflows/execute-workflows" ;
3
4
import { createPartnerCommission } from "@/lib/partners/create-partner-commission" ;
4
5
import { recordSale } from "@/lib/tinybird" ;
5
6
import { LeadEventTB } from "@/lib/types" ;
@@ -8,6 +9,7 @@ import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
8
9
import { transformSaleEventData } from "@/lib/webhook/transform" ;
9
10
import { prisma } from "@dub/prisma" ;
10
11
import { nanoid } from "@dub/utils" ;
12
+ import { WorkflowTrigger } from "@prisma/client" ;
11
13
import { waitUntil } from "@vercel/functions" ;
12
14
import { orderSchema } from "./schema" ;
13
15
@@ -154,5 +156,13 @@ export async function createShopifySale({
154
156
} ,
155
157
} ,
156
158
} ) ;
159
+
160
+ waitUntil (
161
+ executeWorkflows ( {
162
+ trigger : WorkflowTrigger . saleRecorded ,
163
+ programId : link . programId ,
164
+ partnerId : link . partnerId ,
165
+ } ) ,
166
+ ) ;
157
167
}
158
168
}
Original file line number Diff line number Diff line change 5
5
EventType ,
6
6
WorkflowTrigger ,
7
7
} from "@dub/prisma/client" ;
8
- import { log } from "@dub/utils" ;
8
+ import { currencyFormatter , log } from "@dub/utils" ;
9
9
import { waitUntil } from "@vercel/functions" ;
10
10
import { differenceInMonths } from "date-fns" ;
11
11
import { recordAuditLog } from "../api/audit-logs/record-audit-log" ;
@@ -238,6 +238,10 @@ export const createPartnerCommission = async ({
238
238
} ,
239
239
} ) ;
240
240
241
+ console . log (
242
+ `Created a ${ event } commission ${ commission . id } (${ currencyFormatter ( commission . earnings ) } ) for ${ partnerId } : ${ JSON . stringify ( commission ) } ` ,
243
+ ) ;
244
+
241
245
waitUntil (
242
246
( async ( ) => {
243
247
const program = await prisma . program . findUniqueOrThrow ( {
You can’t perform that action at this time.
0 commit comments