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.

finalize confirmPayouts

Steven Teye144611db3a6
diff --git a/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.ts
index c1bdb26fc1..f292981f9a 100644
--- a/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.ts
@@ -160,7 +160,7 @@ export async function processPayouts({
);
}
- // Create the invoice for the payouts
+ // Update the invoice with the finalized payout amount, fee, and total
const invoice = await prisma.invoice.update({
where: {
id: invoiceId,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/success/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/success/page-client.tsx
index d3fb48b7e4..23def18283 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/success/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/success/page-client.tsx
@@ -28,7 +28,7 @@ export function PayoutsSuccessPageClient() {
}
// Convert total from cents to dollars
- const amountInDollars = currencyFormatter(invoice.total / 100);
+ const amountInDollars = currencyFormatter(invoice.amount / 100);
return (
<div className="flex flex-col items-center justify-center">
diff --git a/apps/web/lib/actions/partners/confirm-payouts.ts b/apps/web/lib/actions/partners/confirm-payouts.ts
index 29d8247801..a1363d9a87 100644
--- a/apps/web/lib/actions/partners/confirm-payouts.ts
+++ b/apps/web/lib/actions/partners/confirm-payouts.ts
@@ -15,8 +15,10 @@ const confirmPayoutsSchema = z.object({
workspaceId: z.string(),
paymentMethodId: z.string(),
cutoffPeriod: CUTOFF_PERIOD_ENUM,
- amount: z.number(),
excludedPayoutIds: z.array(z.string()).optional(),
+ amount: z.number(),
+ fee: z.number(),
+ total: z.number(),
});
// Confirm payouts
@@ -24,8 +26,14 @@ export const confirmPayoutsAction = authActionClient
.schema(confirmPayoutsSchema)
.action(async ({ parsedInput, ctx }) => {
const { workspace, user } = ctx;
- const { paymentMethodId, cutoffPeriod, amount, excludedPayoutIds } =
- parsedInput;
+ const {
+ paymentMethodId,
+ cutoffPeriod,
+ excludedPayoutIds,
+ amount,
+ fee,
+ total,
+ } = parsedInput;
if (!workspace.defaultProgramId) {
throw new Error("Workspace does not have a default program.");
@@ -79,7 +87,11 @@ export const confirmPayoutsAction = authActionClient
number: invoiceNumber,
programId: workspace.defaultProgramId!,
workspaceId: workspace.id,
- amount, // this will be updated later in the payouts/process cron job, we're adding it now for the program/payouts/success screen
+ // these numbers will be updated later in the payouts/process cron job
+ // but we're adding them now for the program/payouts/success screen
+ amount,
+ fee,
+ total,
},
});
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsx
index e0e2e437bc..0b4c622f62 100644
--- a/apps/web/ui/partners/payout-invoice-sheet.tsx
+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx
@@ -123,16 +123,19 @@ function PayoutInvoiceSheetContent() {
),
[eligiblePayouts, excludedPayoutIds],
);
- const { executeAsync, isPending } = useAction(confirmPayoutsAction, {
- onSuccess: ({ data }) => {
- router.push(
- `/${slug}/program/payouts/success?invoiceId=${data?.invoiceId}`,
- );
- },
- onError({ error }) {
- toast.error(error.serverError);
+ const { executeAsync: confirmPayouts, isPending } = useAction(
+ confirmPayoutsAction,
+ {
+ onSuccess: ({ data }) => {
+ router.push(
+ `/${slug}/program/payouts/success?invoiceId=${data?.invoiceId}`,
+ );
+ },
+ onError({ error }) {
+ toast.error(error.serverError);
+ },
},
- });
+ );
const finalPaymentMethods = useMemo(
() =>
@@ -180,15 +183,11 @@ function PayoutInvoiceSheetContent() {
}
}, [finalPaymentMethods, selectedPaymentMethod]);
- const amount = useMemo(
- () =>
- includedPayouts?.reduce((acc, payout) => {
- return acc + payout.amount;
- }, 0),
- [includedPayouts],
- );
+ const { amount, fee, total } = useMemo(() => {
+ const amount = includedPayouts?.reduce((acc, payout) => {
+ return acc + payout.amount;
+ }, 0);
- const invoiceData = useMemo(() => {
const fee =
amount === undefined
? undefined
@@ -196,6 +195,10 @@ function PayoutInvoiceSheetContent() {
const total =
amount !== undefined && fee !== undefined ? amount + fee : undefined;
+ return { amount, fee, total };
+ }, [includedPayouts, selectedPaymentMethod]);
+
+ const invoiceData = useMemo(() => {
return [
{
key: "Method",
@@ -472,12 +475,14 @@ function PayoutInvoiceSheetContent() {
return;
}
- await executeAsync({
+ await confirmPayouts({
workspaceId,
paymentMethodId: selectedPaymentMethod.id,
cutoffPeriod,
- amount: amount ?? 0,
excludedPayoutIds,
+ amount: amount ?? 0,
+ fee: fee ?? 0,
+ total: total ?? 0,
});
}}
text={