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.

dynamic payouts

Steven Tey27bf7bb6910b
diff --git a/apps/web/lib/actions/partners/confirm-payouts.ts b/apps/web/lib/actions/partners/confirm-payouts.ts
index 9827906332..4e1f54af09 100644
--- a/apps/web/lib/actions/partners/confirm-payouts.ts
+++ b/apps/web/lib/actions/partners/confirm-payouts.ts
@@ -3,11 +3,7 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { createId } from "@/lib/api/utils";
import { limiter } from "@/lib/cron/limiter";
-import {
- DUB_PARTNERS_PAYOUT_FEE_ACH,
- DUB_PARTNERS_PAYOUT_FEE_CARD,
- MIN_PAYOUT_AMOUNT,
-} from "@/lib/partners/constants";
+import { MIN_PAYOUT_AMOUNT, PAYOUT_FEES } from "@/lib/partners/constants";
import { stripe } from "@/lib/stripe";
import { sendEmail } from "@dub/email";
import { PartnerPayoutConfirmed } from "@dub/email/templates/partner-payout-confirmed";
@@ -112,9 +108,10 @@ export const confirmPayoutsAction = authActionClient
);
const fee =
- paymentMethod.type === "us_bank_account"
- ? amount * DUB_PARTNERS_PAYOUT_FEE_ACH
- : amount * DUB_PARTNERS_PAYOUT_FEE_CARD;
+ amount *
+ PAYOUT_FEES[workspace.plan?.split(" ")[0] ?? "business"][
+ paymentMethod.type === "us_bank_account" ? "ach" : "card"
+ ];
const total = amount + fee;
diff --git a/apps/web/lib/partners/constants.ts b/apps/web/lib/partners/constants.ts
index d926ec2f53..0502b7da17 100644
--- a/apps/web/lib/partners/constants.ts
+++ b/apps/web/lib/partners/constants.ts
@@ -1,5 +1,14 @@
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;
+
+export const PAYOUT_FEES = {
+ business: {
+ ach: 0.05,
+ card: 0.08,
+ },
+ enterprise: {
+ ach: 0.03,
+ card: 0.06,
+ },
+};
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsx
index 930eb7e3b8..ec03dc5e21 100644
--- a/apps/web/ui/partners/payout-invoice-sheet.tsx
+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx
@@ -1,9 +1,5 @@
import { confirmPayoutsAction } from "@/lib/actions/partners/confirm-payouts";
-import {
- DUB_PARTNERS_PAYOUT_FEE_ACH,
- DUB_PARTNERS_PAYOUT_FEE_CARD,
- MIN_PAYOUT_AMOUNT,
-} from "@/lib/partners/constants";
+import { MIN_PAYOUT_AMOUNT, PAYOUT_FEES } from "@/lib/partners/constants";
import usePaymentMethods from "@/lib/swr/use-payment-methods";
import usePayouts from "@/lib/swr/use-payouts";
import useWorkspace from "@/lib/swr/use-workspace";
@@ -16,6 +12,7 @@ import {
Gear,
GreekTemple,
Sheet,
+ SimpleTooltipContent,
Table,
Tooltip,
useRouterStuff,
@@ -45,43 +42,43 @@ interface PayoutInvoiceSheetProps {
setIsOpen: Dispatch<SetStateAction<boolean>>;
}
-const paymentMethodsTypes = Object.freeze({
- link: {
- label: "link",
- type: "link",
- icon: CreditCard,
- fee: DUB_PARTNERS_PAYOUT_FEE_CARD,
- duration: "Instantly",
- },
- card: {
- label: "card",
- type: "card",
- icon: CreditCard,
- fee: DUB_PARTNERS_PAYOUT_FEE_CARD,
- duration: "Instantly",
- },
- us_bank_account: {
- label: "ACH",
- type: "us_bank_account",
- icon: GreekTemple,
- fee: DUB_PARTNERS_PAYOUT_FEE_ACH,
- duration: "4 business days",
- },
-});
-
-type PaymentMethodWithFee =
- (typeof paymentMethodsTypes)[keyof typeof paymentMethodsTypes] & {
- id: string;
- };
-
function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {
- const { id: workspaceId, slug } = useWorkspace();
+ const { id: workspaceId, slug, plan } = useWorkspace();
const { programId } = useParams<{ programId: string }>();
const { paymentMethods, loading: paymentMethodsLoading } =
usePaymentMethods();
const [selectedPayouts, setSelectedPayouts] = useState<PayoutResponse[]>([]);
+ const paymentMethodsTypes = Object.freeze({
+ link: {
+ label: "link",
+ type: "link",
+ icon: CreditCard,
+ fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].card,
+ duration: "Instantly",
+ },
+ card: {
+ label: "card",
+ type: "card",
+ icon: CreditCard,
+ fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].card,
+ duration: "Instantly",
+ },
+ us_bank_account: {
+ label: "ACH",
+ type: "us_bank_account",
+ icon: GreekTemple,
+ fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].ach,
+ duration: "4 business days",
+ },
+ });
+
+ type PaymentMethodWithFee =
+ (typeof paymentMethodsTypes)[keyof typeof paymentMethodsTypes] & {
+ id: string;
+ };
+
const [selectedPaymentMethod, setSelectedPaymentMethod] =
useState<PaymentMethodWithFee | null>(null);
@@ -218,14 +215,14 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {
maximumFractionDigits: 2,
}),
- Fee: (
+ Fee: selectedPaymentMethod ? (
<Tooltip
content={
- selectedPaymentMethod
- ? `${selectedPaymentMethod.fee * 100}% ${capitalize(
- selectedPaymentMethod.label,
- )} fees`
- : "Loading..."
+ <SimpleTooltipContent
+ title={`${selectedPaymentMethod.fee * 100}% processing fee.${selectedPaymentMethod.type !== "us_bank_account" ? " Switch to ACH for a reduced fee." : ""}`}
+ cta="Learn more"
+ href="https://d.to/payouts"
+ />
}
>
<span className="underline decoration-dotted underline-offset-2">
@@ -235,6 +232,8 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {
})}
</span>
</Tooltip>
+ ) : (
+ <div className="h-4 w-24 animate-pulse rounded-md bg-neutral-200" />
),
Duration: (