Chargebee refund issued notifications on your phone.

Get a low-priority push notification when a Chargebee payment is refunded, with the amount, customer and reason.

payment_refundedPayments & billingRefunds
How it works

Three steps to your first push

STEP 01

Install the recipe

One click in Studio gives you a personal webhook URL.

STEP 02

Paste your URL into Chargebee

Add it as a webhook for payment_refunded.

STEP 03

Get a push on your phone

With the text, sound and buttons from the recipe.

Setup

How to set up the Chargebee payment_refunded webhook

  1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
  2. In Chargebee, go to Settings > Configure Chargebee > API Keys and Webhooks, open the Webhooks tab and click Add Webhook.
  3. Paste your webhook URL as the Webhook URL (add ?site=your-site for dashboard buttons).https://••••••••/•••••••• your personal URL, shown after install
  4. Under Events to Send, pick only payment_refunded and save the webhook.
  5. Under **Events to Send**, pick only `payment_refunded` (Chargebee selects All Events by default). Chargebee sends `refund_initiated` when a direct-debit refund starts; this recipe ignores that event.
  6. **Dashboard button:** Chargebee events don't include your site's name, so add it to the webhook URL to get a button that opens the customer in Chargebee. Use the part before `.chargebee.com` in your dashboard address (test sites usually end in `-test`):
  7. ```
  8. your webhook URL?site=your-site
  9. ```
  10. Without `?site=` the push arrives without a button.
  11. Built for API version **v2** events. Chargebee's **Test Webhook** button sends a sample of the event you pick, which should give a normal push.
  12. Chargebee doesn't sign webhooks. It can send a username and password (basic authentication), but JustPush doesn't check them yet, so you can leave that off. Keep your endpoint URL private.
The code

What runs when the webhook arrives

Studio calls handleRequest(request) with the incoming webhook and sends the message it returns. It's yours after install; change anything.

