# verify-payment-webhooks-idempotently

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

- **Space:** billing-and-subscriptions-public (https://github.com/Tech-Realm/space-billing-and-subscriptions-public/tree/main/verify-payment-webhooks-idempotently)
- **Level:** L2 (as the registry reports it)
- **Keys it needs (names only):** STRIPE_WEBHOOK_SECRET
- **Tools:** python3
- **Routes:** stdlib, stripe-sdk; checks: 2
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use billing-and-subscriptions-public/verify-payment-webhooks-idempotently` or MCP `get_pack billing-and-subscriptions-public/verify-payment-webhooks-idempotently`
- **Files:** CHANGELOG.md, code/billing.py, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/fixtures/event.json, outcome/fixtures/plan.json, outcome/fixtures/usage.json, outcome/results.json, pack.yaml, refs/refs.yaml, spec/SPEC.md, spec/source.md

## Purpose (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 '<t>.<body>' 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.



---

Canonical URL: https://logicpacks.io/packs/billing-and-subscriptions-public/verify-payment-webhooks-idempotently

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
