feat(medusa-plugin-sendgrid) Add refund created event to sendgrid (#2740)
This commit is contained in:
1 parent
7cced6006a
commit
b06794b08b
2 files changed
+31
No files matched your search
@@ -129,6 +129,8 @@ class SendGridService extends NotificationService {
|
|||||||
eventData,
|
eventData,
|
||||||
attachmentGenerator
|
attachmentGenerator
|
||||||
)
|
)
|
||||||
|
case "order.refund_created":
|
||||||
|
return this.orderRefundCreatedData(eventData, attachmentGenerator)
|
||||||
default:
|
default:
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
@@ -166,6 +168,8 @@ class SendGridService extends NotificationService {
|
|||||||
return map.customer_password_reset_template
|
return map.customer_password_reset_template
|
||||||
case "restock-notification.restocked":
|
case "restock-notification.restocked":
|
||||||
return map.medusa_restock_template
|
return map.medusa_restock_template
|
||||||
|
case "order.refund_created":
|
||||||
|
return map.order_refund_created_template
|
||||||
default:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -203,6 +207,8 @@ class SendGridService extends NotificationService {
|
|||||||
return this.options_.customer_password_reset_template
|
return this.options_.customer_password_reset_template
|
||||||
case "restock-notification.restocked":
|
case "restock-notification.restocked":
|
||||||
return this.options_.medusa_restock_template
|
return this.options_.medusa_restock_template
|
||||||
|
case "order.refund_created":
|
||||||
|
return this.options_.order_refund_created_template
|
||||||
default:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -1155,6 +1161,30 @@ class SendGridService extends NotificationService {
|
|||||||
return data
|
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) {
|
processItems_(items, taxRate, currencyCode) {
|
||||||
return items.map((i) => {
|
return items.map((i) => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class OrderSubscriber {
|
|||||||
this.notificationService_.subscribe("swap.created", "sendgrid")
|
this.notificationService_.subscribe("swap.created", "sendgrid")
|
||||||
this.notificationService_.subscribe("order.items_returned", "sendgrid")
|
this.notificationService_.subscribe("order.items_returned", "sendgrid")
|
||||||
this.notificationService_.subscribe("order.return_requested", "sendgrid")
|
this.notificationService_.subscribe("order.return_requested", "sendgrid")
|
||||||
|
this.notificationService_.subscribe("order.refund_created", "sendgrid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user