Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,13 @@ export async function checkoutSessionCompleted(
workspaceId: workspace.id,
programId: link.programId,
partnerId: link.partnerId,
customerId: customer.id,
customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
saleAmount: saleData.amount,
},
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,13 @@ export async function invoicePaid(
workspaceId: workspace.id,
programId: link.programId,
partnerId: link.partnerId,
customerId: customer.id,
customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
saleAmount: saleData.amount,
},
},
}),
Expand Down
4 changes: 3 additions & 1 deletion apps/web/lib/api/conversions/track-sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,13 @@ const _trackSale = async ({
workspaceId: workspace.id,
programId: link.programId,
partnerId: link.partnerId,
customerId: customer.id,
customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
saleAmount: saleData.amount,
},
},
}),
Expand Down
13 changes: 12 additions & 1 deletion apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const executeCompleteBountyWorkflow = async ({

const { bountyId } = action.data;
const { identity, metrics } = context;
const { partnerId, groupId } = identity;
const { partnerId, groupId, customerId, customerFirstSaleAt } = identity;

if (!groupId) {
console.error("Partner groupId not set in the context.");
Expand Down Expand Up @@ -118,6 +118,17 @@ export const executeCompleteBountyWorkflow = async ({
}
}

if (
bounty.performanceScope === "new" &&
customerFirstSaleAt &&
customerFirstSaleAt < bounty.startsAt
) {
console.log(
`Bounty ${bounty.id} is for net-new revenue only and partner ${partnerId} referred customer ${customerId} before the bounty started, skipping...`,
);
return;
}

console.log(
`Partner is eligible for bounty ${bounty.id}, executing workflow ${bounty.workflowId}...`,
);
Expand Down
4 changes: 3 additions & 1 deletion apps/web/lib/integrations/shopify/create-sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ export async function createShopifySale({
workspaceId: workspaceId,
programId: link.programId,
partnerId: link.partnerId,
customerId: customer.id,
customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
saleAmount: saleData.amount,
},
},
}),
Expand Down
2 changes: 2 additions & 0 deletions apps/web/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ interface WorkflowIdentity {
programId: string;
partnerId: string;
groupId?: string;
customerId?: string;
customerFirstSaleAt?: Date;
}

interface PartnerMetrics {
Expand Down
Loading