Repository navigation
feat(billing): wire Stripe webhook to credit ledger [REN-79] - #112
Merged
Merged
Conversation
Replace the TODO stub in the checkout.session.completed handler with actual credit allocation via the ledger service. The webhook now extracts user UUID from client_reference_id and SKU from session metadata, then calls allocate_credits() with the checkout session ID as the idempotency key so Stripe retries are safe. Also registers the Stripe webhook router in the API v1 router and adds six test cases covering happy path, idempotency, unknown SKU, missing metadata, missing signature, and invalid signature. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
checkout.session.completedStripe webhook event toallocate_credits()serviceclient_reference_id, SKU frommetadata.sku, lookupCREDIT_MAPTest plan
test_checkout_completed_allocates_credits— verifies ledger entry with correct amount/sourcetest_checkout_completed_idempotent— duplicate events yield single entrytest_checkout_completed_unknown_sku— warns, returns received:truetest_checkout_completed_missing_metadata— warns, returns received:truetest_missing_signature_returns_400— no stripe-signature header → 400test_invalid_signature_returns_400— forged signature → 400🤖 Generated with Claude Code