Skip to content

Packs / billing-and-subscriptions-public

verify-payment-webhooks-idempotently

Verify Stripe-style signed webhooks (HMAC, timestamp tolerance) and apply each event exactly once

L2 Checks passed 3 of 3 runsv1.0.0Tech-Realm/space-billing-and-subscriptions-public

Install

logicpacks pack use billing-and-subscriptions-public/verify-payment-webhooks-idempotently
get_pack billing-and-subscriptions-public/verify-payment-webhooks-idempotently

The second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.

Keys it needs (names only)

  • STRIPE_WEBHOOK_SECRET

Playbooks included

  • Spec: spec/SPEC.md (goal, steps, edge cases, don’ts)
  • Routes: stdlibstripe-sdk
  • Checks: 2 in outcome/checks.yaml
  • Code: billing.py
  • Tools: python3

Usage, last 8 weeks

New: no recorded use yet.

Purpose (from spec/SPEC.md)

Verify Stripe-style signed webhooks (HMAC, timestamp tolerance) and apply each event exactly once

Goal

Only genuine payment-provider events change billing state, and retries/duplicates never double-apply.

Steps

  1. Read the RAW body (before JSON parsing) and the signature header.
  2. Verify HMAC-SHA256 over '.' with the endpoint secret (env STRIPE_WEBHOOK_SECRET); reject if |now - t| > 300 s.
  3. Store processed event ids; skip duplicates; return 2xx fast and process async.
  4. Official SDK route: stripe.Webhook.construct_event (stripe-python, MIT).

Edge cases

  • Secret rotation: Stripe sends several v1 signatures during rollover; accept any match.
  • Out-of-order events: fetch the object's current state from the API before acting.

Don'ts

  • Don't parse/re-serialise JSON before verifying.
  • Don't log the signing secret.