Skip to content

fix(billing): test-plan-aware tier mapping + PAYMENT_TEST_MODE_ENABLED kill-switch#271

Merged
mastermanas805 merged 2 commits into
masterfrom
fix/billing-test-plan-id-tier-mapping
Jun 7, 2026
Merged

fix(billing): test-plan-aware tier mapping + PAYMENT_TEST_MODE_ENABLED kill-switch#271
mastermanas805 merged 2 commits into
masterfrom
fix/billing-test-plan-id-tier-mapping

Conversation

@mastermanas805

Copy link
Copy Markdown
Member

Why

Wiring the real with-UI Razorpay test-card payment E2E (free cohort → dashboard Upgrade → test hosted-checkout → card → Pro active) surfaced two gaps that would have made the full chain silently fail or be unsafe.

What

  1. Test-plan-aware tier mapping. planIDToTier/planIDRecognised only knew the live RAZORPAY_PLAN_ID_*. A TEST-mode subscription.activated/charged webhook carries the test plan_id → matched nothing → fell back to the safe fallback tier (hobby) and emitted a bogus billing.charge_undeliverable. So a test-cohort pro upgrade could never reach pro and the spec's pollTierIsPro would always soft-skip. Now the RazorpayTestPlanID{Pro,HobbyPlus,Hobby} IDs map to their canonical tiers (test plans exist only in test mode → no collision with live plan_ids).

  2. PAYMENT_TEST_MODE_ENABLED kill-switch (default FALSE / fail-CLOSED). Gates the whole test-cohort path on top of the secrets — required by testModeConfigured() (checkout routing) and the webhook try-both verify. The on/off decision lives in the flag; the secret values stay in instant-secrets. An operator can kill test-mode routing instantly without rotating keys, and a leftover test plan_id can never silently touch a live customer's billing. test mode for CI, live for prod.

Safety

  • Default-off, fail-closed; live billing path unchanged (live secret verifies first; test branch only runs when the flag is ON).
  • Cohort team + flag OFF → inert synthetic_test_cohort 403 (never the live path).
  • DB blip on is_test_cohort → fail CLOSED to live.

Tests

  • TestPlanIDToTier_MapsTestPlanIDsToCanonicalTier (+ planIDRecognised).
  • Kill-switch inert proofs: TestCohortCheckout_InertWhenFlagOff (403) + TestWebhook_TestSecretIgnoredWhenFlagOff (400).
  • TestTestModeConfigured_InertWhenUnset extended with the flag dimension; existing cohort/webhook tests updated for the flag.

🤖 Generated with Claude Code

claude added 2 commits June 7, 2026 10:48
…D kill-switch

Two fixes for the test-cohort Razorpay checkout path (the with-UI test-card
payment E2E the CEO asked for):

1. planIDToTier / planIDRecognised now recognise the rzp_test_* plan IDs.
   A TEST-mode subscription.activated/charged webhook carries the TEST plan_id;
   previously it matched no live RAZORPAY_PLAN_ID_* and fell back to the safe
   fallback tier ("hobby") + emitted a bogus billing.charge_undeliverable — so
   the full UI card→webhook→Pro chain could NEVER actually reach Pro. Test plans
   exist only in Razorpay test mode, so they can't collide with a live plan_id.

2. PAYMENT_TEST_MODE_ENABLED — explicit kill-switch (default FALSE / fail-CLOSED)
   gating the whole test-cohort path on TOP of the rzp_test_* secrets. Required
   by testModeConfigured() (checkout routing) AND the webhook try-both verify.
   Separates the on/off decision (this flag) from the secret values (which stay
   in instant-secrets), so an operator can kill test-mode routing instantly
   without rotating keys, and a leftover test plan_id can never silently touch a
   live customer's billing.

Tests: test-plan tier mapping (+ recognised), kill-switch inert proofs for both
the checkout (403 synthetic_test_cohort when flag off) and webhook (test secret
ignored when flag off) legs; existing cohort tests updated for the new flag.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ST_* to allKeys

allKeys() (env host-state clearer) was missing the RAZORPAY_TEST_* vars and the
new PAYMENT_TEST_MODE_ENABLED flag, so a leaked host env could bleed into config
tests. Add them + a TestLoad_PaymentTestModeEnabled mirroring the other *_ENABLED
flag tests (100%-patch coverage for the new parse branch).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mastermanas805 mastermanas805 merged commit 232a991 into master Jun 7, 2026
18 checks passed
@mastermanas805 mastermanas805 deleted the fix/billing-test-plan-id-tier-mapping branch June 7, 2026 05:39
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.

2 participants