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 partnersEnabled, check for confirm payouts

Steven Tey1f558326ac77
diff --git a/apps/web/app/api/stripe/integration/webhook/route.ts b/apps/web/app/api/stripe/integration/webhook/route.ts
index 3b64ab2a74..54f83a65c9 100644
--- a/apps/web/app/api/stripe/integration/webhook/route.ts
+++ b/apps/web/app/api/stripe/integration/webhook/route.ts
@@ -13,7 +13,7 @@ const relevantEvents = new Set([
"account.application.deauthorized",
]);
-// POST /api/stripe/integration/webhook – listen to Stripe webhooks
+// POST /api/stripe/integration/webhook – listen to Stripe webhooks (for Stripe Integration)
export const POST = withAxiom(
async (req: Request) => {
const buf = await req.text();
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 3b86bd1cbf..014fe0f9ac 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
@@ -5,10 +5,6 @@ import { APP_DOMAIN } from "@dub/utils";
import { NextResponse } from "next/server";
import { z } from "zod";
-const addPaymentMethodSchema = z.object({
- method: z.enum(["card", "us_bank_account"]),
-});
-
export const GET = withWorkspace(async ({ workspace }) => {
if (!workspace.stripeId) {
return NextResponse.json([]);
@@ -26,6 +22,10 @@ export const GET = withWorkspace(async ({ workspace }) => {
}
});
+const addPaymentMethodSchema = z.object({
+ method: z.enum(["card", "us_bank_account"]).optional(),
+});
+
export const POST = withWorkspace(async ({ workspace, req }) => {
if (!workspace.stripeId) {
return NextResponse.json({ error: "Workspace does not have a Stripe ID" });
@@ -33,6 +33,18 @@ export const POST = withWorkspace(async ({ workspace, req }) => {
const { method } = addPaymentMethodSchema.parse(await parseRequestBody(req));
+ if (!method) {
+ const { url } = await stripe.billingPortal.sessions.create({
+ customer: workspace.stripeId,
+ return_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing`,
+ flow_data: {
+ type: "payment_method_update",
+ },
+ });
+
+ return NextResponse.json({ url });
+ }
+
const { url } = await stripe.checkout.sessions.create({
mode: "setup",
customer: workspace.stripeId,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx
index 75f601a815..d340ad2479 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx
@@ -5,12 +5,12 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { PayoutsCount } from "@/lib/types";
import { usePayoutInvoiceSheet } from "@/ui/partners/payout-invoice-sheet";
import { PayoutStatus } from "@dub/prisma/client";
-import { Button, buttonVariants, Tooltip } from "@dub/ui";
+import { Button, buttonVariants, Tooltip, TooltipContent } from "@dub/ui";
import { cn, currencyFormatter } from "@dub/utils";
import Link from "next/link";
export function PayoutStats() {
- const { slug } = useWorkspace();
+ const { slug, payoutMethodId } = useWorkspace();
const { payoutInvoiceSheet, setIsOpen } = usePayoutInvoiceSheet();
const { payoutsCount, loading } = usePayoutsCount<PayoutsCount[]>({
@@ -59,9 +59,15 @@ export function PayoutStats() {
onClick={() => setIsOpen(true)}
disabled={confirmButtonDisabled}
disabledTooltip={
- confirmButtonDisabled
- ? "You have no pending payouts that match the minimum payout requirement for partners that have payouts enabled."
- : undefined
+ confirmButtonDisabled ? (
+ "You have no pending payouts that match the minimum payout requirement for partners that have payouts enabled."
+ ) : !payoutMethodId ? (
+ <TooltipContent
+ title="You must have a valid ACH bank account payment method to send payouts."
+ cta="Add payment method"
+ href={`/${slug}/settings/billing`}
+ />
+ ) : undefined
}
/>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx
index 46c3b4323b..adab48a825 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx
@@ -58,7 +58,12 @@ export function PayoutTable() {
error,
isLoading,
} = useSWR<PayoutResponse[]>(
- `/api/programs/${programId}/payouts${getQueryString({ workspaceId })}`,
+ `/api/programs/${programId}/payouts${getQueryString(
+ { workspaceId },
+ {
+ ignore: ["payoutId"],
+ },
+ )}`,
fetcher,
{
keepPreviousData: true,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/payment-methods.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/payment-methods.tsx
index 9371c936c2..63a252061e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/payment-methods.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/payment-methods.tsx
@@ -2,40 +2,62 @@
import usePaymentMethods from "@/lib/swr/use-payment-methods";
import useWorkspace from "@/lib/swr/use-workspace";
-import { Button } from "@dub/ui";
+import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import ManageSubscriptionButton from "@/ui/workspaces/manage-subscription-button";
+import { Badge, Button, CreditCard } from "@dub/ui";
import { cn } from "@dub/utils";
import { useState } from "react";
import { Stripe } from "stripe";
import { PaymentMethodTypesList } from "./payment-method-types";
export default function PaymentMethods() {
- const { paymentMethods, loading } = usePaymentMethods();
+ const { stripeId, partnersEnabled } = useWorkspace();
+ const { paymentMethods } = usePaymentMethods();
+
+ const regularPaymentMethods = paymentMethods?.filter(
+ (pm) => pm.type !== "us_bank_account",
+ );
+
+ const achPaymentMethods = paymentMethods?.filter(
+ (pm) => pm.type === "us_bank_account",
+ );
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 xl:flex-row">
+ <div className="flex flex-col items-center justify-between gap-y-4 p-6 md:p-8 xl:flex-row">
<div>
<h2 className="text-xl font-medium">Payment methods</h2>
<p className="text-balance text-sm leading-normal text-neutral-500">
Manage your payment methods on Dub
</p>
</div>
+ {stripeId && (
+ <ManageSubscriptionButton text="Manage" className="w-fit" />
+ )}
</div>
<div className="grid gap-4 border-t border-neutral-200 p-6">
- {!loading ? (
- ["card", "us_bank_account"].map((methodType) => {
- const paymentMethod = paymentMethods?.find(
- (pm) => pm.type === methodType,
- );
-
- return (
+ {regularPaymentMethods ? (
+ regularPaymentMethods.length > 0 ? (
+ regularPaymentMethods.map((paymentMethod) => (
<PaymentMethodCard
- key={methodType}
- type={methodType as Stripe.PaymentMethod.Type}
+ key={paymentMethod.id}
+ type={paymentMethod.type}
paymentMethod={paymentMethod}
/>
- );
- })
+ ))
+ ) : (
+ <AnimatedEmptyState
+ title="No payment methods found"
+ description="You haven't added any payment methods yet"
+ cardContent={() => (
+ <>
+ <CreditCard className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
+ )}
+ className="border-none md:min-h-[250px]"
+ />
+ )
) : (
<>
<PaymentMethodCardSkeleton />
@@ -43,6 +65,21 @@ export default function PaymentMethods() {
</>
)}
</div>
+ {partnersEnabled && achPaymentMethods && (
+ <div className="grid gap-4 border-t border-neutral-200 p-6">
+ {achPaymentMethods.length > 0 ? (
+ achPaymentMethods.map((paymentMethod) => (
+ <PaymentMethodCard
+ key={paymentMethod.id}
+ type={paymentMethod.type}
+ paymentMethod={paymentMethod}
+ />
+ ))
+ ) : (
+ <PaymentMethodCard type="us_bank_account" />
+ )}
+ </div>
+ )}
</div>
);
}
@@ -92,17 +129,26 @@ const PaymentMethodCard = ({
<Icon className="size-6 text-neutral-700" />
</div>
<div>
- <p className="font-medium text-neutral-900">{title}</p>
+ <div className="flex items-center gap-2">
+ <p className="font-medium text-neutral-900">{title}</p>
+ {type === "us_bank_account" && (
+ <Badge variant="neutral">
+ Recommended for Dub Partners payouts
+ </Badge>
+ )}
+ </div>
<p className="text-sm text-neutral-500">{description}</p>
</div>
</div>
- <Button
- variant={paymentMethod ? "secondary" : "primary"}
- className="h-8 w-fit"
- text={paymentMethod ? "Manage" : "Connect"}
- onClick={() => managePaymentMethods(type)}
- loading={isLoading}
- />
+ {!paymentMethod && (
+ <Button
+ variant="primary"
+ className="h-8 w-fit"
+ text="Connect"
+ onClick={() => managePaymentMethods(type)}
+ loading={isLoading}
+ />
+ )}
</div>
);
};
diff --git a/apps/web/lib/swr/use-payouts-count.ts b/apps/web/lib/swr/use-payouts-count.ts
index c022f9c4bb..4104689877 100644
--- a/apps/web/lib/swr/use-payouts-count.ts
+++ b/apps/web/lib/swr/use-payouts-count.ts
@@ -16,10 +16,15 @@ export default function usePayoutsCount<T>(
const { data: payoutsCount, error } = useSWR<PayoutsCount[]>(
workspaceId &&
- `/api/programs/${programId}/payouts/count${getQueryString({
- ...opts,
- workspaceId,
- })}`,
+ `/api/programs/${programId}/payouts/count${getQueryString(
+ {
+ ...opts,
+ workspaceId,
+ },
+ {
+ ignore: ["payoutId"],
+ },
+ )}`,
fetcher,
);
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index 632daf7299..105dbaa674 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -81,6 +81,9 @@ export const WorkspaceSchema = z
.describe(
"Whether the workspace has claimed a free .link domain. (dub.link/free)",
),
+ partnersEnabled: z
+ .boolean()
+ .describe("Whether the workspace has Dub Partners enabled."),
createdAt: z
.date()
diff --git a/packages/prisma/schema/workspace.prisma b/packages/prisma/schema/workspace.prisma
index 50be1fe843..aee61776cb 100644
--- a/packages/prisma/schema/workspace.prisma
+++ b/packages/prisma/schema/workspace.prisma
@@ -29,6 +29,7 @@ model Project {
webhookEnabled Boolean @default(false)
conversionEnabled Boolean @default(false)
+ partnersEnabled Boolean @default(false)
ssoEnabled Boolean @default(false)
dotLinkClaimed Boolean @default(false)