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.

Refactor customer context to include country and productId in webhook and sale tracking

Kiran K22275997635c
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 9717bbd01e..296121ef66 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
@@ -339,7 +339,12 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
invoiceId,
currency: saleData.currency,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
+ sale: {
+ productId: charge.metadata?.productId,
+ },
},
});
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.ts
index ab7fb22597..c8233dd75f 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
@@ -190,7 +190,12 @@ export async function invoicePaid(event: Stripe.Event) {
invoiceId,
currency: saleData.currency,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
+ sale: {
+ productId: invoice.lines.data[0]?.pricing?.price_details?.product,
+ },
},
});
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/utils.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/utils.ts
index aefdba6627..7bf47157a6 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/utils.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/utils.ts
@@ -108,7 +108,9 @@ export async function createNewCustomer(event: Stripe.Event) {
customerId: customer.id,
quantity: 1,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
},
});
}
diff --git a/apps/web/app/(ee)/api/track/lead/route.ts b/apps/web/app/(ee)/api/track/lead/route.ts
index 085fb5a017..6c97578c83 100644
--- a/apps/web/app/(ee)/api/track/lead/route.ts
+++ b/apps/web/app/(ee)/api/track/lead/route.ts
@@ -253,7 +253,9 @@ export const POST = withWorkspace(
customerId: customer.id,
quantity: eventQuantity ?? 1,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
},
});
}
diff --git a/apps/web/app/(ee)/api/track/sale/route.ts b/apps/web/app/(ee)/api/track/sale/route.ts
index f4acc69b15..d5fcbbe873 100644
--- a/apps/web/app/(ee)/api/track/sale/route.ts
+++ b/apps/web/app/(ee)/api/track/sale/route.ts
@@ -226,7 +226,12 @@ export const POST = withWorkspace(
invoiceId,
currency,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
+ sale: {
+ productId: metadata?.productId as string,
+ },
},
});
diff --git a/apps/web/lib/actions/partners/create-commission.ts b/apps/web/lib/actions/partners/create-commission.ts
index 955a308a07..7d328454d6 100644
--- a/apps/web/lib/actions/partners/create-commission.ts
+++ b/apps/web/lib/actions/partners/create-commission.ts
@@ -182,7 +182,9 @@ export const createCommissionAction = authActionClient
createdAt: finalLeadEventDate,
user,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
},
}),
]);
@@ -221,7 +223,9 @@ export const createCommissionAction = authActionClient
createdAt: saleDate,
user,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
},
}),
]);
diff --git a/apps/web/lib/integrations/shopify/create-sale.ts b/apps/web/lib/integrations/shopify/create-sale.ts
index fd6cecf8f9..ef9aece567 100644
--- a/apps/web/lib/integrations/shopify/create-sale.ts
+++ b/apps/web/lib/integrations/shopify/create-sale.ts
@@ -138,7 +138,9 @@ export async function createShopifySale({
invoiceId: saleData.invoice_id,
currency: saleData.currency,
context: {
- customer,
+ customer: {
+ country: customer.country,
+ },
},
});
diff --git a/apps/web/lib/zod/schemas/reward-conditions.ts b/apps/web/lib/zod/schemas/reward-conditions.ts
index 5878d7b731..ea64e75020 100644
--- a/apps/web/lib/zod/schemas/reward-conditions.ts
+++ b/apps/web/lib/zod/schemas/reward-conditions.ts
@@ -31,13 +31,13 @@ export const rewardConditionsSchema = z.object({
export const rewardContextSchema = z.object({
customer: z
.object({
- country: z.string().nullable(),
+ country: z.string().nullish(),
})
.optional(),
sale: z
.object({
- productId: z.string().nullable(),
+ productId: z.string().nullish(),
})
.optional(),
});