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.

add MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS

Steven Tey078701f21e4f
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
index 188c5069eb..03966fb574 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
@@ -3,6 +3,7 @@
import { forceWithdrawalAction } from "@/lib/actions/partners/force-withdrawal";
import {
BELOW_MIN_WITHDRAWAL_FEE_CENTS,
+ MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS,
MIN_WITHDRAWAL_AMOUNT_CENTS,
} from "@/lib/constants/payouts";
import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
@@ -98,6 +99,11 @@ function PayoutStatsCard({
text="Pay out now"
className="ml-2 h-7 px-2 py-1"
onClick={() => setShowForceWithdrawalModal(true)}
+ disabledTooltip={
+ amount < MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS
+ ? `Your current processed payouts balance is less than the minimum amount required for withdrawal (${currencyFormatter(MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS)}).`
+ : undefined
+ }
/>
)}
</div>
@@ -231,8 +237,7 @@ export function PayoutStats() {
for this payout, which means you will receive{" "}
<strong className="text-black">
{currencyFormatter(
- (payoutStatusMap?.processed?.amount -
- BELOW_MIN_WITHDRAWAL_FEE_CENTS),
+ payoutStatusMap?.processed?.amount - BELOW_MIN_WITHDRAWAL_FEE_CENTS,
{ trailingZeroDisplay: "stripIfInteger" },
)}
</strong>
diff --git a/apps/web/lib/actions/partners/force-withdrawal.ts b/apps/web/lib/actions/partners/force-withdrawal.ts
index 9391314f19..ba711a0af7 100644
--- a/apps/web/lib/actions/partners/force-withdrawal.ts
+++ b/apps/web/lib/actions/partners/force-withdrawal.ts
@@ -1,9 +1,11 @@
"use server";
import { throwIfNoPermission } from "@/lib/auth/partner-users/throw-if-no-permission";
+import { MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS } from "@/lib/constants/payouts";
import { createStripeTransfer } from "@/lib/partners/create-stripe-transfer";
import { ratelimit } from "@/lib/upstash";
import { prisma } from "@dub/prisma";
+import { currencyFormatter } from "@dub/utils";
import { authPartnerActionClient } from "../safe-action";
// Force a withdrawal for a partner (even if the total amount is below the minimum withdrawal amount)
@@ -53,6 +55,16 @@ export const forceWithdrawalAction = authPartnerActionClient.action(
);
}
+ const totalProcessedAmount = previouslyProcessedPayouts.reduce(
+ (acc, payout) => acc + payout.amount,
+ 0,
+ );
+ if (totalProcessedAmount < MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS) {
+ throw new Error(
+ `Your current processed payouts balance (${currencyFormatter(totalProcessedAmount)}) is less than the minimum amount required for withdrawal (${currencyFormatter(MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS)}).`,
+ );
+ }
+
try {
await createStripeTransfer({
partner,
diff --git a/apps/web/lib/constants/payouts.ts b/apps/web/lib/constants/payouts.ts
index 6d39595dbb..42741437a3 100644
--- a/apps/web/lib/constants/payouts.ts
+++ b/apps/web/lib/constants/payouts.ts
@@ -11,6 +11,7 @@ export const ALLOWED_MIN_PAYOUT_AMOUNTS = [0, 1000, 2000, 5000, 10000];
export const INVOICE_MIN_PAYOUT_AMOUNT_CENTS = 1000; // $10
export const MIN_WITHDRAWAL_AMOUNT_CENTS = 1000; // $10
export const BELOW_MIN_WITHDRAWAL_FEE_CENTS = 50; // $0.50
+export const MIN_FORCE_WITHDRAWAL_AMOUNT_CENTS = 100; // $1 (doesn't make sense to force a withdrawal for less than $1)
export const ELIGIBLE_PAYOUTS_MAX_PAGE_SIZE = 500;
export const CUTOFF_PERIOD_MAX_PAYOUTS = 1000;