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.

Add payment method display to invoices and centralize config

Kiran K49f42cc06278
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
index ebbbac8612..a8634965ba 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
@@ -70,6 +70,7 @@ const otherInvoices = async ({
total: true,
createdAt: true,
status: true,
+ paymentMethod: true,
failedReason: true,
},
orderBy: {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx
index f521a5f76d..f7f6d8ee97 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx
@@ -1,9 +1,11 @@
"use client";
+import { PAYMENT_METHODS } from "@/lib/payment-methods";
import useWorkspace from "@/lib/swr/use-workspace";
import { InvoiceProps } from "@/lib/types";
import { PayoutStatusBadges } from "@/ui/partners/payout-status-badges";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { PaymentMethod } from "@dub/prisma/client";
import {
Button,
buttonVariants,
@@ -42,6 +44,8 @@ export default function WorkspaceInvoicesClient() {
fetcher,
);
+ const displayPaymentMethod = selectedInvoiceType.id === "partnerPayout";
+
return (
<div className="rounded-lg border border-neutral-200 bg-white">
<div className="flex flex-col items-start justify-between gap-y-4 p-6 md:p-8 md:pb-2 lg:flex-row">
@@ -68,7 +72,11 @@ export default function WorkspaceInvoicesClient() {
{invoices ? (
invoices.length > 0 ? (
invoices.map((invoice) => (
- <InvoiceCard key={invoice.id} invoice={invoice} />
+ <InvoiceCard
+ key={invoice.id}
+ invoice={invoice}
+ displayPaymentMethod={displayPaymentMethod}
+ />
))
) : (
<AnimatedEmptyState
@@ -85,9 +93,9 @@ export default function WorkspaceInvoicesClient() {
)
) : (
<>
- <InvoiceCardSkeleton />
- <InvoiceCardSkeleton />
- <InvoiceCardSkeleton />
+ <InvoiceCardSkeleton displayPaymentMethod={displayPaymentMethod} />
+ <InvoiceCardSkeleton displayPaymentMethod={displayPaymentMethod} />
+ <InvoiceCardSkeleton displayPaymentMethod={displayPaymentMethod} />
</>
)}
</div>
@@ -95,9 +103,22 @@ export default function WorkspaceInvoicesClient() {
);
}
-const InvoiceCard = ({ invoice }: { invoice: InvoiceProps }) => {
+const InvoiceCard = ({
+ invoice,
+ displayPaymentMethod = false,
+}: {
+ invoice: InvoiceProps;
+ displayPaymentMethod: boolean;
+}) => {
+ const paymentMethod = getPaymentMethodDisplay(invoice.paymentMethod ?? "ach");
+
return (
- <div className="grid grid-cols-3 gap-4 px-6 py-4 sm:px-12">
+ <div
+ className={cn(
+ "grid gap-4 px-6 py-4 sm:px-12",
+ displayPaymentMethod ? "grid-cols-4" : "grid-cols-3",
+ )}
+ >
<div className="text-sm">
<div className="font-medium">{invoice.description}</div>
<div className="text-neutral-500">
@@ -122,7 +143,7 @@ const InvoiceCard = ({ invoice }: { invoice: InvoiceProps }) => {
<StatusBadge
icon={null}
variant={badge.variant}
- className="rounded-full py-0.5"
+ className="rounded-md py-0.5"
>
{badge.label}
</StatusBadge>
@@ -131,6 +152,28 @@ const InvoiceCard = ({ invoice }: { invoice: InvoiceProps }) => {
</div>
</div>
+ {displayPaymentMethod && (
+ <div className="text-left text-sm">
+ <div className="font-medium">Method</div>
+ {paymentMethod ? (
+ <div className="flex items-center gap-1.5 text-neutral-500">
+ <div className="text-content-subtle text-sm font-medium">
+ {paymentMethod.label}
+ </div>
+ <StatusBadge
+ icon={null}
+ variant="neutral"
+ className="rounded-md py-0.5 text-xs font-semibold text-neutral-700"
+ >
+ {paymentMethod.duration}
+ </StatusBadge>
+ </div>
+ ) : (
+ "-"
+ )}
+ </div>
+ )}
+
<div className="flex items-center justify-end">
{invoice.pdfUrl ? (
<a
@@ -161,9 +204,18 @@ const InvoiceCard = ({ invoice }: { invoice: InvoiceProps }) => {
);
};
-const InvoiceCardSkeleton = () => {
+const InvoiceCardSkeleton = ({
+ displayPaymentMethod = false,
+}: {
+ displayPaymentMethod?: boolean;
+}) => {
return (
- <div className="flex items-center justify-between px-6 py-4 sm:px-12">
+ <div
+ className={cn(
+ "grid gap-4 px-6 py-4 sm:px-12",
+ displayPaymentMethod ? "grid-cols-4" : "grid-cols-3",
+ )}
+ >
<div className="flex flex-col gap-1 text-sm">
<div className="h-4 w-32 animate-pulse rounded-md bg-neutral-200" />
<div className="h-4 w-24 animate-pulse rounded-md bg-neutral-200" />
@@ -172,7 +224,38 @@ const InvoiceCardSkeleton = () => {
<div className="h-4 w-16 animate-pulse rounded-md bg-neutral-200" />
<div className="h-4 w-20 animate-pulse rounded-md bg-neutral-200" />
</div>
- <div className="h-8 w-16 animate-pulse rounded-md bg-neutral-200" />
+
+ {displayPaymentMethod && (
+ <div className="flex flex-col gap-1">
+ <div className="h-4 w-12 animate-pulse rounded-md bg-neutral-200" />
+ <div className="h-4 w-20 animate-pulse rounded-md bg-neutral-200" />
+ </div>
+ )}
+
+ <div className="flex items-center justify-end">
+ <div className="h-8 w-16 animate-pulse rounded-md bg-neutral-200" />
+ </div>
</div>
);
};
+
+function getPaymentMethodDisplay(paymentMethod: PaymentMethod) {
+ switch (paymentMethod) {
+ case "ach":
+ return PAYMENT_METHODS["us_bank_account"];
+ case "ach_fast":
+ return {
+ ...PAYMENT_METHODS["us_bank_account"],
+ label: "FAST ACH",
+ duration: "2 business days",
+ };
+ case "card":
+ return PAYMENT_METHODS["card"];
+ case "sepa":
+ return PAYMENT_METHODS["sepa_debit"];
+ case "acss":
+ return PAYMENT_METHODS["acss_debit"];
+ default:
+ return null;
+ }
+}
diff --git a/apps/web/lib/payment-methods.ts b/apps/web/lib/payment-methods.ts
index 40f868325f..9249c9c29a 100644
--- a/apps/web/lib/payment-methods.ts
+++ b/apps/web/lib/payment-methods.ts
@@ -1,3 +1,4 @@
+import { CreditCard, GreekTemple } from "@dub/ui";
import Stripe from "stripe";
import { DIRECT_DEBIT_PAYMENT_METHOD_TYPES } from "./partners/constants";
@@ -22,3 +23,36 @@ export const calculatePayoutFeeForMethod = ({
throw new Error(`Unsupported payment method ${paymentMethod}.`);
};
+
+export 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",
+ },
+});
diff --git a/apps/web/lib/zod/schemas/invoices.ts b/apps/web/lib/zod/schemas/invoices.ts
index 91e8f63474..f9f8adb8df 100644
--- a/apps/web/lib/zod/schemas/invoices.ts
+++ b/apps/web/lib/zod/schemas/invoices.ts
@@ -1,10 +1,11 @@
import z from "@/lib/zod";
-import { InvoiceStatus } from "@dub/prisma/client";
+import { InvoiceStatus, PaymentMethod } from "@dub/prisma/client";
export const InvoiceSchema = z.object({
id: z.string(),
total: z.number(),
status: z.nativeEnum(InvoiceStatus).optional(),
+ paymentMethod: z.nativeEnum(PaymentMethod).nullable().optional(),
createdAt: z.date(),
description: z.string().default("Dub payout"),
pdfUrl: z.string().nullable(),
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsx
index 01e7b08b1d..49234e6118 100644
--- a/apps/web/ui/partners/payout-invoice-sheet.tsx
+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx
@@ -6,7 +6,10 @@ import {
CUTOFF_PERIOD,
CUTOFF_PERIOD_TYPES,
} from "@/lib/partners/cutoff-period";
-import { calculatePayoutFeeForMethod } from "@/lib/payment-methods";
+import {
+ calculatePayoutFeeForMethod,
+ PAYMENT_METHODS,
+} from "@/lib/payment-methods";
import usePaymentMethods from "@/lib/swr/use-payment-methods";
import useWorkspace from "@/lib/swr/use-workspace";
import { PayoutResponse, PlanProps } from "@/lib/types";
@@ -15,7 +18,6 @@ import {
Bolt,
Button,
buttonVariants,
- CreditCard,
DynamicTooltipWrapper,
Gear,
GreekTemple,
@@ -44,39 +46,6 @@ import { toast } from "sonner";
import Stripe from "stripe";
import useSWR from "swr";
-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 SelectPaymentMethod =
(typeof PAYMENT_METHODS)[keyof typeof PAYMENT_METHODS] & {
id: string;
@@ -488,7 +457,7 @@ function PayoutInvoiceSheetContent() {
const result = await confirmPayouts({
workspaceId,
- paymentMethodId: selectedPaymentMethod.id,
+ paymentMethodId: selectedPaymentMethod.id.replace("-fast", ""),
cutoffPeriod,
excludedPayoutIds,
amount: amount ?? 0,