diff --git a/src/api/markket/services/notification.ts b/src/api/markket/services/notification.ts deleted file mode 100644 index fc18413..0000000 --- a/src/api/markket/services/notification.ts +++ /dev/null @@ -1,43 +0,0 @@ -const SENDGRID_FROM_EMAIL = process.env.SENDGRID_FROM_EMAIL || ''; -const SENDGRID_REPLY_TO_EMAIL = process.env.SENDGRID_REPLY_TO_EMAIL || ''; - -const OrderNotificationHTml = (order: any) => { - //
Order Amount: ${((order?.data?.object?.total_amount || 0) / 100)}
- return ` -Thank you for your order!
-Order ID: ${order?.data?.object?.id}
-- - View Receipt - -
- `; -}; - -export const sendOrderNotification = async ({ strapi, order }) => { - console.info('notification::stripe:checkout.session.completed', { - order, - strapi: !!strapi - }); - - if (!SENDGRID_FROM_EMAIL || !SENDGRID_REPLY_TO_EMAIL) { - return; - } - - if (!order?.data?.object?.customer_details?.email) { - return; - } - - const customer = order?.data?.object?.customer_details; - - return await strapi.plugins['email'].services.email.send({ - to: customer.email, - from: SENDGRID_FROM_EMAIL, //e.g. single sender verification in SendGrid - cc: SENDGRID_REPLY_TO_EMAIL, - replyTo: SENDGRID_REPLY_TO_EMAIL, - subject: 'Markkët: Order Confirmation', - text: 'Thank you for your order!', - html: OrderNotificationHTml(order), - }); -}; diff --git a/src/api/markket/services/notification/index.ts b/src/api/markket/services/notification/index.ts new file mode 100644 index 0000000..a025fdb --- /dev/null +++ b/src/api/markket/services/notification/index.ts @@ -0,0 +1,65 @@ +const SENDGRID_FROM_EMAIL = process.env.SENDGRID_FROM_EMAIL || ''; +const SENDGRID_REPLY_TO_EMAIL = process.env.SENDGRID_REPLY_TO_EMAIL || ''; +import { OrderNotificationHTml, RSVPNotificationHTml } from './template'; + + +export const sendRSVPNotification = async ({ strapi, rsvp, event }) => { + console.info('notification::rsvp:created', { + rsvp: !!rsvp, + event: !!event, + strapi: !!strapi, + from: !!SENDGRID_FROM_EMAIL, + reply_to: !!SENDGRID_REPLY_TO_EMAIL, + }); + + if (!SENDGRID_FROM_EMAIL || !SENDGRID_REPLY_TO_EMAIL) { + return; + } + + // if (!order?.data?.object?.customer_details?.email) { + // return; + // } + + // const customer = event?.data?.object?.customer_details; + const customer = { email: rsvp.email }; + + return await strapi.plugins['email'].services.email.send({ + to: customer.email, + from: SENDGRID_FROM_EMAIL, //e.g. single sender verification in SendGrid + cc: SENDGRID_REPLY_TO_EMAIL, + replyTo: SENDGRID_REPLY_TO_EMAIL, + subject: 'Markkët: RSVP Confirmation', + text: 'RSVP confirmation!', + html: RSVPNotificationHTml(event), + }); +}; + + +export const sendOrderNotification = async ({ strapi, order }) => { + console.info('notification::stripe:checkout.session.completed', { + order, + strapi: !!strapi, + from: !!SENDGRID_FROM_EMAIL, + reply_to: !!SENDGRID_REPLY_TO_EMAIL, + }); + + if (!SENDGRID_FROM_EMAIL || !SENDGRID_REPLY_TO_EMAIL) { + return; + } + + if (!order?.data?.object?.customer_details?.email) { + return; + } + + const customer = order?.data?.object?.customer_details; + + return await strapi.plugins['email'].services.email.send({ + to: customer.email, + from: SENDGRID_FROM_EMAIL, //e.g. single sender verification in SendGrid + cc: SENDGRID_REPLY_TO_EMAIL, + replyTo: SENDGRID_REPLY_TO_EMAIL, + subject: 'Markkët: Order Confirmation', + text: 'Thank you for your order!', + html: OrderNotificationHTml(order), + }); +}; diff --git a/src/api/markket/services/notification/template.ts b/src/api/markket/services/notification/template.ts new file mode 100644 index 0000000..c592969 --- /dev/null +++ b/src/api/markket/services/notification/template.ts @@ -0,0 +1,231 @@ + +type EmailLayout = { + content: string; + title: string; +}; + +export const emailLayout = ({ content, title }: EmailLayout) => { + return ` + + + + + +Order Amount: ${((order?.data?.object?.total_amount || 0) / 100)}
+ const content = ` +Thank you for your order!
+Order ID: ${order?.data?.object?.id}
+Dear buyer,
+ + + View Receipt + +The seller has been notified and will reach out if more information is needed.
+Order Amount: ${((order?.data?.object?.total_amount || 0) / 100)}
+ const content = ` + +Dear {{name}},
+ +Event: {{eventName}}
+Date: {{eventDate}}
+Time: {{startTime}} - {{endTime}}
+Your Email: {{email}}
+