Workflows / Stripe / payment.intent.payment.failed

Stripe Payment Failed Notification to Slack & Email

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

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 payment.intent.payment.failed:

integration.stripe.payment_intent.payment_failed

Example workflow

Notify customer when payment intent fails and prompt retry.

{
  "key": "integration.stripe.payment_intent.payment_failed",
  "steps": [
    {
      "command": "broadcast",
      "input": {
        "content": "We couldn't process your payment of ${{payload.data.object.amount}}. Error: {{payload.data.object.last_payment_error.message}}. Please try again with a different 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.payment_intent.payment_failed","steps":[{"command":"broadcast","input":{"content":"We couldn't process your payment of ${{payload.data.object.amount}}. Error: {{payload.data.object.last_payment_error.message}}. Please try again with a different payment method.","recipients":[{"external_id":"{{payload.data.object.customer}}"}],"title":"Payment failed"}}]}'

Event payload

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

{
  "api_version": "2023-10-16",
  "created": 1694109561,
  "data": {
    "object": {
      "amount": 2000,
      "amount_received": 0,
      "created": 1694109561,
      "currency": "usd",
      "customer": "cus_Na6dX7aXxi11N4",
      "description": "Payment for Order #12345",
      "id": "pi_1NqIiRLkdIwHu7ixVvF8Gh1i",
      "last_payment_error": {
        "code": "card_declined",
        "message": "Your card was declined.",
        "type": "card_error"
      },
      "livemode": false,
      "object": "payment_intent",
      "payment_method": "pm_1NqIiRLkdIwHu7ixWwG9Hi2j",
      "status": "requires_payment_method"
    }
  },
  "id": "evt_1NqIiSLkdIwHu7ixUuE7Fg0h",
  "livemode": false,
  "object": "event",
  "type": "payment_intent.payment_failed"
}
View all Stripe workflows →