feat(medusa-plugin-sendgrid) Add refund created event to sendgrid (#2740)
This commit is contained in:
committed by
GitHub
parent
7cced6006a
commit
b06794b08b
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user