Skip to content

feat(payments): redeem a promotion code onto an existing subscription - #23588

Merged
mdmohsin7 merged 5 commits into
mainfrom
rex/promo-redeem-trial
Oct 25, 2026
Merged

mdmohsin7 merged 5 commits into
mainfrom
rex/promo-redeem-trial

Conversation

@mdmohsin7

@mdmohsin7 mdmohsin7 commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Refs #23299. Unlimited yearly activation codes carry a minimum order amount. A first-time buyer's checkout starts with a 7-day free trial, so the total due today is zero, and Stripe rejects the code against that zero in every currency ("your order doesn't meet the minimum amount"). Stripe also refuses codes with a minimum on subscription updates.

This adds POST /v1/payments/redeem-code (routers/redeem_code.py). The buyer starts the plan (trial or paid) without the code, then redeems the code onto that subscription:

  • The code must be active and unused, and its restrictions are checked against the plan price itself: coupon product, minimum amount, customer, expiry.
  • The code's coupon is attached to the subscription, so the discount lands on the first invoice after the trial. A preview of a trialing yearly subscription's next invoice with the coupon comes to $0.
  • A Firestore claim keyed by the promotion code id keeps each code single-use, since Stripe doesn't count a coupon applied this way as a redemption. The promotion code is also deactivated, with the redeeming user and subscription in its metadata. If the Stripe update fails, the code is reactivated and the claim released.
  • Rate limited to 10 attempts an hour per user.

The web app's plan settings get a "Redeem a code" field while a subscription exists, so this works without an app release.

Redeem a code

Product invariants

none

Test plan

  • tests/unit/test_promotion_redemption.py: trial redemption attaches the coupon and uses up the code; monthly (below the minimum), another product, unknown, used and expired codes, a lost claim race, canceled or canceling subscriptions and an existing discount are refused; a failed Stripe update gives the code back; the endpoint returns refusals as client errors.
  • tests/unit/test_payment_checkout_trial.py
  • Firestore index guard set (790 passed), app-client OpenAPI compatibility against origin/main
  • web/app: bun run typecheck, vitest src/components/settings
  • After deploy: start the yearly trial, redeem a code on the web app, confirm the upcoming invoice is $0.

Failure-Class: none

🤖 Generated with Claude Code

A code with a minimum amount can't be entered at a free-trial checkout:
Stripe checks the minimum against today's total, which is zero during the
trial. POST /v1/payments/redeem-code checks the code against the plan price
and attaches its coupon to the caller's subscription, so the discount lands
on the first invoice after the trial. A Firestore claim keeps each code
single-use. The web app's plan settings get a Redeem a code field.
@mintlify

mintlify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Oct 25, 2026, 11:27 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@mdmohsin7
mdmohsin7 merged commit 216b20b into main Oct 25, 2026
61 checks passed
@mdmohsin7
mdmohsin7 deleted the rex/promo-redeem-trial branch October 25, 2026 12:07
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