@@ -7,6 +7,7 @@ import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-progr
77import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw" ;
88import {
99 CUTOFF_PERIOD_MAX_PAYOUTS ,
10+ DIRECT_DEBIT_PAYMENT_METHOD_TYPES ,
1011 INVOICE_MIN_PAYOUT_AMOUNT_CENTS ,
1112 PAYMENT_METHOD_TYPES ,
1213 STRIPE_PAYMENT_METHOD_NORMALIZATION ,
@@ -15,6 +16,7 @@ import { qstash } from "@/lib/cron";
1516import { exceededLimitError } from "@/lib/exceeded-limit-error" ;
1617import { CUTOFF_PERIOD_ENUM } from "@/lib/partners/cutoff-period" ;
1718import { stripe } from "@/lib/stripe" ;
19+ import { checkPaymentMethodMandate } from "@/lib/stripe/check-payment-method-mandate" ;
1820import { getWebhooks } from "@/lib/webhook/get-webhooks" ;
1921import { prisma } from "@dub/prisma" ;
2022import { APP_DOMAIN_WITH_NGROK } from "@dub/utils" ;
@@ -161,6 +163,20 @@ export const confirmPayoutsAction = authActionClient
161163 throw new Error ( "Fast settlement is only supported for ACH payment." ) ;
162164 }
163165
166+ if ( DIRECT_DEBIT_PAYMENT_METHOD_TYPES . includes ( paymentMethod . type ) ) {
167+ // check if mandate is valid
168+ const mandate = await checkPaymentMethodMandate ( {
169+ paymentMethodId,
170+ } ) ;
171+ if ( ! mandate ) {
172+ // remove the payment method
173+ await stripe . paymentMethods . detach ( paymentMethodId ) ;
174+ throw new Error (
175+ "No active mandate found for this bank account. Please set up a new bank account for payouts under your billing settings page." ,
176+ ) ;
177+ }
178+ }
179+
164180 const invoice = await prisma . $transaction ( async ( tx ) => {
165181 // Generate the next invoice number by counting the number of invoices for the workspace
166182 const totalInvoices = await tx . invoice . count ( {
0 commit comments