The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add `STABLECOIN_PAYOUT_FIXED_FEE_CENTS` to `stablecoinFundingAmount` (#3716)
Steven Tey9a3a4b31394c
diff --git a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.tsindex 1198e88fb0..9113ea98d6 100644--- a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts+++ b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts@@ -1,5 +1,8 @@import { handleAndReturnErrorResponse } from "@/lib/api/errors";-import { MIN_WITHDRAWAL_AMOUNT_CENTS } from "@/lib/constants/payouts";+import {+ MIN_WITHDRAWAL_AMOUNT_CENTS,+ STABLECOIN_PAYOUT_FIXED_FEE_CENTS,+} from "@/lib/constants/payouts";import { verifyQstashSignature } from "@/lib/cron/verify-qstash";import { fundFinancialAccount } from "@/lib/stripe/fund-financial-account";import { prisma } from "@dub/prisma";@@ -66,8 +69,9 @@ export async function POST(req: Request) {`;// Fund the total stablecoin payout amount for this invoice- const { _sum } = await prisma.payout.aggregate({+ const { _sum, _count } = await prisma.payout.aggregate({_sum: { amount: true },+ _count: { id: true },where: {invoiceId: invoice.id,method: "stablecoin",@@ -81,7 +85,10 @@ export async function POST(req: Request) {});let skipStablecoinPayouts = false;- const stablecoinFundingAmount = _sum.amount ?? 0;+ // we need to add the STABLECOIN_PAYOUT_FIXED_FEE_CENTS for each payout to the total funding amount+ // to make sure that `createStablecoinPayout` later has enough funds to cover Stripe's fees+ const stablecoinFundingAmount =+ (_sum.amount ?? 0) + _count.id * STABLECOIN_PAYOUT_FIXED_FEE_CENTS;// Send money to Financial Account to handle stablecoin payoutsif (stablecoinFundingAmount > 0) {diff --git a/apps/web/lib/constants/payouts.ts b/apps/web/lib/constants/payouts.tsindex e28bb1bfd7..038827ef13 100644--- a/apps/web/lib/constants/payouts.ts+++ b/apps/web/lib/constants/payouts.ts@@ -10,6 +10,7 @@ export const ELIGIBLE_PAYOUTS_MAX_PAGE_SIZE = 500;export const CUTOFF_PERIOD_MAX_PAYOUTS = 1000;export const STABLECOIN_PAYOUT_FEE_RATE = 0.005; // 0.5%+export const STABLECOIN_PAYOUT_FIXED_FEE_CENTS = 50; // $0.50export const FAST_ACH_FEE_CENTS = 2500; // $25export const PAYOUT_FAILURE_FEE_CENTS = 1000; // 10 USDexport const FOREX_MARKUP_RATE = 0.005; // 0.5%