transform.js
1// Chargebee → payment_refunded
2// Fires when a payment is fully or partially refunded to the customer.
3// Docs: https://apidocs.chargebee.com/docs/api/events/webhook/payment_refunded
4//
5// Paste this into a JustPush Studio integration and add a Chargebee webhook for the
6// "payment_refunded" event pointing at the integration's endpoint URL.
7// Add ?site=your-site to the URL to get a button that opens the customer in Chargebee.
8
9// Chargebee amounts are whole numbers in the currency's smallest unit (2900 = €29.00),
10// except for zero-decimal currencies such as JPY, where 500 means ¥500. This is Chargebee's
11// own list: https://www.chargebee.com/docs/billing/2.0/site-configuration/supported-currencies
12const ZERO_DECIMAL = new Set(["clp", "isk", "jpy", "krw", "mga", "pyg", "vnd", "xaf", "xof", "xpf"])
13
14// Chargebee's built-in credit note reasons (credit_note.reason_code). "other" says nothing, so it's left out.
15const REASONS = {
16 product_unsatisfactory: "product unsatisfactory",
17 service_unsatisfactory: "service unsatisfactory",
18 order_change: "order changed",
19 order_cancellation: "order cancelled",
20 subscription_change: "subscription changed",
21 subscription_cancellation: "subscription cancelled",
22 subscription_pause: "subscription paused",
23 waiver: "waiver",
24 fraudulent: "fraudulent",
25 chargeback: "chargeback",
26 write_off: "write-off",
27}
28
29function money(amount, currency) {
30 // Don't invent a figure when the event doesn't carry one.
31 if (typeof amount !== "number" || !Number.isFinite(amount) || typeof currency !== "string" || !currency) return null
32
33 const code = currency.toLowerCase()
34 const value = ZERO_DECIMAL.has(code) ? amount : amount / 100
35
36 try {
37 return new Intl.NumberFormat("en-GB", { style: "currency", currency: code }).format(value)
38 } catch {
39 return `${value} ${code.toUpperCase()}`
40 }
41}
42
43// A trimmed string, or null for anything else.
44function text(value) {
45 return typeof value === "string" && value.trim() ? value.trim() : null
46}
47
48// Look a key up in a table without tripping over inherited names such as "toString".
49function pick(table, key, fallback) {
50 return typeof key === "string" && Object.prototype.hasOwnProperty.call(table, key) ? table[key] : fallback
51}
52
53// Only link to real http(s) URLs.
54function link(url, cta) {
55 return typeof url === "string" && /^https?:\/\//.test(url) ? [{ cta, url }] : []
56}
57
58// Chargebee events don't carry your site's name, so the dashboard link needs ?site=acme
59// (or ?site=acme-test for a test site) on the webhook URL.
60function adminUrl(request, path, id) {
61 const raw = Array.isArray(request.query?.site) ? request.query.site[0] : request.query?.site
62 const site = (typeof raw === "string" ? raw : "")
63 .trim()
64 .toLowerCase()
65 .replace(/^https?:\/\//, "")
66 .replace(/\.chargebee\.com.*$/, "")
67
68 if (!/^[a-z0-9][a-z0-9-]*$/.test(site) || !text(id)) return null
69 return `https://${site}.chargebee.com/d/${path}/${encodeURIComponent(id)}`
70}
71
72// "Jane Doe", or the company or email when there's no name.
73function customerName(customer) {
74 const name = [text(customer?.first_name), text(customer?.last_name)].filter(Boolean).join(" ")
75 return name || text(customer?.company) || text(customer?.email)
76}
77
78function handleRequest(request) {
79 const event = request.body && typeof request.body === "object" ? request.body : {}
80
81 // Guard: only this event type, so other Chargebee events on this integration stay quiet.
82 // Chargebee sends no event header, so the payload's event_type decides.
83 if (
84 event.event_type !== "payment_refunded" ||
85 (event.object !== undefined && event.object !== "event") ||
86 !event.content?.transaction ||
87 typeof event.content.transaction !== "object"
88 ) {
89 console.log(`Ignoring Chargebee event "${text(event.event_type) ?? "unknown"}"`)
90 return null
91 }
92
93 const { transaction, customer } = event.content
94 const creditNote = event.content.credit_note && typeof event.content.credit_note === "object" ? event.content.credit_note : {}
95 // The event's transaction is the refund itself, so its amount is what went back.
96 const amount =
97 money(transaction.amount, transaction.currency_code) ??
98 money(creditNote.amount_refunded, creditNote.currency_code)
99 const who = customerName(customer)
100 // Your own reason code wins; otherwise Chargebee's built-in reason.
101 const reason = text(creditNote.create_reason_code) ?? pick(REASONS, creditNote.reason_code, null)
102 // Card and direct-debit refunds can take a few days at the gateway.
103 const pending = transaction.status === "in_progress" ? ". Still processing at the gateway." : ""
104
105 return {
106 title: "↩️ Refund issued",
107 message:
108 (amount ? `${amount} refunded` : "A payment was refunded") +
109 (who ? ` to ${who}` : "") +
110 (reason ? ` — ${reason}` : "") +
111 pending,
112 topic: "Chargebee",
113 priority: -1, // Low — you (or a teammate) most likely issued it yourself
114 buttons: link(adminUrl(request, "customers", transaction.customer_id ?? customer?.id), "View customer"),
115 }
116}
Payload

The Chargebee payment_refunded webhook

This is what Chargebee sends to your URL for payment_refunded. It is a sample, trimmed to the fields recipes use.

payment_refunded · sample.json
1{
2 "id": "ev_test_payment_refunded",
3 "user": "[email protected]",
4 "object": "event",
5 "source": "admin_console",
6 "content": {
7 "invoice": {
8 "id": "1042",
9 "total": 2900,
10 "object": "invoice",
11 "status": "paid",
12 "amount_paid": 2900,
13 "customer_id": "cus_test_16BjpLU3",
14 "currency_code": "EUR"
15 },
16 "customer": {
17 "id": "cus_test_16BjpLU3",
18 "email": "[email protected]",
19 "object": "customer",
20 "last_name": "Doe",
21 "first_name": "Jane"
22 },
23 "credit_note": {
24 "id": "CN-7",
25 "type": "refundable",
26 "total": 1500,
27 "object": "credit_note",
28 "status": "refunded",
29 "customer_id": "cus_test_16BjpLU3",
30 "reason_code": "service_unsatisfactory",
31 "currency_code": "EUR",
32 "amount_refunded": 1500,
33 "amount_available": 0,
34 "reference_invoice_id": "1042"
35 },
36 "transaction": {
37 "id": "txn_test_16BjpLU5",
38 "date": 1790584200,
39 "type": "refund",
40 "amount": 1500,
41 "object": "transaction",
42 "status": "success",
43 "gateway": "stripe",
44 "customer_id": "cus_test_16BjpLU3",
45 "currency_code": "EUR",
46 "payment_method": "card",
47 "refunded_txn_id": "txn_test_16BjpLU3",
48 "subscription_id": "sub_test_16BjpLU3",
49 "masked_card_number": "************4242"
50 },
51 "subscription": {
52 "id": "sub_test_16BjpLU3",
53 "object": "subscription",
54 "status": "active",
55 "currency_code": "EUR"
56 }
57 },
58 "event_type": "payment_refunded",
59 "api_version": "v2",
60 "occurred_at": 1790584200,
61 "webhook_status": "scheduled"
62}
FAQ

Chargebee refund issued notifications: questions

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 Chargebee 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.

Ready when you are

Chargebee on your phone in two minutes.

Install the recipe, paste one URL, done. Free for 30 days, no credit card required.