import dayjs from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; import timezone from "dayjs/plugin/timezone"; import toArray from "dayjs/plugin/toArray"; import utc from "dayjs/plugin/utc"; import { emailHead } from "./common/head"; import { emailSchedulingBodyHeader } from "./common/scheduling-body-head"; import OrganizerScheduledEmail from "./organizer-scheduled-email"; dayjs.extend(utc); dayjs.extend(timezone); dayjs.extend(localizedFormat); dayjs.extend(toArray); export default class OrganizerPaymentRefundFailedEmail extends OrganizerScheduledEmail { protected getNodeMailerPayload(): Record { const toAddresses = [this.calEvent.organizer.email]; if (this.calEvent.team) { this.calEvent.team.members.forEach((member) => { const memberAttendee = this.calEvent.attendees.find((attendee) => attendee.name === member); if (memberAttendee) { toAddresses.push(memberAttendee.email); } }); } return { from: `Cal.com <${this.getMailerOptions().from}>`, to: toAddresses.join(","), subject: `${this.calEvent.language("refund_failed_subject", { eventType: this.calEvent.type, name: this.calEvent.attendees[0].name, date: `${this.getOrganizerStart().format("h:mma")} - ${this.getOrganizerEnd().format( "h:mma" )}, ${this.calEvent.language( this.getOrganizerStart().format("dddd").toLowerCase() )}, ${this.calEvent.language( this.getOrganizerStart().format("MMMM").toLowerCase() )} ${this.getOrganizerStart().format("D")}, ${this.getOrganizerStart().format("YYYY")}`, })}`, html: this.getHtmlBody(), text: this.getTextBody(), }; } protected getTextBody(): string { return ` ${this.calEvent.language("a_refund_failed")} ${this.calEvent.language("check_with_provider_and_user", { user: this.calEvent.attendees[0].name })} ${ this.calEvent.paymentInfo && this.calEvent.language("error_message", { errorMessage: this.calEvent.paymentInfo.reason }) } ${this.getWhat()} ${this.getWhen()} ${this.getLocation()} ${this.getAdditionalNotes()} `.replace(/(<([^>]+)>)/gi, ""); } protected getHtmlBody(): string { const headerContent = this.calEvent.language("refund_failed_subject", { eventType: this.calEvent.type, name: this.calEvent.attendees[0].name, date: `${this.getOrganizerStart().format("h:mma")} - ${this.getOrganizerEnd().format( "h:mma" )}, ${this.calEvent.language( this.getOrganizerStart().format("dddd").toLowerCase() )}, ${this.calEvent.language( this.getOrganizerStart().format("MMMM").toLowerCase() )} ${this.getOrganizerStart().format("D")}, ${this.getOrganizerStart().format("YYYY")}`, }); return ` ${emailHead(headerContent)}
${emailSchedulingBodyHeader("xCircle")}
${this.getRefundInformation()}
${this.calEvent.language( "a_refund_failed" )}
${this.calEvent.language( "check_with_provider_and_user", { user: this.calEvent.attendees[0].name } )}

${this.getWhat()} ${this.getWhen()} ${this.getWho()} ${this.getLocation()} ${this.getAdditionalNotes()}
`; } protected getRefundInformation(): string { const paymentInfo = this.calEvent.paymentInfo; let refundInformation = ""; if (paymentInfo) { if (paymentInfo.reason) { refundInformation = `
${this.calEvent.language( "error_message", { errorMessage: paymentInfo.reason } )}
`; } if (paymentInfo.id) { refundInformation += `
Payment ${paymentInfo.id}
`; } } return refundInformation; } }