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.

exclude credit grants from product line amounts

Pedro Ladeira7274d0fa4f4e
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 9c03fbd7ad..0e3058e85c 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
@@ -310,9 +310,19 @@ export async function invoicePaid({
if (!productId) return null;
+ // Credit grants sit on the line, not in line.amount — subtract so
+ // productId rewards commission on the portion actually charged.
+ const creditGrantAmount = (line.pretax_credit_amounts ?? []).reduce(
+ (sum, credit) =>
+ credit.type === "credit_balance_transaction"
+ ? sum + credit.amount
+ : sum,
+ 0,
+ );
+
return {
id: productId,
- amount: line.amount,
+ amount: Math.max(line.amount - creditGrantAmount, 0),
quantity: line.quantity ?? 0,
};
})