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.

use dynamic fee on backend

Kiran Ke229b747d405
diff --git a/apps/web/lib/actions/partners/confirm-payouts.ts b/apps/web/lib/actions/partners/confirm-payouts.ts
index 5bcabb9fa8..bd46da291c 100644
--- a/apps/web/lib/actions/partners/confirm-payouts.ts
+++ b/apps/web/lib/actions/partners/confirm-payouts.ts
@@ -3,7 +3,8 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { createId } from "@/lib/api/utils";
import {
- DUB_PARTNERS_PAYOUT_FEE,
+ DUB_PARTNERS_PAYOUT_FEE_ACH,
+ DUB_PARTNERS_PAYOUT_FEE_CARD,
MIN_PAYOUT_AMOUNT,
} from "@/lib/partners/constants";
import { stripe } from "@/lib/stripe";
@@ -41,6 +42,12 @@ export const confirmPayoutsAction = authActionClient
throw new Error("Invalid payout method.");
}
+ if (!["card", "us_bank_account"].includes(payoutMethod.type)) {
+ throw new Error(
+ `We only support card and ACH for now. Please update your payout method to one of these.`,
+ );
+ }
+
const payouts = await prisma.payout.findMany({
where: {
programId,
@@ -75,7 +82,12 @@ export const confirmPayoutsAction = authActionClient
(total, payout) => total + payout.amount,
0,
);
- const fee = amount * DUB_PARTNERS_PAYOUT_FEE;
+
+ const fee =
+ payoutMethod.type === "card"
+ ? amount * DUB_PARTNERS_PAYOUT_FEE_CARD
+ : amount * DUB_PARTNERS_PAYOUT_FEE_ACH;
+
const total = amount + fee;
const invoice = await tx.invoice.create({
diff --git a/apps/web/lib/partners/constants.ts b/apps/web/lib/partners/constants.ts
index a2091f6d84..d926ec2f53 100644
--- a/apps/web/lib/partners/constants.ts
+++ b/apps/web/lib/partners/constants.ts
@@ -1,4 +1,5 @@
-export const DUB_PARTNERS_PAYOUT_FEE = 0.03;
export const MIN_PAYOUT_AMOUNT = 10000; // min payout is $100
export const SHEET_MAX_ITEMS = 6;
export const SALES_PAGE_SIZE = 8;
+export const DUB_PARTNERS_PAYOUT_FEE_CARD = 0.06;
+export const DUB_PARTNERS_PAYOUT_FEE_ACH = 0.03;