diff --git a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js index fe61083eb1..f50b1e700e 100644 --- a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js +++ b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js @@ -129,6 +129,8 @@ class SendGridService extends NotificationService { eventData, attachmentGenerator ) + case "order.refund_created": + return this.orderRefundCreatedData(eventData, attachmentGenerator) default: return {} } @@ -166,6 +168,8 @@ class SendGridService extends NotificationService { return map.customer_password_reset_template case "restock-notification.restocked": return map.medusa_restock_template + case "order.refund_created": + return map.order_refund_created_template default: return null } @@ -203,6 +207,8 @@ class SendGridService extends NotificationService { return this.options_.customer_password_reset_template case "restock-notification.restocked": return this.options_.medusa_restock_template + case "order.refund_created": + return this.options_.order_refund_created_template default: return null } @@ -1155,6 +1161,30 @@ class SendGridService extends NotificationService { return data } + async orderRefundCreatedData({ id, refund_id }) { + const order = await this.orderService_.retrieveWithTotals(id, { + select: [ + "total", + ], + relations: [ + "refunds", + "items", + ] + }) + + const refund = order.refunds.find((refund) => refund.id === refund_id) + + return { + order, + refund, + refund_amount: `${this.humanPrice_( + refund.amount, + order.currency_code + )} ${order.currency_code}`, + email: order.email + } + } + processItems_(items, taxRate, currencyCode) { return items.map((i) => { return { diff --git a/packages/medusa-plugin-sendgrid/src/subscribers/order.js b/packages/medusa-plugin-sendgrid/src/subscribers/order.js index f9d71d147f..717ef4d7ba 100644 --- a/packages/medusa-plugin-sendgrid/src/subscribers/order.js +++ b/packages/medusa-plugin-sendgrid/src/subscribers/order.js @@ -13,6 +13,7 @@ class OrderSubscriber { this.notificationService_.subscribe("swap.created", "sendgrid") this.notificationService_.subscribe("order.items_returned", "sendgrid") this.notificationService_.subscribe("order.return_requested", "sendgrid") + this.notificationService_.subscribe("order.refund_created", "sendgrid") } }