import dayjs, { Dayjs } from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; import timezone from "dayjs/plugin/timezone"; import utc from "dayjs/plugin/utc"; import { CalendarEvent } from "@lib/calendarClient"; import EventMail, { AdditionInformation } from "./EventMail"; dayjs.extend(utc); dayjs.extend(timezone); dayjs.extend(localizedFormat); export default class EventPaymentMail extends EventMail { paymentLink: string; constructor( paymentLink: string, calEvent: CalendarEvent, uid: string, additionInformation: AdditionInformation = null ) { super(calEvent, uid, additionInformation); this.paymentLink = paymentLink; } /** * Returns the email text as HTML representation. * * @protected */ protected getHtmlRepresentation(): string { return ( `

Your meeting is awaiting payment

You and any other attendees have been emailed with this information.


What ${this.calEvent.type}
When ${this.getInviteeStart().format("dddd, LL")}
${this.getInviteeStart().format("h:mma")} (${ this.calEvent.attendees[0].timeZone })
Who ${this.calEvent.organizer.name}
${this.calEvent.organizer.email}
Where ${this.getLocation()}
Notes ${this.calEvent.description}
` + this.getAdditionalBody() + "
" + `
Cal.com Logo
` ); } /** * Adds the video call information to the mail body. * * @protected */ protected getLocation(): string { if (this.additionInformation?.hangoutLink) { return `${this.additionInformation?.hangoutLink}
`; } if (this.additionInformation?.entryPoints && this.additionInformation?.entryPoints.length > 0) { const locations = this.additionInformation?.entryPoints .map((entryPoint) => { return ` Join by ${entryPoint.entryPointType}:
${entryPoint.label}
`; }) .join("
"); return `${locations}`; } return this.calEvent.location ? `${this.calEvent.location}

` : ""; } protected getAdditionalBody(): string { return `Pay now`; } /** * Returns the payload object for the nodemailer. * * @protected */ protected getNodeMailerPayload(): Record { return { to: `${this.calEvent.attendees[0].name} <${this.calEvent.attendees[0].email}>`, from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`, replyTo: this.calEvent.organizer.email, subject: `Awaiting Payment: ${this.calEvent.type} with ${ this.calEvent.organizer.name } on ${this.getInviteeStart().format("dddd, LL")}`, html: this.getHtmlRepresentation(), text: this.getPlainTextRepresentation(), }; } protected printNodeMailerError(error: string): void { console.error("SEND_BOOKING_PAYMENT_ERROR", this.calEvent.attendees[0].email, error); } /** * Returns the inviteeStart value used at multiple points. * * @private */ protected getInviteeStart(): Dayjs { return dayjs(this.calEvent.startTime).tz(this.calEvent.attendees[0].timeZone); } }