Use Case

Payment API Monitoring

Protect your revenue stream

Payment API Monitoring

Payment processing is the lifeblood of online business. When payment APIs fail, you lose revenue immediately. APIAssert helps you detect payment issues before customers abandon their carts.

The Problem

Payment API failures are uniquely painful:

  • Silent failures — API returns 200 but transaction fails
  • Partial outages — Specific card types or methods fail
  • Gateway issues — Third-party payment provider has problems
  • Validation errors — Your integration rejects valid requests

A 5-minute payment outage during peak hours can cost thousands in lost sales.

How APIAssert Helps

Monitor Payment Gateway Health

Check that your payment provider is operational:

Monitor: Stripe Health Check
URL: POST https://api.stripe.com/v1/payment_methods
Assertions:
  ✓ Status code == 200
  ✓ $.object == "payment_method"
  ✓ Response time < 2000ms

Validate Your Payment Integration

Ensure your own payment endpoints work:

Monitor: Checkout Payment Validation
URL: POST /api/payments/validate
Body: {"amount": 100, "currency": "USD", "method": "card"}
Assertions:
  ✓ $.valid == true
  ✓ $.available_methods contains "card"
  ✓ $.min_amount <= 100

Check Webhook Endpoints

Verify your webhook handlers are responding:

Monitor: Payment Webhook Health
URL: POST /webhooks/stripe
Assertions:
  ✓ Status code == 200
  ✓ Response time < 500ms

Critical Assertions for Payment APIs

Transaction Creation

// Expected response from payment creation:
{
  "id": "txn_abc123",
  "status": "pending",
  "amount": 9999,
  "currency": "usd"
}

Assertions:

  • $.id must exist
  • $.status must be one of ["pending", "succeeded", "processing"]
  • $.amount must equal expected amount
  • $.currency must equal expected currency

Payment Status

// Expected response from status check:
{
  "status": "succeeded",
  "paid": true,
  "receipt_url": "https://..."
}

Assertions:

  • $.status must exist
  • $.paid must be boolean
  • $.receipt_url must match URL pattern

Refund Processing

// Expected refund response:
{
  "id": "re_xyz789",
  "status": "succeeded",
  "amount": 5000
}

Assertions:

  • $.status must equal "succeeded"
  • $.amount must be positive integer
  • $.id must start with "re_"

Real-World Example

The Scenario

A SaaS company processes subscriptions through Stripe. Occasionally, webhook deliveries fail silently, causing subscription renewals to not be recorded — leading to users being incorrectly downgraded.

The APIAssert Solution

Monitor 1: Stripe Webhook Endpoint

URL: POST /webhooks/stripe
Headers:
  Stripe-Signature: test_signature
Body: {"type": "test"}
Assertions:
  ✓ Status code == 200 or 400
  ✓ Response time < 1000ms

Monitor 2: Subscription Status API

URL: GET /api/subscriptions/health
Assertions:
  ✓ $.queue_size < 100
  ✓ $.last_processed within 5 minutes
  ✓ $.error_rate < 0.01

The Outcome

  • Webhook endpoint availability monitored every minute
  • Alert triggered when queue size exceeded threshold
  • Team discovered Redis connection issue before customer impact
  • Implemented fix and added permanent monitor

Payment Providers to Monitor

Stripe

Endpoint What to Monitor
Payment Intents Transaction creation works
Payment Methods Card tokenization succeeds
Webhooks Events are delivered
Customers Customer creation works

PayPal

Endpoint What to Monitor
Orders Order creation succeeds
Captures Payment capture works
Refunds Refund processing
Webhooks Event delivery

Your Payment Endpoints

Endpoint What to Monitor
POST /checkout Cart to payment works
POST /payments Payment processing
GET /payments/:id Status retrieval
POST /refunds Refund processing

Best Practices

Use Test/Sandbox Endpoints

Most payment providers offer test endpoints:

Production: api.stripe.com
Sandbox: api.stripe.com (with test keys)

Monitor both:

  • Sandbox — verify your integration works
  • Production — catch production-specific issues

Monitor from Multiple Regions

Payment latency matters globally:

US East:    Monitor latency to Stripe US
Europe:     Monitor latency to Stripe EU
Asia:       Monitor latency to Stripe APAC

Different regions may have different performance characteristics.

Set Aggressive Alert Thresholds

For payment APIs, detect issues fast:

  • Check interval: Every 30-60 seconds
  • Alert threshold: 1-2 failures (not 3-5)
  • Response time: Alert if > 3 seconds

Create Payment-Specific Alerts

Route payment alerts to specialized channels:

Payment API Down → PagerDuty (immediate page)
Payment Slow → Slack #payments (warning)
Webhook Queue Growing → Email (monitor)

Test Edge Cases

Monitor for specific scenarios:

  • Zero amount — free trials, $0 checkouts
  • Large amounts — high-value transactions
  • Currency handling — multi-currency support
  • Declined cards — proper error handling

Alert Response Runbook

When payment alerts fire:

  1. Check provider status — Is Stripe/PayPal having issues?
  2. Check your logs — Recent deployments? Error spikes?
  3. Test manually — Can you process a test payment?
  4. Check dependencies — Database, Redis, webhooks working?
  5. Escalate if needed — Contact payment provider support

Getting Started

  1. Identify payment flows — Checkout, subscriptions, refunds
  2. Map API endpoints — Both yours and provider's
  3. Create monitors — Start with transaction creation
  4. Add assertions — Validate response structure
  5. Set up alerts — PagerDuty for critical, Slack for warnings

Related Use Cases