Skip to content

Load Stripe plan-price mapping from env with startup validation#374

Merged
AJaySi merged 1 commit intomainfrom
codex/move-stripe_plan_price_mapping-to-env-driven-config
Mar 5, 2026
Merged

Load Stripe plan-price mapping from env with startup validation#374
AJaySi merged 1 commit intomainfrom
codex/move-stripe_plan_price_mapping-to-env-driven-config

Conversation

@AJaySi
Copy link
Owner

@AJaySi AJaySi commented Mar 4, 2026

Motivation

  • Replace hardcoded Stripe price IDs with environment-driven configuration so test and live deployments can use different mappings without code edits.
  • Fail fast at startup when mapping is missing, malformed, or missing required tier/cycle keys to avoid runtime checkout/webhook errors.

Description

  • Replaced the in-code STRIPE_PLAN_PRICE_MAPPING with an environment-driven loader in backend/services/subscription/stripe_service.py that: detects mode via STRIPE_MODE or STRIPE_SECRET_KEY prefix, prefers STRIPE_PLAN_PRICE_MAPPING_LIVE/_TEST and falls back to STRIPE_PLAN_PRICE_MAPPING, parses JSON, normalizes keys, and builds the runtime mapping and reverse map (STRIPE_PRICE_TO_PLAN).
  • Added strict validation (REQUIRED_STRIPE_PLAN_KEYS) to ensure required combinations (currently basic.monthly and pro.monthly) exist and that price IDs are non-empty, raising RuntimeError on failure.
  • Kept existing runtime lookup behavior (_get_price_id_for_plan, _get_plan_for_price_id) intact but now backed by the validated mapping.
  • Updated documentation: docs/Billing_Subscription/stripe-go-live-checklist.md, docs/Billing_Subscription/stripe-dev-guide.md, and backend/README.md to document the new env vars and expected JSON mapping format and required keys.

Testing

  • Compiled the modified module: python -m py_compile backend/services/subscription/stripe_service.py (succeeded).
  • Verified successful import with a valid test mapping by setting STRIPE_PLAN_PRICE_MAPPING_TEST='{"basic":{"monthly":"price_basic"},"pro":{"monthly":"price_pro"}}' and importing STRIPE_PLAN_PRICE_MAPPING (succeeded and returned expected price id).
  • Verified fail-fast behaviour by setting STRIPE_PLAN_PRICE_MAPPING_TEST='{"basic":{"monthly":"price_basic"}}' and importing the module, which raised the expected RuntimeError for the missing required pro.monthly mapping.

Codex Task

@vercel
Copy link

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
alwrity Error Error Mar 4, 2026 3:12pm

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@AJaySi AJaySi merged commit 806ab7b into main Mar 5, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant