fix(billing): Stripe webhook 500 — normalize event to plain dict - #9
Merged
Conversation
… exploded in prod webhook (500)
There was a problem hiding this comment.
Pull request overview
This PR addresses a production 500 caused by stripe.Webhook.construct_event() returning a Stripe object that is no longer dict-like in stripe-python v15+, by normalizing the verified event into plain Python types and adding a regression test that validates signed payload verification.
Changes:
- Normalize the Stripe webhook event returned by the default verifier into plain JSON/Python types.
- Add a regression test that builds a Stripe-signed payload and asserts the verifier returns a plain
dict.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
gateway/src/declaude/app.py |
Updates the default Stripe webhook verifier to return plain Python types instead of a Stripe object. |
gateway/tests/test_billing_webhook.py |
Adds a regression test covering signature verification and dict-normalization behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+49
to
+51
| event = stripe.Webhook.construct_event(payload, sig_header, os.environ["STRIPE_WEBHOOK_SECRET"]) | ||
| # StripeObject attribute access is unreliable across versions; normalize to plain JSON types. | ||
| return json.loads(str(event)) # StripeObject.__str__ is canonical JSON |
Comment on lines
+126
to
+128
| ts = int(time.time()) | ||
| sig = stripe.WebhookSignature._compute_signature(f"{ts}.{payload.decode()}", secret) | ||
| event = default_webhook_verifier(payload, f"t={ts},v1={sig}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Live Stripe test event (stripe trigger checkout.session.completed) hit prod and 500'd: construct_event returns a StripeObject whose .get lookup raises AttributeError in stripe>=15. Verifier now normalizes to plain JSON types. TDD: signed-payload regression test using stripe's own signature scheme.