Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update checkout-session-completed.ts

Kiran K15af9eae9676
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.ts
index cec57daee6..7b615ae202 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
@@ -14,12 +14,7 @@ import {
recordSale,
} from "@/lib/tinybird";
import { recordFakeClick } from "@/lib/tinybird/record-fake-click";
-import {
- ClickEventTB,
- LeadEventTB,
- StripeMode,
- WebhookPartner,
-} from "@/lib/types";
+import { ClickEventTB, LeadEventTB, StripeMode } from "@/lib/types";
import { redis } from "@/lib/upstash";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import {
@@ -629,26 +624,27 @@ async function attributeViaPromoCode({
(async () => {
const linkUpdated = await incrementLinkLeads(link.id);
- let webhookPartner: WebhookPartner | undefined;
+ let createdCommission:
+ | Awaited<ReturnType<typeof createPartnerCommission>>
+ | undefined = undefined;
+
if (link.programId && link.partnerId) {
- await Promise.allSettled([
- createPartnerCommission({
- event: "lead",
- programId: link.programId,
- partnerId: link.partnerId,
- linkId: link.id,
- eventId: leadEvent.event_id,
- customerId: customer.id,
- quantity: 1,
- context: {
- customer: {
- country: customer.country,
- },
+ createdCommission = await createPartnerCommission({
+ event: "lead",
+ programId: link.programId,
+ partnerId: link.partnerId,
+ linkId: link.id,
+ eventId: leadEvent.event_id,
+ customerId: customer.id,
+ quantity: 1,
+ context: {
+ customer: {
+ country: customer.country,
},
- }).then((res) => {
- webhookPartner = res.webhookPartner;
- }),
+ },
+ });
+ await Promise.allSettled([
executeWorkflows({
trigger: WorkflowTrigger.leadRecorded,
context: {
@@ -659,6 +655,7 @@ async function attributeViaPromoCode({
},
},
}),
+
syncPartnerLinksStats({
partnerId: link.partnerId,
programId: link.programId,
@@ -666,6 +663,7 @@ async function attributeViaPromoCode({
}),
]);
}
+
await sendWorkspaceWebhook({
trigger: "lead.created",
workspace,
@@ -674,7 +672,7 @@ async function attributeViaPromoCode({
eventName: "Checkout session completed",
link: linkUpdated,
customer,
- partner: webhookPartner,
+ partner: createdCommission?.webhookPartner,
metadata: null,
}),
});