Workflows / Stripe / charge.failed

Stripe Charge Failed Notification to Slack & Email

Use the Stripe integration by MagicBell to setup a workflow when charge.failed 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.failed 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.failed:

integration.stripe.charge.failed

Example workflow

Notify customers when their payment fails and prompt them to update their payment method.

{
  "key": "integration.stripe.charge.failed",
  "steps": [
    {
      "command": "broadcast",
      "input": {
        "content": "We couldn't process your payment of ${{payload.data.object.amount}}. Reason: {{payload.data.object.failure_message}}. Please update your payment method.",
        "recipients": [
          {
            "external_id": "{{payload.data.object.customer}}"
          }
        ],
        "title": "Payment failed"
      }
    }
  ]
}

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.failed","steps":[{"command":"broadcast","input":{"content":"We couldn't process your payment of ${{payload.data.object.amount}}. Reason: {{payload.data.object.failure_message}}. Please update your payment method.","recipients":[{"external_id":"{{payload.data.object.customer}}"}],"title":"Payment failed"}}]}'

Event payload

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

{
  "api_version": "2023-10-16",
  "created": 1694109141,
  "data": {
    "object": {
      "amount": 2000,
      "amount_captured": 0,
      "amount_refunded": 0,
      "billing_details": {
        "email": "customer@example.com",
        "name": "Jenny Rosen"
      },
      "captured": false,
      "created": 1694109141,
      "currency": "usd",
      "customer": "cus_Na6dX7aXxi11N4",
      "description": "Payment for Order #12345",
      "failure_code": "card_declined",
      "failure_message": "Your card was declined.",
      "id": "ch_1NqIbRLkdIwHu7ixNnX0Yz3a",
      "livemode": false,
      "object": "charge",
      "paid": false,
      "payment_intent": "pi_1NqIbRLkdIwHu7ixOoY1Za4b",
      "payment_method": "pm_1NqIbRLkdIwHu7ixPpZ2Ab5c",
      "refunded": false,
      "status": "failed"
    }
  },
  "id": "evt_1NqIbSLkdIwHu7ixLmW9Xy2z",
  "livemode": false,
  "object": "event",
  "type": "charge.failed"
}
View all Stripe workflows →