From c6158e262cebda11b4840b6cafde33c08b1abe52 Mon Sep 17 00:00:00 2001 From: Leo Kewitz Date: Thu, 22 Feb 2024 17:31:04 +0100 Subject: [PATCH] refact: send receipts to vendors --- server/lib/notifications/email.ts | 9 ++++++++- server/lib/payments.js | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/lib/notifications/email.ts b/server/lib/notifications/email.ts index b6a955bd1fc..3ddb7b13bbe 100644 --- a/server/lib/notifications/email.ts +++ b/server/lib/notifications/email.ts @@ -24,6 +24,8 @@ import { replaceVideosByImagePreviews } from './utils'; const debug = debugLib('notifications'); +const VENDOR_SUBSCRIBED_ACTIVITIES = [ActivityTypes.ORDER_THANKYOU]; + type NotifySubscribersOptions = { attachments?: any[]; bcc?: string; @@ -147,7 +149,12 @@ export const notify = { const collectiveId = options?.collectiveId || activity.CollectiveId; const collective = options?.collective || (await models.Collective.findByPk(collectiveId)); const isVendor = collective?.type === CollectiveType.VENDOR; - if (isVendor) { + if (isVendor && VENDOR_SUBSCRIBED_ACTIVITIES.includes(activity.type)) { + // Notify the vendor, prioritizing the contact information used on the pending contribution data + const email = activity.data?.fromAccountInfo?.email || collective?.data?.vendorInfo?.contact?.email; + if (email) { + await emailLib.send(options?.template || activity.type, email, activity.data, options); + } return; } diff --git a/server/lib/payments.js b/server/lib/payments.js index d2969d6b21a..0439f1dd181 100644 --- a/server/lib/payments.js +++ b/server/lib/payments.js @@ -762,6 +762,8 @@ const sendOrderConfirmedEmail = async (order, transaction) => { firstPayment: true, subscriptionsLink: interval && getEditRecurringContributionsUrl(fromCollective), customMessage, + // Include Pending Order contact info if available + fromAccountInfo: order.data?.fromAccountInfo, }; // hit PDF service and get PDF (unless payment method type is gift card)