Email me when a refund is requested

Get instant notifications when customers request refunds so you can provide timely support and turn unhappy customers into loyal ones.

Overview

This hook sends you an email alert whenever a refund is requested in your Shopify store. You can set a minimum threshold amount to filter notifications for only significant refunds.

Prerequisites

  • A Shopify store with Cloudhooks installed
  • Email address where you want to receive notifications

Configuration

1) Set up trigger

Create a new hook in the Cloudhooks dashboard with "A refund is created" as your trigger event.

2) Configure settings

Customize these settings in the hook code:

  • REFUND_MINIMUM: Set the minimum dollar amount that triggers a notification (default: $0 to receive alerts for all refunds)
  • REFUND_EMAIL: Your email address where notifications will be sent

Implementation

const REFUND_MINIMUM = 200 // Refund amount in USD
const REFUND_EMAIL = 'john.doe@example.com'

module.exports = async function (payload, actions, context) {
  const { shopifyDomain } = context

  const subject = `(${shopifyDomain}) Refund requested`
  const body = `
    Please review the following refund: 
    ${payload.order_id}
  `

  const totalRefundAmount = payload.refund_line_items.reduce((total, item) => {
    return total + parseInt(item.subtotal)
  }, 0)

  if (totalRefundAmount > REFUND_MINIMUM) {
    await actions.email.send({ to: REFUND_EMAIL, subject, body })
  } 
}

Testing

Test your hook using Cloudhooks' test payload feature with a sample refund request before activating it in production.

Important: Before activating, make sure to update the REFUND_EMAIL constant with your actual email address and adjust the REFUND_MINIMUM value to your preferred threshold.

Additional Resources

For more integration examples, visit our Gist page on Github.