Skip to content

feat(billing): wire Stripe webhook to credit ledger [REN-79] - #112

Merged
Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-79-stripe-webhook-ledger
Mar 9, 2026
Merged

Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-79-stripe-webhook-ledger

Conversation

@cheddarfox

Copy link
Copy Markdown
Member

Summary

  • Wire checkout.session.completed Stripe webhook event to allocate_credits() service
  • Extract user UUID from client_reference_id, SKU from metadata.sku, lookup CREDIT_MAP
  • Gracefully handle missing/unknown SKU (warn + acknowledge, no webhook failure)
  • Register Stripe webhook router in API v1 router
  • 6 tests covering allocation, idempotency, unknown SKU, missing metadata, and signature validation

Test plan

  • test_checkout_completed_allocates_credits — verifies ledger entry with correct amount/source
  • test_checkout_completed_idempotent — duplicate events yield single entry
  • test_checkout_completed_unknown_sku — warns, returns received:true
  • test_checkout_completed_missing_metadata — warns, returns received:true
  • test_missing_signature_returns_400 — no stripe-signature header → 400
  • test_invalid_signature_returns_400 — forged signature → 400

🤖 Generated with Claude Code

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>
@cheddarfox
Scott Graham (cheddarfox) merged commit 830bf6c into dev Mar 9, 2026
13 of 15 checks passed
@cheddarfox
Scott Graham (cheddarfox) deleted the REN-79-stripe-webhook-ledger branch March 9, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant