File tree Expand file tree Collapse file tree
app/(ee)/api/cron/payouts/charge-succeeded Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { handleAndReturnErrorResponse } from "@/lib/api/errors" ;
2- import { MIN_WITHDRAWAL_AMOUNT_CENTS } from "@/lib/constants/payouts" ;
2+ import {
3+ MIN_WITHDRAWAL_AMOUNT_CENTS ,
4+ STABLECOIN_PAYOUT_FIXED_FEE_CENTS ,
5+ } from "@/lib/constants/payouts" ;
36import { verifyQstashSignature } from "@/lib/cron/verify-qstash" ;
47import { fundFinancialAccount } from "@/lib/stripe/fund-financial-account" ;
58import { prisma } from "@dub/prisma" ;
@@ -66,8 +69,9 @@ export async function POST(req: Request) {
6669 ` ;
6770
6871 // Fund the total stablecoin payout amount for this invoice
69- const { _sum } = await prisma . payout . aggregate ( {
72+ const { _sum, _count } = await prisma . payout . aggregate ( {
7073 _sum : { amount : true } ,
74+ _count : { id : true } ,
7175 where : {
7276 invoiceId : invoice . id ,
7377 method : "stablecoin" ,
@@ -81,7 +85,10 @@ export async function POST(req: Request) {
8185 } ) ;
8286
8387 let skipStablecoinPayouts = false ;
84- const stablecoinFundingAmount = _sum . amount ?? 0 ;
88+ // we need to add the STABLECOIN_PAYOUT_FIXED_FEE_CENTS for each payout to the total funding amount
89+ // to make sure that `createStablecoinPayout` later has enough funds to cover Stripe's fees
90+ const stablecoinFundingAmount =
91+ ( _sum . amount ?? 0 ) + _count . id * STABLECOIN_PAYOUT_FIXED_FEE_CENTS ;
8592
8693 // Send money to Financial Account to handle stablecoin payouts
8794 if ( stablecoinFundingAmount > 0 ) {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export const ELIGIBLE_PAYOUTS_MAX_PAGE_SIZE = 500;
1010export const CUTOFF_PERIOD_MAX_PAYOUTS = 1000 ;
1111
1212export const STABLECOIN_PAYOUT_FEE_RATE = 0.005 ; // 0.5%
13+ export const STABLECOIN_PAYOUT_FIXED_FEE_CENTS = 50 ; // $0.50
1314export const FAST_ACH_FEE_CENTS = 2500 ; // $25
1415export const PAYOUT_FAILURE_FEE_CENTS = 1000 ; // 10 USD
1516export const FOREX_MARKUP_RATE = 0.005 ; // 0.5%
You can’t perform that action at this time.
0 commit comments