Packs / billing-and-subscriptions-public
verify-payment-webhooks-idempotently
Verify Stripe-style signed webhooks (HMAC, timestamp tolerance) and apply each event exactly once
Install
logicpacks pack use billing-and-subscriptions-public/verify-payment-webhooks-idempotentlyget_pack billing-and-subscriptions-public/verify-payment-webhooks-idempotentlyThe 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
- Read the RAW body (before JSON parsing) and the signature header.
- Verify HMAC-SHA256 over '
.' with the endpoint secret (env STRIPE_WEBHOOK_SECRET); reject if |now - t| > 300 s. - Store processed event ids; skip duplicates; return 2xx fast and process async.
- 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.