feat: support redeeming subscription plans with redemption codes - #3207
feat: support redeeming subscription plans with redemption codes#3207mxyhi wants to merge 5412 commits into
Conversation
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
feat: channel test with stream=true
fix: 使用openai兼容接口调用部分渠道在最终端点为claude原生端点下还是走了openai扣减input_token的逻辑
fix: 补全 streaming message_delta 事件缺失的 input_tokens 和 cache 相关字段
feat: /v1/messages -> /v1/responses
…rable feat: make 5m cache-creation ratio configurable
fix: 如果模型管理有自定义配置则不合并默认配置
fix: 修复模型管理"参与官方同步"与"状态"开关无法保存的问题
left a comment
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
controller/redemption.gocontroller/redemption_test.gomodel/redemption.gomodel/redemption_test.goweb/src/components/topup/index.jsxweb/src/i18n/locales/en.jsonweb/src/i18n/locales/zh-CN.json
🚧 Files skipped from review as they are similar to previous changes (1)
- web/src/i18n/locales/en.json
left a comment
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
controller/redemption.gocontroller/redemption_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- controller/redemption.go
chore: update model lists for frequently used channels
…tion links and submission checks
Round remaining balance
enhance channel key viewing
- 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
commented
Mar 16, 2026
|
I hope to pass this PR, open source should be inclusive. |
commented
Mar 16, 2026
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 |
commented
Mar 17, 2026
Hope you would release a docker image to docker hub. |
Summary
/api/user/topupflow and admin redemption management UI instead of adding a separate subscription-code moduleTesting
Closes #2845
Summary by CodeRabbit
New Features
Improvements
Tests
Documentation