Skip to content

Commit b56ebfc

Browse files
authored
Merge branch 'main' into payout-settings
2 parents 3bc6950 + 00dc858 commit b56ebfc

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • apps/web/app/(ee)/api/cron/payouts/balance-available

‎apps/web/app/(ee)/api/cron/payouts/balance-available/route.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ export const POST = withCron(async ({ rawBody }) => {
6060

6161
let { amount: availableBalance, currency } = balance.available[0];
6262

63-
// if available balance is 0, check if there's any pending balance
64-
if (availableBalance === 0) {
63+
if (["huf", "twd"].includes(currency)) {
64+
// Stripe requires HUF/TWD payouts to be evenly divisible by 100
65+
availableBalance = Math.floor(availableBalance / 100) * 100;
66+
}
67+
68+
// Stripe requires payout amount >= 1; skip dust (e.g. HUF/TWD rounded down)
69+
// and negatives (refunds/reversals). Requeue if funds are still pending.
70+
if (availableBalance < 1) {
6571
const pendingBalance = balance.pending?.[0]?.amount ?? 0;
6672

6773
// if there's a pending balance, schedule another check in 1 hour
@@ -83,7 +89,7 @@ export const POST = withCron(async ({ rawBody }) => {
8389
}
8490

8591
return logAndRespond(
86-
`Partner ${partner.email} (${stripeAccount})'s available balance is 0. Skipping...`,
92+
`Partner ${partner.email} (${stripeAccount}) has no payable available balance (${currencyFormatter(availableBalance, { currency })}). Skipping...`,
8793
);
8894
}
8995

@@ -125,12 +131,6 @@ export const POST = withCron(async ({ rawBody }) => {
125131
);
126132
}
127133

128-
if (["huf", "twd"].includes(currency)) {
129-
// For HUF and TWD, Stripe requires payout amounts to be evenly divisible by 100
130-
// We need to round down to the nearest 100 units
131-
availableBalance = Math.floor(availableBalance / 100) * 100;
132-
}
133-
134134
const stripePayout = await stripe.payouts.create(
135135
{
136136
amount: availableBalance,

0 commit comments

Comments
 (0)