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.

fix final bugs

Steven Tey205628c3b8be
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 afe9a64331..d32391f3f0 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
@@ -12,7 +12,7 @@ import { prisma } from "@dub/prisma";
import { Program, ProgramPayoutMode, Project } from "@dub/prisma/client";
import { APP_DOMAIN_WITH_NGROK, currencyFormatter, log } from "@dub/utils";
-const paymentMethodToCurrency = {
+const nonUsdPaymentMethodTypes = {
sepa_debit: "eur",
acss_debit: "cad",
} as const;
@@ -91,13 +91,15 @@ export async function processPayouts({
userId,
initiatedAt: new Date(),
// if the program is in external mode, set the mode to external
- // otherwise set it to internal (we'll update to "external" later if it's hybrid mode)
+ // otherwise set it to internal (we'll update specific payouts to "external" later if it's hybrid mode)
mode: program.payoutMode === "external" ? "external" : "internal",
},
});
if (res.count === 0) {
- console.log(`No payouts found for invoice ${invoiceId}. Skipping...`);
+ console.log(
+ `No payouts updated/found for invoice ${invoiceId}. Skipping...`,
+ );
return;
}
@@ -154,7 +156,6 @@ export async function processPayouts({
const fastAchFee =
invoice.paymentMethod === "ach_fast" ? FAST_ACH_FEE_CENTS : 0;
- const currency = paymentMethodToCurrency[paymentMethod.type] || "usd";
const invoiceFee = Math.round(totalPayoutAmount * payoutFee) + fastAchFee;
const invoiceTotal = totalPayoutAmount + invoiceFee;
@@ -171,9 +172,10 @@ export async function processPayouts({
});
let totalToCharge = invoiceTotal - totalExternalPayoutAmount;
+ const currency = nonUsdPaymentMethodTypes[paymentMethod.type] || "usd";
// convert the amount to EUR/CAD if the payment method is sepa_debit or acss_debit
- if (["sepa_debit", "acss_debit"].includes(paymentMethod.type)) {
+ if (Object.keys(nonUsdPaymentMethodTypes).includes(paymentMethod.type)) {
const fxQuote = await createFxQuote({
fromCurrency: currency,
toCurrency: "usd",
diff --git a/apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts b/apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts
index 82ae87de51..5109a145d2 100644
--- a/apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts
@@ -3,6 +3,7 @@ import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
import { sendBatchEmail } from "@dub/email";
+import PartnerPayoutConfirmed from "@dub/email/templates/partner-payout-confirmed";
import { prisma } from "@dub/prisma";
import { APP_DOMAIN_WITH_NGROK, currencyFormatter, log } from "@dub/utils";
import { z } from "zod";
@@ -48,6 +49,9 @@ export async function POST(req: Request) {
id: startingAfter,
},
}),
+ orderBy: {
+ id: "asc",
+ },
});
if (payouts.length === 0) {
@@ -92,8 +96,7 @@ export async function POST(req: Request) {
subject: `Your ${currencyFormatter(payout.amount)} payout for ${payout.program.name} is on the way`,
variant: "notifications",
replyTo: payout.program.supportEmail || "noreply",
- templateName: "PartnerPayoutConfirmed",
- templateProps: {
+ react: PartnerPayoutConfirmed({
email: payout.partner.email!,
program: {
id: payout.program.id,
@@ -106,9 +109,9 @@ export async function POST(req: Request) {
startDate: payout.periodStart,
endDate: payout.periodEnd,
mode: payout.mode,
- paymentMethod: payout.invoice?.paymentMethod ?? "ach",
+ paymentMethod: invoice.paymentMethod ?? "ach",
},
- },
+ }),
})),
);
console.log({ batchEmailResponse });