feat: support Stripe discount coupons in promo registration #392

Merged
forgejo_admin merged 3 commits from 391-stripe-discount-coupons into main 2026-04-07 21:17:52 +00:00

Summary

Promo codes now support two paths: free codes (from the env var list) bypass payment entirely, while Stripe promotion codes create a discounted checkout session with the coupon applied. Invalid codes that match neither path return 400.

Closes #391

Changes

  • src/basketball_api/routes/register.py: Split promo validation into free-code check and Stripe PromotionCode.list fallback. Added promo_discount signup method and discounted Stripe checkout session creation with discounts parameter.
  • tests/test_promo_registration.py: Added test for Stripe discount promo redirect, test for free code still working without Stripe, updated invalid code test to mock stripe.PromotionCode.list.

Test Plan

  • pytest tests/test_promo_registration.py -v -- 24/24 passed
  • Free promo codes still create paid registrations with no Stripe redirect
  • Stripe promotion codes create pending registrations with discounted checkout redirect
  • Invalid codes (not free, not in Stripe) return 400
  • Keycloak account creation correctly deferred to webhook for discount codes (payment_status=pending)

Review Checklist

  • ruff format and ruff check pass
  • All 24 tests pass
  • Free code path unchanged (backward compatible)
  • Discount code path creates Stripe checkout with discounts param
  • No Keycloak account created for discount codes (deferred to webhook)
  • Forgejo issue: #391
## Summary Promo codes now support two paths: free codes (from the env var list) bypass payment entirely, while Stripe promotion codes create a discounted checkout session with the coupon applied. Invalid codes that match neither path return 400. Closes #391 ## Changes - `src/basketball_api/routes/register.py`: Split promo validation into free-code check and Stripe `PromotionCode.list` fallback. Added `promo_discount` signup method and discounted Stripe checkout session creation with `discounts` parameter. - `tests/test_promo_registration.py`: Added test for Stripe discount promo redirect, test for free code still working without Stripe, updated invalid code test to mock `stripe.PromotionCode.list`. ## Test Plan - `pytest tests/test_promo_registration.py -v` -- 24/24 passed - Free promo codes still create paid registrations with no Stripe redirect - Stripe promotion codes create pending registrations with discounted checkout redirect - Invalid codes (not free, not in Stripe) return 400 - Keycloak account creation correctly deferred to webhook for discount codes (payment_status=pending) ## Review Checklist - [x] ruff format and ruff check pass - [x] All 24 tests pass - [x] Free code path unchanged (backward compatible) - [x] Discount code path creates Stripe checkout with `discounts` param - [x] No Keycloak account created for discount codes (deferred to webhook) ## Related Notes - Forgejo issue: #391
feat: support Stripe discount coupons in promo code registration
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
2f5ded5d0e
Promo codes now have two paths: free codes (env var list) bypass payment
entirely, while Stripe promotion codes create a discounted checkout
session. Invalid codes that match neither path return 400.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
forgejo_admin force-pushed 391-stripe-discount-coupons from 2f5ded5d0e
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
to f695e3ba1b
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
2026-04-07 21:06:48 +00:00
Compare
style: ruff format test file
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
fe7bd72780
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: remove duplicate first_payment enum entry
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
9a7fe2d968
PR #376 introduced a duplicate first_payment in EmailType enum,
breaking all test collection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
forgejo_admin deleted branch 391-stripe-discount-coupons 2026-04-07 21:17:52 +00:00
Sign in to join this conversation.
No description provided.