Skip to content

feat: beta payment lockdown, redemption code system, and admin subscription bugfix#235

Merged
dvlin-dev merged 5 commits intomainfrom
feat/beta-payment-lockdown-and-redemption-codes
Mar 16, 2026
Merged

feat: beta payment lockdown, redemption code system, and admin subscription bugfix#235
dvlin-dev merged 5 commits intomainfrom
feat/beta-payment-lockdown-and-redemption-codes

Conversation

@dvlin-dev
Copy link
Copy Markdown
Owner

@dvlin-dev dvlin-dev commented Mar 16, 2026

Summary

  • Disable real payment flows in PC app during beta (usePurchase hook short-circuit + BetaNotice inline text with clickable Discord link)
  • Add Discord community entry in Settings > About
  • Add redemption code system: admin CRUD + user-facing redeem dialog, support CREDITS and MEMBERSHIP code types
  • Fix admin updateSubscription to sync Quota on tier/status changes (status semantics take priority)
  • Extract activateSubscriptionWithQuota/deactivateSubscriptionToFree shared functions
  • Add Prisma migration for RedemptionCode + RedemptionCodeUsage models

Changes by area

Server (apps/anyhunt/server): Prisma schema + migration, subscription-activation.ts shared functions, payment.service.ts refactor, admin.service.ts bugfix, redemption module (DTO + service + controllers + module), OpenAPI registration

PC App (apps/moryflow/pc): usePurchase short-circuit, BetaNotice component, Discord in About, RedeemCodeDialog (RHF+zod), user-profile integration

Admin Frontend (apps/anyhunt/admin/www): redemption-codes feature (12 files), RedemptionCodesPage, route registration

i18n (packages/i18n): settings + auth keys for all 5 locales

Test plan

  • TypeScript compilation passes (pre-commit hook)
  • 1654 unit tests pass (pre-commit hook)
  • Manual: PC app purchase buttons show toast, BetaNotice visible with clickable Discord link
  • Manual: Redeem code dialog opens, submits, refreshes user info
  • Manual: Admin redemption codes page renders, CRUD works
  • Deploy: Prisma migration runs successfully on production database

Open with Devin

…iption bugfix

- Disable real payment flows in PC app during beta (usePurchase hook short-circuit + BetaNotice inline text with clickable Discord link)
- Add Discord community entry in Settings > About
- Add redemption code system: admin CRUD for creating/managing codes, user-facing redeem dialog in account center
- Support two code types: CREDITS (grant purchased quota) and MEMBERSHIP (activate subscription tier)
- Multi-use codes with per-account single-use enforcement (@@unique constraint + atomic counter)
- Extract activateSubscriptionWithQuota/deactivateSubscriptionToFree shared functions from payment.service.ts
- Fix admin updateSubscription to sync Quota on tier/status changes (status semantics take priority)
- Add admin redemption codes management page with full CRUD, filters, and usage history
- Register RedemptionModule in app.module.ts and openapi-modules.ts
- Add Prisma migration for RedemptionCode + RedemptionCodeUsage models
- Add unit tests for redemption service and admin subscription update
devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

- Guard EXPIRED/CANCELED branches with statusChanged to prevent tier-only
  changes on expired/canceled subscriptions from taking wrong path
- Move subscription findUnique inside $transaction to prevent TOCTOU race
- Preserve non-ACTIVE status (e.g., PAST_DUE) when admin changes tier only
- Allow clearing expiresAt (nullable) in server-side updateRedemptionCodeSchema
devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…pty string

- When tier changes, apply intended status (explicit or preserved) after
  activateSubscriptionWithQuota, covering PAST_DUE and all non-ACTIVE states
- Convert empty expiresAt string to null before sending to server in edit flow
devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…validate membershipDays

- Create dedicated anyhunt apiClient for redemption (PC app connects to server.anyhunt.app)
- Add ANYHUNT_API_URL constant with VITE_ANYHUNT_API_URL env override
- Catch P2002 on createCode and return 409 instead of 500 for duplicate custom codes
- Add membershipDays to MEMBERSHIP type validation in admin frontend schema
devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…nd consistency

- Add internal API Key-authenticated redeem endpoint on anyhunt server
  (POST /api/v1/redemption-codes/redeem with ApiKeyGuard)
- Add redemption proxy module to moryflow server that forwards redeem
  requests to anyhunt server using ANYHUNT_API_KEY
- Revert PC app to use moryflow server apiClient (no cross-domain auth)
- Fix cancelAtPeriodEnd consistency: restoring CANCELED status after tier
  change now also sets cancelAtPeriodEnd: true

Request flow: PC app -> moryflow server (user auth) -> anyhunt server (API Key)
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 new potential issues.

🐛 3 issues in files not directly in the diff

🐛 CLAUDE.md for admin features not updated with new redemption-codes module (apps/anyhunt/admin/www/src/features/CLAUDE.md:1)

The apps/anyhunt/admin/www/src/features/CLAUDE.md has the mandatory rule: "⚠️ 本目录结构变更时,必须同步更新此文档。" A new redemption-codes/ feature module was added to this directory, but the CLAUDE.md's feature list table was not updated to include it.


🐛 CLAUDE.md for payment directory not updated with new subscription-activation.ts (apps/anyhunt/server/src/payment/CLAUDE.md:1)

The apps/anyhunt/server/src/payment/CLAUDE.md has the mandatory rule: "This folder structure changes require updating this document." A new file subscription-activation.ts was added to this directory, but the CLAUDE.md's File Structure table was not updated to include it.


🐛 CLAUDE.md for admin www not updated with new RedemptionCodesPage (apps/anyhunt/admin/www/CLAUDE.md:1)

The apps/anyhunt/admin/www/CLAUDE.md has the mandatory rule: "⚠️ 本文件夹结构变更时,必须同步更新此文档". A new RedemptionCodesPage was added and a new feature module redemption-codes/ was created, but the CLAUDE.md's Pages table, Feature List, and related sections were not updated.

View 12 additional findings in Devin Review.

Open in Devin Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a64443062

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/moryflow/server/src/redemption/redemption-proxy.service.ts
@dvlin-dev dvlin-dev merged commit 24ae6f2 into main Mar 16, 2026
2 checks passed
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