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.

address CR feedback

Steven Teya11510768c24
diff --git a/apps/web/lib/api/commissions/create-manual-commissions.ts b/apps/web/lib/api/commissions/create-manual-commissions.ts
index 34656ebf6a..2bd93cb167 100644
--- a/apps/web/lib/api/commissions/create-manual-commissions.ts
+++ b/apps/web/lib/api/commissions/create-manual-commissions.ts
@@ -566,9 +566,9 @@ async function recordEvents(args: RecordEventsArgs) {
});
if (stripeInvoicesToImport === "all") {
- // Filter out invoices that are already associated with a commission on Dub
+ // Skip invoices that already have a commission, and refunded invoices.
stripeCustomerInvoices = stripeCustomerInvoices.filter(
- (invoice) => !invoice.dubCommissionId,
+ (invoice) => !invoice.dubCommissionId && !invoice.refunded,
);
} else {
const invoicesById = new Map(
@@ -598,6 +598,17 @@ async function recordEvents(args: RecordEventsArgs) {
});
}
+ const refundedInvoiceIds = requestedInvoiceIds.filter(
+ (id) => invoicesById.get(id)!.refunded,
+ );
+
+ if (refundedInvoiceIds.length > 0) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: `Refunded Stripe invoices cannot be imported: ${refundedInvoiceIds.join(", ")}`,
+ });
+ }
+
stripeCustomerInvoices = requestedInvoiceIds.map(
(id) => invoicesById.get(id)!,
);
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index 8466838536..93a727d282 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -654,7 +654,7 @@ const createSaleCommissionSchema = z
.union([z.literal("all"), z.array(z.string().min(1)).min(1).max(100)])
.nullish()
.describe(
- "Import paid Stripe invoices for the customer and create a commission for each. Pass `all` to import every unimported paid invoice, or an array of Stripe invoice IDs to import only those invoices. When not provided, create a single manual sale event using `sale.amount`",
+ "Import paid Stripe invoices for the customer and create a commission for each. Pass `all` to import every unimported, paid invoice, or an array of Stripe invoice IDs to import only those invoices. Refunded invoices are not imported. When not provided, create a single manual sale event using `sale.amount`",
),
date: parseDateSchema
.nullish()