Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

DIRECT_DEBIT_PAYMENT_METHOD_TYPES

Steven Teya9c005ff7240
diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
index a742e9e693..dce73529fa 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
@@ -1,4 +1,7 @@
-import { PAYOUT_FAILURE_FEE_CENTS } from "@/lib/partners/constants";
+import {
+ DIRECT_DEBIT_PAYMENT_METHOD_TYPES,
+ PAYOUT_FAILURE_FEE_CENTS,
+} from "@/lib/partners/constants";
import { stripe } from "@/lib/stripe";
import { sendEmail } from "@dub/email";
import PartnerPayoutFailed from "@dub/email/templates/partner-payout-failed";
@@ -80,8 +83,13 @@ export async function chargeFailed(event: Stripe.Event) {
let cardLast4: string | undefined;
let chargedFailureFee = false;
- // Charge failure fee for ACH payment failures
- if (charge.payment_method_details?.type === "us_bank_account") {
+ // Charge failure fee for direct debit payment failures
+ if (
+ charge.payment_method_details &&
+ DIRECT_DEBIT_PAYMENT_METHOD_TYPES.includes(
+ charge.payment_method_details.type as Stripe.PaymentMethod.Type,
+ )
+ ) {
const [cards, links] = await Promise.all([
stripe.paymentMethods.list({
customer: workspace.stripeId,
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
index 53ad362335..0e96a9c645 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
@@ -2,6 +2,7 @@ import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import {
+ DIRECT_DEBIT_PAYMENT_METHOD_TYPES,
DIRECT_DEBIT_PAYMENT_TYPES_INFO,
PAYMENT_METHOD_TYPES,
} from "@/lib/partners/constants";
@@ -26,14 +27,14 @@ export const GET = withWorkspace(async ({ workspace }) => {
customer: workspace.stripeId,
});
- // reorder to put ACH first
- const ach = paymentMethods.data.find(
- (method) => method.type === "us_bank_account",
+ // reorder to put direct debit first
+ const directDebit = paymentMethods.data.find((method) =>
+ DIRECT_DEBIT_PAYMENT_METHOD_TYPES.includes(method.type),
);
return NextResponse.json([
- ...(ach ? [ach] : []),
- ...paymentMethods.data.filter((method) => method.id !== ach?.id),
+ ...(directDebit ? [directDebit] : []),
+ ...paymentMethods.data.filter((method) => method.id !== directDebit?.id),
]);
} catch (error) {
console.error(error);