# Magento order refunded notifications on your phone

> Get a low-priority push notification when a credit memo refunds all or part of a Magento order.

- Company: Magento (https://www.justpush.io/recipes/magento)
- Event: `order.refunded` (Order refunded)
- Tags: E-commerce, Refunds
- Install: https://studio.justpush.io/recipes/magento/order-refunded
- Web page: https://www.justpush.io/recipes/magento/order-refunded

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. Install the JustPush module in your shop: composer require justpush/magento-module-notify, then bin/magento setup:upgrade.
3. In the Magento admin, open Stores > Configuration > Services > JustPush and set Enabled to Yes.
4. Paste your webhook URL (shown in Studio after install) into the Order refunded field, click Save Config, then click Send test.
5. Magento has no outgoing webhooks, so this recipe needs the free **JustPush module** in your shop ([source](https://github.com/JustPush-io/justpush-magento)). Install it once; it serves every Magento recipe:
6. ```bash
7. composer require justpush/magento-module-notify
8. bin/magento setup:upgrade
9. bin/magento cache:flush
10. ```
11. Then open **Stores → Configuration → Services → JustPush** in the Magento admin, set **Enabled** to **Yes**, paste the URL above into the **Order refunded** field and click **Save Config**. Click **Send test**: this recipe answers with a quiet "🔔 Magento connected".
12. The module sends one message per credit memo, so an order refunded in two steps gives two pushes.
13. The module sends from Magento's message queue, so Magento cron has to run (it usually does). Without cron, set **Send immediately (no cron)** to **Yes**.
14. The **Open credit memo** button opens the Magento admin. With Magento's default **Add Secret Key to URLs** setting, it lands on the dashboard rather than the page itself.
15. Requests aren't signed, so keep the URL private.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// Magento → order refunded
// Fires when the JustPush module (justpush/magento-module-notify) reports an "order.refunded" event:
// a credit memo was created, once per credit memo.
// Docs: https://github.com/JustPush-io/justpush-magento

// The module sends plain strings; treat blanks and nulls as missing.
function text(value) {
    return typeof value === "string" && value.trim() ? value.trim() : null
}

// Only link to real http(s) URLs.
function link(url, cta) {
    return typeof url === "string" && /^https?:\/\//.test(url) ? [{ cta, url }] : []
}

// Which shop sent it, so owners of several websites can tell them apart.
function shop(store) {
    if (!store || typeof store !== "object") return null
    const url = text(store.url)
    const host = url && /^https?:\/\//.test(url) ? url.replace(/^https?:\/\//, "").replace(/\/.*$/, "") : null
    return text(store.website) ?? text(store.store_view) ?? host
}

// The module's "Send test" button; every Magento recipe answers it.
function testPing(body) {
    const from = shop(body.store)
    return {
        title: "🔔 Magento connected",
        message: from ? `${from} is sending to this recipe` : "Your shop is sending to this recipe",
        topic: "Magento",
        priority: -1, // Low — you just clicked the button
    }
}

// Magento sends money as decimal strings ("49.00"). Returns null when there's no amount.
function money(amount, currency) {
    const value = Number(amount)
    if (amount == null || amount === "" || !Number.isFinite(value) || !text(currency)) return null

    try {
        return new Intl.NumberFormat("en-GB", { style: "currency", currency: currency.trim() }).format(value)
    } catch {
        return `${amount} ${currency}`
    }
}

function handleRequest(request) {
    const body = request.body && typeof request.body === "object" ? request.body : {}

    if (body.event === "test.ping") return testPing(body)

    // Guard: only handle this recipe's event, so other Magento events on this integration stay quiet.
    const memo = body.creditmemo
    if (body.event !== "order.refunded" || !memo || typeof memo !== "object") {
        console.log(`Ignoring Magento event "${body.event ?? "unknown"}"`)
        return null
    }

    const order = text(memo.order_increment_id)
    const refunded = money(memo.grand_total, memo.currency)
    const of = money(memo.order_grand_total, memo.currency)
    // Only say "of €x" for a partial refund.
    const partial = refunded && of && Number(memo.grand_total) < Number(memo.order_grand_total)
    const customer = text(memo.customer_name)

    return {
        title: order ? `↩️ Refund for order #${order}` : "↩️ Refund issued",
        message: [
            (refunded ? `${refunded}${partial ? ` of ${of}` : ""} refunded` : "Refund issued") +
                (customer ? ` to ${customer}` : ""),
            shop(body.store),
        ]
            .filter(Boolean)
            .join(" · "),
        topic: "Magento",
        priority: -1, // Low — you (or a colleague) most likely created the credit memo yourself
        buttons: link(memo.admin_url, "Open credit memo"),
    }
}
```

## Magento order.refunded webhook payload (sample)

```json
{
  "event": "order.refunded",
  "store": {
    "url": "https://shop.example.com/",
    "website": "Main Website",
    "store_view": "Default Store View"
  },
  "sent_at": "2026-09-30T14:29:28Z",
  "version": 1,
  "creditmemo": {
    "currency": "EUR",
    "admin_url": "https://shop.example.com/admin/sales/creditmemo/view/creditmemo_id/3/",
    "grand_total": "49.00",
    "increment_id": "000000003",
    "customer_name": "Jane Doe",
    "order_grand_total": "108.00",
    "order_increment_id": "000000012"
  }
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into Magento and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
