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.

update partner payment methods

Kiran Ke427b75f93a8
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-method-types.ts b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-method-types.ts
index 8cef0321b9..2eb6cd1bfc 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-method-types.ts
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-method-types.ts
@@ -38,6 +38,22 @@ export const PaymentMethodTypesList = (paymentMethod?: Stripe.PaymentMethod) =>
? `Account ending in ****${paymentMethod.us_bank_account.last4}`
: "Not connected",
},
+ {
+ type: "acss_debit",
+ title: "ACSS Debit",
+ icon: GreekTemple,
+ description: paymentMethod?.acss_debit
+ ? `Account ending in ****${paymentMethod.acss_debit.last4}`
+ : "Not connected",
+ },
+ {
+ type: "sepa_debit",
+ title: "SEPA Debit",
+ icon: GreekTemple,
+ description: paymentMethod?.sepa_debit
+ ? `Account ending in ****${paymentMethod.sepa_debit.last4}`
+ : "Not connected",
+ },
{
type: "link",
title: "Link",
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx
index b3702eea76..ae04bbee07 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx
@@ -12,18 +12,20 @@ import { useState } from "react";
import { Stripe } from "stripe";
import { PaymentMethodTypesList } from "./payment-method-types";
+const PARTNER_PAYMENT_METHODS = ["us_bank_account", "acss_debit", "sepa_debit"];
+
export default function PaymentMethods() {
const router = useRouter();
+ const { paymentMethods } = usePaymentMethods();
const [isLoading, setIsLoading] = useState(false);
const { slug, stripeId, partnersEnabled, plan } = useWorkspace();
- const { paymentMethods } = usePaymentMethods();
const regularPaymentMethods = paymentMethods?.filter(
- (pm) => pm.type !== "us_bank_account",
+ (pm) => !PARTNER_PAYMENT_METHODS.includes(pm.type),
);
- const achPaymentMethods = paymentMethods?.filter(
- (pm) => pm.type === "us_bank_account",
+ const partnerPaymentMethods = paymentMethods?.filter((pm) =>
+ PARTNER_PAYMENT_METHODS.includes(pm.type),
);
const managePaymentMethods = async () => {
@@ -86,25 +88,26 @@ export default function PaymentMethods() {
/>
)
) : (
- <>
- <PaymentMethodCardSkeleton />
- <PaymentMethodCardSkeleton />
- </>
+ <PaymentMethodCardSkeleton />
)}
{partnersEnabled && (
<>
- {achPaymentMethods && achPaymentMethods.length > 0 ? (
- achPaymentMethods.map((paymentMethod) => (
- <PaymentMethodCard
- key={paymentMethod.id}
- type={paymentMethod.type}
- paymentMethod={paymentMethod}
- forPayouts={true}
- />
- ))
+ {partnerPaymentMethods ? (
+ partnerPaymentMethods.length > 0 ? (
+ partnerPaymentMethods.map((paymentMethod) => (
+ <PaymentMethodCard
+ key={paymentMethod.id}
+ type={paymentMethod.type}
+ paymentMethod={paymentMethod}
+ forPayouts={true}
+ />
+ ))
+ ) : (
+ <NoPartnerPaymentMethods />
+ )
) : (
- <PaymentMethodCard forPayouts={true} />
+ <PaymentMethodCardSkeleton />
)}
</>
)}
@@ -132,11 +135,7 @@ const PaymentMethodCard = ({
icon: Icon,
iconBgColor,
description,
- } = result.find((method) => method.type === type) || {
- title: "Bank account",
- icon: GreekTemple,
- description: "Not connected",
- };
+ } = result.find((method) => method.type === type) || result[0];
return (
<>
@@ -156,7 +155,8 @@ const PaymentMethodCard = ({
<div className="flex items-center gap-2">
<p className="font-medium text-neutral-900">{title}</p>
{paymentMethod &&
- (type === "us_bank_account" || paymentMethod.link?.email) && (
+ (PARTNER_PAYMENT_METHODS.includes(type ?? "") ||
+ paymentMethod.link?.email) && (
<Badge className="border-transparent bg-green-200 text-[0.625rem] text-green-900">
Connected
</Badge>
@@ -180,6 +180,44 @@ const PaymentMethodCard = ({
);
};
+const NoPartnerPaymentMethods = () => {
+ const { setShowAddPayoutMethodModal, AddPayoutMethodModal } =
+ useAddPayoutMethodModal();
+
+ return (
+ <>
+ {AddPayoutMethodModal}
+ <RecommendedForPayoutsWrapper recommended={true}>
+ <div className="flex items-center justify-between rounded-lg border border-neutral-200 bg-white p-4 drop-shadow-sm">
+ <div className="flex items-center gap-4">
+ <div
+ className={cn(
+ "flex size-12 items-center justify-center rounded-lg bg-neutral-100",
+ )}
+ >
+ <GreekTemple className="size-6 text-neutral-700" />
+ </div>
+
+ <div>
+ <div className="flex items-center gap-2">
+ <p className="font-medium text-neutral-900">Bank account</p>
+ </div>
+ <p className="text-sm text-neutral-500">Not connected</p>
+ </div>
+ </div>
+
+ <Button
+ variant="primary"
+ className="h-9 w-fit"
+ text="Connect"
+ onClick={() => setShowAddPayoutMethodModal(true)}
+ />
+ </div>
+ </RecommendedForPayoutsWrapper>
+ </>
+ );
+};
+
const RecommendedForPayoutsWrapper = ({
recommended,
children,
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsx
index 1626941189..d801fdda0c 100644
--- a/apps/web/ui/partners/payout-invoice-sheet.tsx
+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx
@@ -34,6 +34,7 @@ import {
Dispatch,
Fragment,
SetStateAction,
+ useCallback,
useEffect,
useMemo,
useState,
@@ -44,57 +45,53 @@ interface PayoutInvoiceSheetProps {
setIsOpen: Dispatch<SetStateAction<boolean>>;
}
+const PAYMENT_METHODS = Object.freeze({
+ link: {
+ label: "link",
+ type: "link",
+ icon: CreditCard,
+ duration: "Instantly",
+ },
+ card: {
+ label: "card",
+ type: "card",
+ icon: CreditCard,
+ duration: "Instantly",
+ },
+ us_bank_account: {
+ label: "ACH",
+ type: "us_bank_account",
+ icon: GreekTemple,
+ duration: "4 business days",
+ },
+ acss_debit: {
+ label: "ACSS Debit",
+ type: "acss_debit",
+ icon: GreekTemple,
+ duration: "5 business days",
+ },
+ sepa_debit: {
+ label: "SEPA Debit",
+ type: "sepa_debit",
+ icon: GreekTemple,
+ duration: "5 business days",
+ },
+});
+
+type PAYMENT_METHOD = (typeof PAYMENT_METHODS)[keyof typeof PAYMENT_METHODS] & {
+ id: string;
+ fee: number;
+};
+
function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {
- const { programId } = useParams() as { programId: string };
+ const { programId } = useParams<{ programId: string }>();
const { id: workspaceId, slug, plan } = useWorkspace();
+
const { paymentMethods, loading: paymentMethodsLoading } =
usePaymentMethods();
- const paymentMethodsTypes = Object.freeze({
- link: {
- label: "link",
- type: "link",
- icon: CreditCard,
- fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].card,
- duration: "Instantly",
- },
- card: {
- label: "card",
- type: "card",
- icon: CreditCard,
- fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].card,
- duration: "Instantly",
- },
- us_bank_account: {
- label: "ACH",
- type: "us_bank_account",
- icon: GreekTemple,
- fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].ach,
- duration: "4 business days",
- },
- acss_debit: {
- label: "ACSS Debit",
- type: "acss_debit",
- icon: GreekTemple,
- fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].ach,
- duration: "4 business days",
- },
- sepa_debit: {
- label: "SEPA Debit",
- type: "sepa_debit",
- icon: GreekTemple,
- fee: PAYOUT_FEES[plan?.split(" ")[0] ?? "business"].ach,
- duration: "4 business days",
- },
- });
-
- type PaymentMethodWithFee =
- (typeof paymentMethodsTypes)[keyof typeof paymentMethodsTypes] & {
- id: string;
- };
-
const [selectedPaymentMethod, setSelectedPaymentMethod] =
- useState<PaymentMethodWithFee | null>(null);
+ useState<PAYMENT_METHOD | null>(null);
const {
payoutsCount: eligiblePayoutsCount,
@@ -137,24 +134,67 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {
if (!selectedPaymentMethod) {
const firstPaymentMethod = paymentMethods[0];
+
setSelectedPaymentMethod({
- ...paymentMethodsTypes[firstPaymentMethod.type],
+ ...PAYMENT_METHODS[firstPaymentMethod.type],
id: firstPaymentMethod.id,
});
}
}, [paymentMethods, selectedPaymentMethod]);
- const paymentMethodsWithFee = useMemo(
+ const calculateFee = useCallback(
+ (paymentMethod: PAYMENT_METHOD | null) => {
+ if (!paymentMethod) {
+ return null;
+ }
+
+ const planType = plan?.split(" ")[0] ?? "business";
+
+ if (["link", "card"].includes(paymentMethod.type)) {
+ return PAYOUT_FEES[planType].card;
+ }
+
+ if (
+ ["us_bank_account", "acss_debit", "sepa_debit"].includes(
+ paymentMethod.type,
+ )
+ ) {
+ return PAYOUT_FEES[planType].ach;
+ }
+ },
+ [plan],
+ );
+
+ const finalPaymentMethods = useMemo(
() =>
- paymentMethods?.map((pm) => ({
- ...paymentMethodsTypes[pm.type],
- id: pm.id,
- title: pm.link
- ? `Link – ${truncate(pm.link.email, 16)}`
- : pm.card
- ? `${capitalize(pm.card?.brand)} **** ${pm.card?.last4}`
- : `ACH **** ${pm.us_bank_account?.last4}`,
- })),
+ paymentMethods?.map((pm) => {
+ const paymentMethod = PAYMENT_METHODS[pm.type];
+
+ const base = {
+ ...paymentMethod,
+ id: pm.id,
+ fee: calculateFee(paymentMethod),
+ };
+
+ if (pm.link) {
+ return {
+ ...base,
+ title: `Link – ${truncate(pm.link.email, 16)}`,
+ };
+ }
+
+ if (pm.card) {
+ return {
+ ...base,
+ title: `${capitalize(pm.card.brand)} **** ${pm.card.last4}`,
+ };
+ }
+
+ return {
+ ...base,
+ title: `${paymentMethod.label} **** ${pm[paymentMethod.type]?.last4}`,
+ };
+ }),
[paymentMethods],
);
@@ -197,13 +237,12 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {
value={selectedPaymentMethod?.id || ""}
onChange={(e) =>
setSelectedPaymentMethod(
- paymentMethodsWithFee?.find(
- (pm) => pm.id === e.target.value,
- ) || null,
+ finalPaymentMethods?.find((pm) => pm.id === e.target.value) ||
+ null,
)
}
>
- {paymentMethodsWithFee?.map(({ id, title }) => (
+ {finalPaymentMethods?.map(({ id, title }) => (
<option key={id} value={id}>
{title}
</option>