Skip to content

feat: support redeeming subscription plans with redemption codes - #3207

Closed
mxyhi wants to merge 5412 commits into
QuantumNous:mainfrom
mxyhi:feat/redemption-subscription-codes
Closed

feat: support redeeming subscription plans with redemption codes#3207
mxyhi wants to merge 5412 commits into
QuantumNous:mainfrom
mxyhi:feat/redemption-subscription-codes

Conversation

@mxyhi

@mxyhi mxyhi commented Mar 11, 2026

Copy link
Copy Markdown

Summary

  • add redemption code types so a code can either top up quota or activate a subscription plan
  • reuse the existing /api/user/topup flow and admin redemption management UI instead of adding a separate subscription-code module
  • update the console redemption form/list and user success messaging, and add model tests for both redemption paths

Testing

  • go test ./...
  • cd web && bun run build
  • cd web && bunx eslint src/constants/redemption.constants.js src/components/table/redemptions/RedemptionsColumnDefs.jsx src/components/table/redemptions/modals/EditRedemptionModal.jsx src/components/topup/index.jsx src/components/topup/RechargeCard.jsx

Closes #2845

Summary by CodeRabbit

  • New Features

    • Redemption codes now support two types: quota and subscription; subscription codes can activate plans and show plan details.
  • Improvements

    • Admin edit modal: choose type, pick subscription plan, name auto-fills from plan when appropriate.
    • Redeem flow and success UI display type-specific results (activated plan + expiry or redeemed quota).
    • List/table shows type and content; top-up UI text clarified.
  • Tests

    • Added tests for quota and subscription redemption scenarios.
  • Documentation

    • Added English and Chinese translations for redemption UI.

t0ng7u and others added 30 commits February 7, 2026 00:57
Add a lightweight active-subscription check to skip subscription pre-consume when none exist, reducing unnecessary transactions and locks. In the subscription UI, disable subscription-first options when no active plan is available, show the effective fallback to wallet with a clear notice, and distinguish “invalidated” from “expired” states. Update i18n strings across supported locales to reflect the new messages and status labels.
Aligns the error variable types in the subscription-first path so that quota fallback checks use the correct NewAPIError.
This prevents build failures and preserves the intended wallet fallback when subscription pre-consume returns an insufficient quota error.
Routes quota alerts through a subscription-specific check when billing from subscriptions, preventing wallet-based thresholds from triggering false warnings.
Updates the notification settings description and localization keys to clarify that both wallet and subscription balances are monitored.
🔔 feat: Add subscription-aware quota notifications and update UI copy
…-fallback

✨ chore: Improve subscription billing fallback and UI states
当上游为 AWS Bedrock 时,message_delta 的 usage 可能缺少 input_tokens、
cache_creation_input_tokens、cache_read_input_tokens 等字段,导致与原生
Anthropic 格式不一致。从 message_start 积累的 claudeInfo 中补全这些字段后
重新序列化,确保客户端收到一致的 usage 格式。
Modified the formatUserLogs function to include a startIdx parameter, allowing for more flexible log ID assignment. Updated calls to this function in GetLogByTokenId and GetUserLogs to pass the appropriate starting index.
feat: add Codex channel disclaimer (i18n, OpenAI terms)
feat: Force beta=true parameter for Anthropic channel
feat(oauth): implement custom OAuth provider
fix: Claude stream block index/type transitions
fix: add paragraph breaks between reasoning summary chunks
# Conflicts:
#	service/openaicompat/chat_to_responses.go
fix: 使用openai兼容接口调用部分渠道在最终端点为claude原生端点下还是走了openai扣减input_token的逻辑
fix: 补全 streaming message_delta 事件缺失的 input_tokens 和 cache 相关字段
…rable

feat: make 5m cache-creation ratio configurable
fix: 如果模型管理有自定义配置则不合并默认配置
fix: 修复模型管理"参与官方同步"与"状态"开关无法保存的问题

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@controller/redemption.go`:
- Around line 16-44: In validateRedemptionDefinition, after calling
model.GetSubscriptionPlanById(redemption.SubscriptionPlanId) and before using
the plan, verify the plan is enabled (check plan.Enabled); if it's not enabled
call common.ApiErrorMsg(c, "订阅套餐不可用") (or similar message consistent with other
handlers) and return nil, false so disabled plans cannot be linked to redemption
codes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 07e10ec9-377d-497f-850b-b18b685bed92

📥 Commits

Reviewing files that changed from the base of the PR and between 5083df5 and f5a8561.

📒 Files selected for processing (7)
  • controller/redemption.go
  • controller/redemption_test.go
  • model/redemption.go
  • model/redemption_test.go
  • web/src/components/topup/index.jsx
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/zh-CN.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/i18n/locales/en.json

Comment thread controller/redemption.go

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@controller/redemption_test.go`:
- Around line 21-59: The setup mutates globals (gin mode, model.DB,
model.LOG_DB, common.UsingSQLite/UsingPostgreSQL/UsingMySQL/common.RedisEnabled)
before registering t.Cleanup, and it never restores gin mode; fix by capturing
prevMode := gin.Mode() and all old* values immediately, register t.Cleanup right
away (before calling gorm.Open or require.NoError), then perform the mutations
and migrations; in the cleanup restore gin.SetMode(prevMode), model.DB,
model.LOG_DB and the common.* flags and only attempt to close sqlDB if db was
successfully opened. Ensure the cleanup closure references the same old
variables you saved at the top so every exit path restores state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4b62f7eb-58d8-4232-84c2-6fd4952210af

📥 Commits

Reviewing files that changed from the base of the PR and between f5a8561 and 9754a4d.

📒 Files selected for processing (2)
  • controller/redemption.go
  • controller/redemption_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/redemption.go

Comment thread controller/redemption_test.go Outdated
mxyhi and others added 21 commits March 11, 2026 14:09
chore: update model lists for frequently used channels
- add findings.md, progress.md, and task_plan.md to gitignore
- prevent local task notes from being committed accidentally
- sort group names before responding to ensure deterministic output
- prevent unordered map iteration from causing inconsistent API results

✅ test(group): add sorted groups response test

- verify GetGroups always returns group names in ascending order
- repeat assertions to guard against non-deterministic map iteration
@kinzhi

ghost commented Mar 16, 2026

Copy link
Copy Markdown

I hope to pass this PR, open source should be inclusive.

@mxyhi

ghost commented Mar 16, 2026

Copy link
Copy Markdown
Author

I hope to pass this PR, open source should be inclusive.

The main branch of the repository I forked has already been implemented. I will maintain it in parallel and periodically synchronize the feature updates from the upstream main branch.

mxyhi/new-api

@Betavion

ghost commented Mar 17, 2026

Copy link
Copy Markdown

I hope to pass this PR, open source should be inclusive.我希望这个 PR 能通过,开源应当具有包容性。

The main branch of the repository I forked has already been implemented. I will maintain it in parallel and periodically synchronize the feature updates from the upstream main branch.我 fork 的仓库主分支已经实现了该功能。我会并行维护它,并定期同步上游主分支的功能更新。

mxyhi/new-api

Hope you would release a docker image to docker hub.

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.

希望增加兑换码(订阅码)兑换订阅套餐的功能