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.

Improve payout emails

Steven Tey6d8e25091d4e
diff --git a/apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts b/apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts
index 71cf193f10..b9971aa034 100644
--- a/apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts
+++ b/apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts
@@ -130,6 +130,13 @@ export async function balanceAvailable(event: Stripe.Event) {
react: PartnerPayoutWithdrawalInitiated({
email: partner.email,
amount: payout.amount,
+ expectedDate: new Date(payout.arrival_date * 1000).toLocaleDateString(
+ "en-US",
+ {
+ month: "long",
+ day: "numeric",
+ },
+ ),
}),
});
diff --git a/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts b/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts
index dd97cf5853..cd84a17ea2 100644
--- a/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts
+++ b/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts
@@ -1,3 +1,5 @@
+import { sendEmail } from "@dub/email";
+import PartnerPayoutWithdrawalCompleted from "@dub/email/templates/partner-payout-withdrawal-completed";
import { prisma } from "@dub/prisma";
import Stripe from "stripe";
@@ -39,4 +41,21 @@ export async function payoutPaid(event: Stripe.Event) {
console.log(
`Updated ${updatedPayouts.count} payouts for partner ${partner.email} (${stripeAccount}) to "completed" status`,
);
+
+ if (partner.email) {
+ const sentEmail = await sendEmail({
+ variant: "notifications",
+ subject: "Your funds have been transferred to your bank account",
+ email: partner.email,
+ react: PartnerPayoutWithdrawalCompleted({
+ email: partner.email,
+ amount: stripePayout.amount,
+ traceId: stripePayout.id,
+ }),
+ });
+
+ console.log(
+ `Sent email to partner ${partner.email} (${stripeAccount}): ${JSON.stringify(sentEmail, null, 2)}`,
+ );
+ }
}
diff --git a/packages/email/src/templates/partner-payout-withdrawal-completed.tsx b/packages/email/src/templates/partner-payout-withdrawal-completed.tsx
new file mode 100644
index 0000000000..7602e2129f
--- /dev/null
+++ b/packages/email/src/templates/partner-payout-withdrawal-completed.tsx
@@ -0,0 +1,97 @@
+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";
+
+// Send this email after payout.paid webhook is received
+export default function PartnerPayoutWithdrawalCompleted({
+ email = "[email protected]",
+ amount = 45590,
+ traceId = "DUB PARTN-XYZ",
+}: {
+ email: string;
+ amount: number;
+ traceId?: string;
+}) {
+ const amountInDollars = currencyFormatter(amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ });
+
+ const fiveBusinessDaysFromNow = (() => {
+ let date = new Date();
+ let businessDays = 0;
+ while (businessDays < 5) {
+ date.setDate(date.getDate() + 1);
+ // Skip weekends (0 = Sunday, 6 = Saturday)
+ if (date.getDay() !== 0 && date.getDay() !== 6) {
+ businessDays++;
+ }
+ }
+ return date.toLocaleDateString("en-US", {
+ month: "long",
+ day: "numeric",
+ });
+ })();
+
+ return (
+ <Html>
+ <Head />
+ <Preview>Your funds have been transferred to your bank account</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[600px] rounded border border-solid border-neutral-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img src={DUB_WORDMARK} height="32" alt="Dub" />
+ </Section>
+
+ <Heading className="mx-0 my-7 p-0 text-lg font-medium text-black">
+ Your funds have been transferred to your bank account
+ </Heading>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ <span className="font-semibold text-neutral-800">
+ {amountInDollars}
+ </span>{" "}
+ has been transferred from your Stripe Express account to your
+ connected bank account.
+ </Text>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ Banks can take up to 5 business days to process payouts. Wait
+ until{" "}
+ <span className="font-semibold text-neutral-800">
+ {fiveBusinessDaysFromNow}
+ </span>{" "}
+ and then contact your bank using the trace ID{" "}
+ <span className="font-semibold text-neutral-800">{traceId}</span>.
+ </Text>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ If you still have any questions, contact{" "}
+ <Link
+ href="https://support.stripe.com/express"
+ className="font-medium text-black underline"
+ >
+ Stripe support
+ </Link>
+ .
+ </Text>
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}
diff --git a/packages/email/src/templates/partner-payout-withdrawal-initiated.tsx b/packages/email/src/templates/partner-payout-withdrawal-initiated.tsx
index 4054518a0c..e33332a196 100644
--- a/packages/email/src/templates/partner-payout-withdrawal-initiated.tsx
+++ b/packages/email/src/templates/partner-payout-withdrawal-initiated.tsx
@@ -18,9 +18,11 @@ import { Footer } from "../components/footer";
export default function PartnerPayoutWithdrawalInitiated({
email = "[email protected]",
amount = 45590,
+ expectedDate = "Aug 4",
}: {
email: string;
amount: number;
+ expectedDate: string;
}) {
const amountInDollars = currencyFormatter(amount / 100, {
minimumFractionDigits: 2,
@@ -47,13 +49,14 @@ export default function PartnerPayoutWithdrawalInitiated({
<span className="font-semibold text-neutral-800">
{amountInDollars}
</span>{" "}
- is being transferred to your bank account.
+ is being transferred from your Stripe Express account to your
+ connected bank account.
</Text>
<Text className="text-sm leading-6 text-neutral-600">
- Depending on your bank's location, this process can{" "}
+ The funds are expected to arrive in your bank account by{" "}
<span className="font-semibold text-neutral-800">
- can take anywhere between 1-14 business days
+ {expectedDate}
</span>
. If there are any delays, please contact{" "}
<Link