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.

charge failure fee only for ACH payment failures

Kiran K0271cf86c139
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 71aa6f2a52..47638be8b5 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
@@ -88,19 +88,23 @@ export async function chargeFailed(event: Stripe.Event) {
}
const paymentMethod = paymentMethods.data[0];
+ const shouldChargeFailureFee =
+ charge.payment_method_details?.type === "ach_debit";
- // Charge the failure fee to the workspace
- await stripe.paymentIntents.create({
- amount: PAYOUT_FAILURE_FEE_CENTS,
- customer: workspace.stripeId,
- payment_method_types: ["card"],
- payment_method: paymentMethod.id,
- currency: "usd",
- confirmation_method: "automatic",
- confirm: true,
- statement_descriptor: "Dub Partners",
- description: `Dub Partners payout failure fee for invoice ${invoice.id}`,
- });
+ // Charge failure fee for ACH payment failures
+ if (shouldChargeFailureFee) {
+ await stripe.paymentIntents.create({
+ amount: PAYOUT_FAILURE_FEE_CENTS,
+ customer: workspace.stripeId,
+ payment_method_types: ["card"],
+ payment_method: paymentMethod.id,
+ currency: "usd",
+ confirmation_method: "automatic",
+ confirm: true,
+ statement_descriptor: "Dub Partners",
+ description: `Dub Partners payout failure fee for invoice ${invoice.id}`,
+ });
+ }
waitUntil(
(async () => {
@@ -115,8 +119,10 @@ export async function chargeFailed(event: Stripe.Event) {
},
payout: {
amount,
- failureFee: PAYOUT_FAILURE_FEE_CENTS,
- cardLast4: paymentMethod.card?.last4 || "",
+ ...(shouldChargeFailureFee && {
+ failureFee: PAYOUT_FAILURE_FEE_CENTS,
+ cardLast4: paymentMethod.card?.last4 || "",
+ }),
},
}));
diff --git a/packages/email/src/templates/partner-payout-failed.tsx b/packages/email/src/templates/partner-payout-failed.tsx
index c8bd5d1aa7..c8c954da67 100644
--- a/packages/email/src/templates/partner-payout-failed.tsx
+++ b/packages/email/src/templates/partner-payout-failed.tsx
@@ -36,8 +36,8 @@ export default function PartnerPayoutFailed({
};
payout: {
amount: number; // in cents
- failureFee: number; // in cents
- cardLast4: string;
+ failureFee?: number; // in cents
+ cardLast4?: string;
};
email: string;
}) {
@@ -75,13 +75,15 @@ export default function PartnerPayoutFailed({
and will need to be confirmed again.
</Text>
- <Text className="text-sm leading-6 text-neutral-600">
- We've charged a{" "}
- <span className="font-semibold text-neutral-800">
- ${payout.failureFee / 100} payment failure fee
- </span>{" "}
- to your card ending in {payout.cardLast4}.
- </Text>
+ {payout.failureFee && payout.cardLast4 && (
+ <Text className="text-sm leading-6 text-neutral-600">
+ We've charged a{" "}
+ <span className="font-semibold text-neutral-800">
+ ${payout.failureFee / 100} payment failure fee
+ </span>{" "}
+ to your card ending in {payout.cardLast4}.
+ </Text>
+ )}
<Text className="text-sm leading-6 text-neutral-600">
Please update your payment info to avoid disruption.