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.

Merge branch 'main' into bank-debits

Steven Teya5e4d85e92f5
diff --cc apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
index 5ab9cb8851,b382310f22..d065ab99b6
--- a/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
@@@ -1,20 -1,19 +1,21 @@@
import { createId } from "@/lib/api/create-id";
- import { limiter } from "@/lib/cron/limiter";
-import { PAYOUT_FEES } from "@/lib/partners/constants";
+import {
+ DIRECT_DEBIT_PAYMENT_METHOD_TYPES,
+ PAYMENT_METHOD_TYPES,
+} from "@/lib/partners/constants";
import {
CUTOFF_PERIOD,
CUTOFF_PERIOD_TYPES,
} from "@/lib/partners/cutoff-period";
+import { calculatePayoutFee } from "@/lib/payment-methods";
import { stripe } from "@/lib/stripe";
- import { sendEmail } from "@dub/email";
+ import { resend } from "@dub/email/resend";
+ import { VARIANT_TO_FROM_MAP } from "@dub/email/resend/constants";
import PartnerPayoutConfirmed from "@dub/email/templates/partner-payout-confirmed";
import { prisma } from "@dub/prisma";
+ import { chunk, log } from "@dub/utils";
import { Program, Project } from "@prisma/client";
-const allowedPaymentMethods = ["us_bank_account", "card", "link"];
-
export async function confirmPayouts({
workspace,
program,
@@@ -156,34 -154,41 +157,44 @@@
return invoice;
});
- // Send emails to all the partners involved in the payouts if the payout method is ACH
- // This is because ACH takes 4 business days to process, so we want to give partners a heads up
- if (newInvoice && paymentMethod.type === "us_bank_account") {
+ // Send emails to all the partners involved in the payouts if the payout method is Direct Debit
+ // This is because Direct Debit takes 4 business days to process, so we want to give partners a heads up
+ if (
+ newInvoice &&
+ DIRECT_DEBIT_PAYMENT_METHOD_TYPES.includes(paymentMethod.type)
+ ) {
- await Promise.allSettled(
- payouts
- .filter((payout) => payout.partner.email)
- .map((payout) =>
- limiter.schedule(() =>
- sendEmail({
- subject: "You've got money coming your way!",
- email: payout.partner.email!,
- react: PartnerPayoutConfirmed({
- email: payout.partner.email!,
- program,
- payout: {
- id: payout.id,
- amount: payout.amount,
- startDate: payout.periodStart,
- endDate: payout.periodEnd,
- },
- }),
- variant: "notifications",
- }),
- ),
- ),
+ if (!resend) {
+ // this should never happen, but just in case
+ await log({
+ message: "Resend is not configured, skipping email sending.",
+ type: "errors",
+ });
+ console.log("Resend is not configured, skipping email sending.");
+ return;
+ }
+
+ const payoutChunks = chunk(
+ payouts.filter((payout) => payout.partner.email),
+ 100,
);
+ for (const payoutChunk of payoutChunks) {
+ await resend.batch.send(
+ payoutChunk.map((payout) => ({
+ from: VARIANT_TO_FROM_MAP.notifications,
+ to: payout.partner.email!,
+ subject: "You've got money coming your way!",
+ react: PartnerPayoutConfirmed({
+ email: payout.partner.email!,
+ program,
+ payout: {
+ id: payout.id,
+ amount: payout.amount,
+ startDate: payout.periodStart,
+ endDate: payout.periodEnd,
+ },
+ }),
+ })),
+ );
+ }
}
}