# Polar order paid notifications on your phone

> Get a push notification with the amount, product and customer every time a Polar order is paid, including new subscriptions and renewals.

- Company: Polar (https://www.justpush.io/recipes/polar)
- Event: `order.paid` (order.paid)
- Tags: Payments & billing, Orders, Payments
- Install: https://studio.justpush.io/recipes/polar/order-paid
- Web page: https://www.justpush.io/recipes/polar/order-paid

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In the Polar dashboard, open Settings > Webhooks and click Add Endpoint.
3. Paste your webhook URL (shown in Studio after install) as the URL and leave the format on Raw.
4. Generate a secret (JustPush doesn't need it), tick the order.paid event and save.
5. Tick **order.paid**, not `order.created`: renewal orders are created as *pending* before the payment goes through, while `order.paid` only fires once the money is in. It covers one-time purchases, new subscriptions and renewals, each with its own title.
6. Don't want a push for every renewal? Add `?renewals=0` to the URL. Testing in the **sandbox**? Add `?sandbox=1` so the button opens the sandbox dashboard:
7. ```
8. your webhook URL (shown in Studio after install)?renewals=0
9. ```
10. Polar signs every delivery (`webhook-id`, `webhook-timestamp`, `webhook-signature`; Standard Webhooks for secrets made on or after 8 September 2026), but JustPush doesn't check that signature yet, so keep your endpoint 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
// Polar → order.paid
// Fires when an order is fully processed and paid: one-time purchases, new subscriptions and renewals.
// Docs: https://polar.sh/docs/api-reference/current/order_paid
//
// Use order.paid rather than order.created: renewal orders are created as "pending" before
// the payment goes through.

// How each billing reason reads, and how loud to be.
const REASONS = {
    purchase: { title: "💰 New order", priority: 0 }, // Normal: a sale
    subscription_create: { title: "🎉 New subscriber", priority: 0 }, // Normal: a new customer
    subscription_cycle: { title: "🔁 Subscription renewed", priority: -1, renewal: true }, // Low: routine
    subscription_meter_cycle: { title: "🔁 Usage billed", priority: -1, renewal: true }, // Low: routine
    subscription_update: { title: "⬆️ Subscription changed", priority: 0 }, // Normal: upgrade or seat change
}

// Polar amounts are in the currency's smallest unit (cents), except zero-decimal currencies.
const ZERO_DECIMAL = new Set([
    "bif", "clp", "djf", "gnf", "jpy", "kmf", "krw", "mga",
    "pyg", "rwf", "ugx", "vnd", "vuv", "xaf", "xof", "xpf",
])

function money(amount, currency) {
    if (typeof amount !== "number" || !Number.isFinite(amount) || typeof currency !== "string" || !currency) return null

    const code = currency.toLowerCase()
    const value = ZERO_DECIMAL.has(code) ? amount : amount / 100

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

// Table lookup that ignores inherited names such as "toString".
function pick(table, key, fallback) {
    return typeof key === "string" && Object.prototype.hasOwnProperty.call(table, key) ? table[key] : fallback
}

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

// A non-empty string, or null.
function text(value) {
    return typeof value === "string" && value.trim() ? value.trim() : null
}

function flag(query, name) {
    return ["1", "true", "yes"].includes(String(query?.[name] ?? "").toLowerCase())
}

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

    // Guard: only order.paid, so other Polar events on this integration stay quiet.
    if (body.type !== "order.paid" || !order || typeof order !== "object" || !order.id) {
        console.log(`Ignoring Polar "${typeof body.type === "string" ? body.type : "unknown"}" event`)
        return null
    }

    const reason = pick(REASONS, order.billing_reason, { title: "💰 Order paid", priority: 0 })

    // ?renewals=0 on the webhook URL skips routine renewal payments.
    if (reason.renewal && ["0", "false", "no"].includes(String(request.query?.renewals ?? "").toLowerCase())) {
        console.log("Skipping renewal (renewals=0)")
        return null
    }

    const free = order.total_amount === 0
    const total = free ? "Free" : money(order.total_amount, order.currency)
    const who = text(order.customer?.name) ?? text(order.billing_name) ?? text(order.customer?.email)
    const product = text(order.product?.name) ?? text(order.description)
    // ?sandbox=1 points the button at the sandbox dashboard.
    const host = flag(request.query, "sandbox") ? "https://sandbox.polar.sh" : "https://polar.sh"

    return {
        title: reason.title,
        message:
            (total ?? "An order") +
            (product ? ` · ${product}` : "") +
            (who ? ` · ${who}` : ""),
        topic: "Polar",
        priority: free ? -1 : reason.priority, // free orders are Low: nothing was earned
        ...(free ? {} : { sound: "cashregister" }),
        buttons: link(`${host}/to/dashboard/sales/${encodeURIComponent(order.id)}`, "View order"),
    }
}
```

## Polar order.paid webhook payload (sample)

```json
{
  "data": {
    "id": "7e3a5c1d-2b4f-4c8e-9a1b-0f2d3e4c5b6a",
    "paid": true,
    "items": [
      {
        "label": "Lifetime licence",
        "amount": 4900,
        "proration": false,
        "tax_amount": 1029
      }
    ],
    "status": "paid",
    "product": {
      "id": "p1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
      "name": "Lifetime licence",
      "description": null,
      "is_archived": false,
      "is_recurring": false,
      "organization_id": "o1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
      "recurring_interval": null
    },
    "currency": "eur",
    "customer": {
      "id": "c1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
      "name": "Jane Doe",
      "type": "individual",
      "email": "jane@example.com",
      "billing_name": "Jane Doe",
      "email_verified": true,
      "organization_id": "o1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b"
    },
    "metadata": [],
    "created_at": "2026-09-29T08:06:30.000000Z",
    "due_amount": 0,
    "net_amount": 4900,
    "product_id": "p1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
    "tax_amount": 1029,
    "checkout_id": "k1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
    "customer_id": "c1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
    "description": "Lifetime licence",
    "discount_id": null,
    "modified_at": "2026-09-29T08:06:40.000000Z",
    "billing_name": "Jane Doe",
    "subscription": null,
    "total_amount": 5929,
    "billing_reason": "purchase",
    "invoice_number": "ACME-0042",
    "discount_amount": 0,
    "refunded_amount": 0,
    "subscription_id": null,
    "subtotal_amount": 4900,
    "refunded_tax_amount": 0,
    "applied_balance_amount": 0
  },
  "type": "order.paid",
  "timestamp": "2026-09-29T08:06:40.000000Z"
}
```

## 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 Polar 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.
