Workflows / Stripe / charge.refunded

Stripe Charge Refunded Notification to Slack & Email

Use the Stripe integration by MagicBell to setup a workflow when charge.refunded triggers in Stripe.

Connect Stripe to MagicBell to receive events and trigger workflows. This guide uses the MagicBell CLI.

Add the Stripe integration

Save your Stripe webhook signing secret in MagicBell. See Stripe webhooks.

magicbell integration save_stripe \
  --data '{"webhook_signing_secret":"whsec_xxx"}'

Copy the ID from the response and use it to build your webhook URL:

https://api.magicbell.com/v2/integrations/stripe/webhooks/incoming/{id}

Setup the webhook

  • Setup a webhook in Stripe with the URL from the last step.
  • Select the charge.refunded event.
  • If you already have a webhook configured, make sure it includes this event.

Add a workflow

Create a workflow that triggers automatically when Stripe sends this event.

Workflow key

Use this key to trigger the workflow when Stripe sends a charge.refunded:

integration.stripe.charge.refunded

Example workflow

Confirm refund to customer and notify the finance team.

{
  "key": "integration.stripe.charge.refunded",
  "steps": [
    {
      "command": "broadcast",
      "input": {
        "content": "Your refund of ${{payload.data.object.amount_refunded}} has been processed. It may take 5-10 business days to appear on your statement.",
        "recipients": [
          {
            "external_id": "{{payload.data.object.customer}}"
          }
        ],
        "title": "Refund processed"
      }
    },
    {
      "command": "broadcast",
      "input": {
        "content": "Refund of ${{payload.data.object.amount_refunded}} issued to customer {{payload.data.object.customer}}. Charge ID: {{payload.data.object.id}}",
        "overrides": {
          "providers": {
            "slack": {}
          }
        },
        "recipients": [
          {
            "external_id": "finance-team"
          }
        ],
        "title": "Refund issued"
      }
    }
  ]
}

Save with the CLI

Use the MagicBell CLI to save this workflow to your project. You can also use the Workflows API endpoint instead.

magicbell workflow save \
  --data '{"key":"integration.stripe.charge.refunded","steps":[{"command":"broadcast","input":{"content":"Your refund of ${{payload.data.object.amount_refunded}} has been processed. It may take 5-10 business days to appear on your statement.","recipients":[{"external_id":"{{payload.data.object.customer}}"}],"title":"Refund processed"}},{"command":"broadcast","input":{"content":"Refund of ${{payload.data.object.amount_refunded}} issued to customer {{payload.data.object.customer}}. Charge ID: {{payload.data.object.id}}","overrides":{"providers":{"slack":{}}},"recipients":[{"external_id":"finance-team"}],"title":"Refund issued"}}]}'

Event payload

Sample payload for the charge.refunded event. Use liquid templates to access fields in your workflow.

{
  "api_version": "2023-10-16",
  "created": 1694109201,
  "data": {
    "object": {
      "amount": 2000,
      "amount_captured": 2000,
      "amount_refunded": 2000,
      "billing_details": {
        "email": "customer@example.com",
        "name": "Jenny Rosen"
      },
      "captured": true,
      "created": 1694109201,
      "currency": "usd",
      "customer": "cus_Na6dX7aXxi11N4",
      "description": "Payment for Order #12345",
      "id": "ch_1NqIcRLkdIwHu7ixOoY1Za4b",
      "livemode": false,
      "object": "charge",
      "paid": true,
      "payment_intent": "pi_1NqIcRLkdIwHu7ixPpZ2Ab5c",
      "receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xTTJKVGtMa2RJd0h1N2l4",
      "refunded": true,
      "refunds": {
        "data": [
          {
            "amount": 2000,
            "currency": "usd",
            "id": "re_1NqIcRLkdIwHu7ixQqA3Bc6d",
            "object": "refund",
            "reason": "requested_by_customer",
            "status": "succeeded"
          }
        ],
        "object": "list"
      },
      "status": "succeeded"
    }
  },
  "id": "evt_1NqIcSLkdIwHu7ixMnX0Yz3a",
  "livemode": false,
  "object": "event",
  "type": "charge.refunded"
}
View all Stripe workflows →