The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Make sure partners that don’t have `payoutsEnabled` don’t get added tot be `payout-invoice-sheet`.
Kiran Kd73b7dab5568
diff --git a/apps/web/app/api/cron/invoices/utils.ts b/apps/web/app/api/cron/invoices/utils.tsindex d6e09d78eb..8145adc96b 100644--- a/apps/web/app/api/cron/invoices/utils.ts+++ b/apps/web/app/api/cron/invoices/utils.ts@@ -38,6 +38,12 @@ export const processInvoice = async ({ invoiceId }: { invoiceId: string }) => {where: {invoiceId,status: "pending",+ partner: {+ payoutsEnabled: true,+ stripeConnectId: {+ not: null,+ },+ },},select: {id: true,@@ -83,17 +89,10 @@ export const processInvoice = async ({ invoiceId }: { invoiceId: string }) => {// Create transfers for each partners// TODO (Kiran): Need to optimize this when we have large number of payouts for an invoice.for (const payout of payouts) {- if (!payout.partner.stripeConnectId) {- console.warn(- `Partner ${payout.partner.id} does not have a Stripe Connect ID. Skipping payout...`,- );- continue;- }-const transfer = await stripe.transfers.create({amount: payout.amount,currency: "usd",- destination: payout.partner.stripeConnectId,+ destination: payout.partner.stripeConnectId!,source_transaction: latest_charge as string,transfer_group: invoiceId,description: "Stripe Payout",diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.tsindex ad85174e63..6dca23c2ac 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts@@ -65,6 +65,9 @@ const payoutInvoices = async (workspaceId: string) => {total: true,createdAt: true,},+ orderBy: {+ createdAt: "desc",+ },});return invoices.map((invoice) => {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.tsxindex 1713490f77..ef32137f72 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@@ -69,7 +69,7 @@ export function PayoutStats() {<div className="text-sm text-neutral-500">Total paid</div></div><Link- href={`/${slug}/settings/billing/invoices`}+ href={`/${slug}/settings/billing/invoices?type=payout`}className={cn(buttonVariants({ variant: "secondary" }),"flex h-7 items-center rounded-md border px-2 text-sm",diff --git a/apps/web/lib/actions/partners/confirm-payouts.ts b/apps/web/lib/actions/partners/confirm-payouts.tsindex df2eeab6eb..65b8b9a45f 100644--- a/apps/web/lib/actions/partners/confirm-payouts.ts+++ b/apps/web/lib/actions/partners/confirm-payouts.ts@@ -51,6 +51,12 @@ export const confirmPayoutsAction = authActionClientprogramId,status: "pending",invoiceId: null, // just to be extra safe+ partner: {+ stripeConnectId: {+ not: null,+ },+ payoutsEnabled: true,+ },},select: {id: true,diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsxindex a31e43f84c..69fa0236fb 100644--- a/apps/web/ui/partners/payout-invoice-sheet.tsx+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx@@ -33,7 +33,6 @@ interface PayoutInvoiceSheetProps {// TODO:// Fix the fee calculation-// Fix the table menus + View all// Payment method dropdown UI need fixingfunction PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {@@ -72,9 +71,15 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {},});+ // Filter out partners that don’t have `payoutsEnabled`+ const pendingPayouts = useMemo(+ () => payouts?.filter((payout) => payout.partner.payoutsEnabled),+ [payouts],+ );+const invoiceData = useMemo(() => {const amount =- payouts?.reduce((acc, payout) => acc + payout.amount, 0) || 0;+ pendingPayouts?.reduce((acc, payout) => acc + payout.amount, 0) || 0;const fee = amount * 0.02;const total = amount + fee;@@ -127,10 +132,10 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {maximumFractionDigits: 2,}),};- }, [payouts, paymentMethods, paymentMethodsLoading]);+ }, [pendingPayouts, paymentMethods, paymentMethodsLoading]);const table = useTable({- data: payouts || [],+ data: pendingPayouts || [],columns: [{header: "Partner",@@ -165,7 +170,7 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {tdClassName: (id) => cn(id === "total" && "text-right", "border-l-0"),className: "[&_tr:last-child>td]:border-b-transparent",scrollWrapperClassName: "min-h-[40px]",- resourceName: (p) => `partner${p ? "s" : ""}`,+ resourceName: (p) => `pending payout${p ? "s" : ""}`,loading: payoutsLoading,error: payoutsError? "Failed to load payouts for this invoice."@@ -205,17 +210,6 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {<div className="p-6 pt-2"><Table {...table} />- <div className="mt-2 flex justify-end">- <Link- href="/"- className={cn(- buttonVariants({ variant: "secondary" }),- "flex h-7 items-center rounded-lg border px-2 text-sm",- )}- >- View all- </Link>- </div></div></div><div className="flex grow flex-col justify-end">@@ -249,6 +243,7 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {}}text="Confirm payout"className="w-fit"+ disabled={pendingPayouts?.length === 0}/></div></div>