Skip to content

Commit

Permalink
email receipt: send parameter days_until_next_year
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz committed Dec 15, 2024
1 parent f4fe78e commit c12263e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/donation/email.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addYears, differenceInDays, startOfYear } from "date-fns";
import { EmailParams, MailerSend, Recipient } from "mailersend";
import {
type BankTransferInfo,
Expand Down Expand Up @@ -75,6 +76,11 @@ export async function sendPaymentEmail(
donation: DonationToEmail,
bank?: BankTransferInfo,
) {
const days_until_next_year = differenceInDays(
startOfYear(addYears(new Date(), 1)),
new Date(),
);

const emailParams = new EmailParams()
.setTo([new Recipient(donation.email)])
.setTemplateId(process.env.MAILERSEND_TEMPLATE_DONATION)
Expand All @@ -91,6 +97,7 @@ export async function sendPaymentEmail(
frequency: donation.frequency,
tax_deductible: donation.tax_deductible,
bank_msg: bank?.msg ?? null,
days_until_next_year,
},
},
]);
Expand Down Expand Up @@ -136,12 +143,12 @@ export async function sendFailedRecurringDonationEmail(
{
email: info.donor_email,
data: {
subject_prefix:
process.env.VERCEL_ENV === "production" ? "" : "DEV: ",
amount: info.amount.toLocaleString("da-DK"),
name: info.donor_name ?? null,
recipient: info.recipient,
payment_link: info.payment_link,
subject_prefix:
process.env.VERCEL_ENV === "production" ? "" : "DEV: ",
},
},
]);
Expand Down

0 comments on commit c12263e

Please sign in to comment.