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.

partner when a program owner sends them a payout transfer

Kiran Kaab43df01c8a
diff --git a/apps/web/emails/new-sale-created.tsx b/apps/web/emails/new-sale-created.tsx
index 4ccaac2095..f75d781efb 100644
--- a/apps/web/emails/new-sale-created.tsx
+++ b/apps/web/emails/new-sale-created.tsx
@@ -1,4 +1,4 @@
-import { DUB_WORDMARK, getPrettyUrl } from "@dub/utils";
+import { currencyFormatter, DUB_WORDMARK, getPrettyUrl } from "@dub/utils";
import {
Body,
Container,
@@ -45,15 +45,23 @@ export default function NewSaleCreated({
earnings: number;
};
}) {
- const earningsInDollars = Math.round(sale.earnings / 100).toLocaleString();
- const saleAmountInDollars = Math.round(sale.amount / 100).toLocaleString();
const linkToSale = `https://partners.dub.co/${partner.id}/${program.id}/sales`;
+ const earningsInDollars = currencyFormatter(sale.earnings / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ });
+
+ const saleAmountInDollars = currencyFormatter(sale.amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ });
+
return (
<Html>
<Head />
<Preview>
- You just made a ${earningsInDollars} sale via your referral link{" "}
+ You just made a {earningsInDollars} sale via your referral link{" "}
{getPrettyUrl(partner.referralLink)}
</Preview>
<Tailwind>
@@ -68,11 +76,11 @@ export default function NewSaleCreated({
/>
</Section>
<Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">
- You just made a ${earningsInDollars} referral sale!
+ You just made a {earningsInDollars} referral sale!
</Heading>
<Text className="text-sm leading-6 text-black">
Congratulations! Someone made a{" "}
- <strong>${saleAmountInDollars}</strong> purchase on{" "}
+ <strong>{saleAmountInDollars}</strong> purchase on{" "}
<strong>{program.name}</strong> using your referral link (
<a
href={partner.referralLink}
@@ -83,7 +91,7 @@ export default function NewSaleCreated({
).
</Text>
<Text className="text-sm leading-6 text-black">
- Your received <strong>${earningsInDollars}</strong> in commission
+ Your received <strong>{earningsInDollars}</strong> in commission
for this sale and it will be included in your next payout.
</Text>
<Text className="text-sm leading-6 text-black"></Text>
diff --git a/apps/web/emails/partner-payout-sent.tsx b/apps/web/emails/partner-payout-sent.tsx
index e69de29bb2..898184c6f9 100644
--- a/apps/web/emails/partner-payout-sent.tsx
+++ b/apps/web/emails/partner-payout-sent.tsx
@@ -0,0 +1,89 @@
+import { currencyFormatter, DUB_WORDMARK } from "@dub/utils";
+import {
+ Body,
+ Container,
+ Head,
+ Heading,
+ Html,
+ Img,
+ Link,
+ Preview,
+ Section,
+ Tailwind,
+ Text,
+} from "@react-email/components";
+import Footer from "./components/footer";
+
+export default function PartnerPayoutSent({
+ email = "[email protected]",
+ program = {
+ id: "prog_d8pl69xXCv4AoHNT281pHQdo",
+ name: "Acme",
+ logo: DUB_WORDMARK,
+ },
+ payout = {
+ amount: 490,
+ startDate: "2024-01-01",
+ endDate: "2024-01-31",
+ },
+}: {
+ email: string;
+ program: {
+ id: string;
+ name: string;
+ logo: string | null;
+ };
+ payout: {
+ amount: number;
+ startDate: string;
+ endDate: string;
+ };
+}) {
+ const linkToPayout = `https://partners.dub.co/${program.id}/payouts`;
+
+ const saleAmountInDollars = currencyFormatter(payout.amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ });
+
+ return (
+ <Html>
+ <Head />
+ <Preview>You've been paid!</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img
+ src={program.logo || DUB_WORDMARK}
+ height="40"
+ alt={program.name}
+ className="mx-auto my-0"
+ />
+ </Section>
+ <Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">
+ You've been paid!
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ <strong>{program.name}</strong> has sent you{" "}
+ <strong>{saleAmountInDollars}</strong> for affiliate sales made
+ from <strong>{payout.startDate}</strong> to{" "}
+ <strong>{payout.endDate}</strong>. Your wallet has been updated to
+ reflect this payout.
+ </Text>
+ <Text className="text-sm leading-6 text-black"></Text>
+ <Section className="my-8 text-center">
+ <Link
+ className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
+ href={linkToPayout}
+ >
+ View payout
+ </Link>
+ </Section>
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}
diff --git a/apps/web/lib/actions/partners/create-dots-transfer.ts b/apps/web/lib/actions/partners/create-dots-transfer.ts
index e414dba98a..94a59515db 100644
--- a/apps/web/lib/actions/partners/create-dots-transfer.ts
+++ b/apps/web/lib/actions/partners/create-dots-transfer.ts
@@ -1,6 +1,9 @@
"use server";
import { prisma } from "@/lib/prisma";
+import { waitUntil } from "@vercel/functions";
+import { sendEmail } from "emails";
+import PartnerPayoutSent from "emails/partner-payout-sent";
import { z } from "zod";
import { createOrgTransfer } from "../../dots/create-org-transfer";
import { createTransfer } from "../../dots/create-transfer";
@@ -32,7 +35,10 @@ export const createDotsTransferAction = authActionClient
programId: payout.programId,
},
},
- select: { dotsUserId: true },
+ select: {
+ dotsUserId: true,
+ program: true,
+ },
});
if (!programEnrollment.dotsUserId) {
@@ -56,11 +62,45 @@ export const createDotsTransferAction = authActionClient
where: { id: payoutId },
data: { dotsTransferId: transfer.id, status: "completed" },
}),
+
prisma.sale.updateMany({
where: { payoutId },
data: { status: "paid" },
}),
]);
+ waitUntil(
+ (async () => {
+ const { program } = programEnrollment;
+
+ const { user } = await prisma.partnerUser.findFirstOrThrow({
+ where: {
+ partnerId: payout.partnerId,
+ },
+ include: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ });
+
+ sendEmail({
+ subject: "You've been paid!",
+ email: user.email!,
+ react: PartnerPayoutSent({
+ email: user.email!,
+ program,
+ payout: {
+ amount: payout.amount,
+ startDate: payout.periodStart.toISOString(),
+ endDate: payout.periodEnd.toISOString(),
+ },
+ }),
+ });
+ })(),
+ );
+
return { transfer, orgTransfer };
});