Guides / Payments

Auto-Alert When Payment Failures Exceed a Threshold

4 min read·Payments

Why Threshold Alerts Beat Raw Notifications

A single failed payment is noise — cards decline for dozens of reasons. But five failures in ten minutes is a signal: your payment processor may be down, your checkout is broken, or a fraud wave is hitting.

Smart Actions evaluates counts, not individual events. You set the rule once; it fires only when the pattern matters.

Step 1: Log Payment Failures

ts
// In your Stripe webhook handler
import { logit } from "@/lib/logit";

if (event.type === "payment_intent.payment_failed") {
  const intent = event.data.object;
  await logit.now("payments", {
    event: "Payment failed",
    description: intent.last_payment_error?.message ?? "Unknown failure",
    icon: "❌",
    notify: false,      // Smart Action handles bulk alerting
    tags: {
      declineCode: intent.last_payment_error?.decline_code ?? "none",
      currency: intent.currency,
    },
    metadata: {
      intentId: intent.id,
      amount: intent.amount,
      customerId: intent.customer,
    },
  });
}

Step 2: Configure the Smart Action

FieldValue
NamePayment failure spike
Channelpayments
Event namePayment failed
Threshold5
Window10 minutes
Cooldown1 hour
ActionPush notification
Push title❌ Payment failure spike
Push body5+ failures in 10 minutes — check Stripe

Tuning the Rule

Traffic levelRecommended thresholdRecommended window
< 100 payments/day3 failures15 minutes
100–1,000 payments/day5 failures10 minutes
> 1,000 payments/day10 failures5 minutes

Start conservative. You can lower the threshold once you know your normal failure baseline.

Tips

  • Add a separate rule for decline_code: card_declined vs. do_not_honor — they have different remediation paths.
  • Set a 1-hour cooldown during active incidents so the alert doesn't re-fire every 10 minutes while you're investigating.

Try LogIt free

7-day trial. No credit card required.

Start free