The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update trigger-withdrawal cron
Steven Teya59aed3f758d
diff --git a/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts b/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.tsindex c2ed5da268..9c7e89d66d 100644--- a/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts+++ b/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts@@ -16,21 +16,20 @@ export async function GET(req: Request) {const [currentBalance, pendingPayouts] = await Promise.all([stripe.balance.retrieve(),- prisma.payout.findMany({+ prisma.payout.aggregate({where: {status: "processing",},+ _sum: {+ amount: true,+ },}),]);let reservedBalance = 50000; // keep at least $500 in the account- if (pendingPayouts.length) {- const totalPendingPayouts = pendingPayouts.reduce(- (acc, payout) => acc + payout.amount,- 0,- );-+ const totalPendingPayouts = pendingPayouts._sum.amount;+ if (totalPendingPayouts) {// add the pending payouts to the reserved balance (to make sure we have enough balance// to pay out partners when chargeSucceeded webhook is triggered)reservedBalance += totalPendingPayouts;@@ -45,6 +44,12 @@ export async function GET(req: Request) {const balanceToWithdraw =currentBalance.available[0].amount - reservedBalance;+ if (balanceToWithdraw <= 10000) {+ return NextResponse.json({+ message: "Balance to withdraw is less than $100, skipping...",+ });+ }+const createPayout = await stripe.payouts.create({amount: balanceToWithdraw,currency: "usd",