Skip to content

feat: add max top-up amount limit for Epay and Stripe - #2933

Closed
worryzyy wants to merge 5213 commits into
QuantumNous:mainfrom
worryzyy:feature/add-topup-max-amount-limit
Closed

worryzyy wants to merge 5213 commits into
QuantumNous:mainfrom
worryzyy:feature/add-topup-max-amount-limit

Conversation

@worryzyy

@worryzyy worryzyy commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add configurable maximum top-up amount for both Epay and Stripe payment gateways to prevent users from intentionally placing orders with excessive amounts
  • This is an optional feature: MaxTopUp defaults to 0 (no limit), admins can configure it in payment settings if needed
  • Backend validation with i18n error messages (en, zh-CN, zh-TW)
  • Frontend: inline warning + disable payment buttons when exceeded, skip redundant API calls

Summary by CodeRabbit

  • New Features

    • Added configurable maximum top-up limits with UI controls for general and Stripe-specific settings.
    • Frontend enforces and displays max/min top-up bounds and disables payment options when limits are exceeded.
    • API now surfaces max top-up values so the UI can reflect limits.
  • Internationalization

    • Added localized validation messages for top-up minimum/maximum in multiple languages (en, fr, ja, ru, vi, zh-CN, zh-TW).

seefs001 and others added 30 commits January 12, 2026 18:47
…-auto-disable

feat: status code auto-disable configuration
* fix: setting ui

* fix: rm global.chat_completions_to_responses_policy

* fix: rm global.chat_completions_to_responses_policy
…Names

fix: clean propertyNames for gemini function
…t-param-override

feat: channel testing supports parameter overriding
* feat: codex channel

* feat: codex channel

* feat: codex oauth flow

* feat: codex refresh cred

* feat: codex usage

* fix: codex err message detail

* fix: codex setting ui

* feat: codex refresh cred task

* fix: import err

* fix: codex store must be false

* fix: chat -> responses tool call

* fix: chat -> responses tool call
…sing Claude's rendering logs, the two approaches handle input rendering differently.
common.GetRequestBody(c) read bod is null
Calcium-Ion and others added 21 commits February 8, 2026 23:53
…inity-tips

optimize: channel affinity tips
Replace icon-based language options with plain text labels in both the
header dropdown and preferences settings to keep the UI clean and
avoid potential controversies. Remove unused country-flag-icons dependency.
Bumps [axios](https://github.com/axios/axios) from 1.12.0 to 1.13.5.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v1.12.0...v1.13.5)

---
updated-dependencies:
- dependency-name: axios
  dependency-version: 1.13.5
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
…nd_yarn/web/axios-1.13.5

chore(deps): bump axios from 1.12.0 to 1.13.5 in /web
* feat(localization): added zh_TW

* fixed based on @coderabbitai

* updated false translation for zh_TW

* new workflow

* revert

* fixed a lot of translations

* turned most zh to zh-CN

* fallbacklang

* bruh

* eliminate ALL _

* fix: paths and other miscs thanks @Calcium-Ion

* fixed translation and temp fix for preferencessettings.js

* fixed translation error

* fixed issue about legacy support

* reverted stupid coderabbit's suggestion
* feat: logs cache field

* feat: logs cache field

* feat: logs cache field
# Conflicts:
#	README.fr.md
#	README.ja.md
#	README.md
#	README.zh_CN.md
* feat(xai): 为xAI渠道添加/v1/responses支持

* Add video generation model to constants

* fix: 修正先前更改中对于grok-3-mini的思考预算和"-search"设计
…mount-input

feat(user): add currency amount input with auto quota conversion
* perf: task log show userinfo

* feat: add Tooltip component to TaskLogsColumnDefs
@coderabbitai

coderabbitai Bot commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Backend and frontend now support configurable maximum top-up limits. Controllers return max_topup/stripe_max_topup and perform localized min/max validations. Frontend components receive and enforce max bounds and display related i18n messages. Admin settings/pages expose MaxTopUp and StripeMaxTopUp configuration fields.

Changes

Cohort / File(s) Summary
Backend Top-Up Controllers
controller/topup.go, controller/topup_stripe.go
Added getMaxTopup() and getStripeMaxTopup() helpers; include max_topup and stripe_max_topup in GetTopUpInfo; apply max/top-up validation and replace hard-coded messages with i18n keys for too-low/too-high amounts.
Backend i18n
i18n/keys.go, i18n/locales/en.yaml, i18n/locales/zh-CN.yaml, i18n/locales/zh-TW.yaml
Added i18n keys topup.amount_too_low and topup.amount_too_high and translations with {{.Min}}/{{.Max}} placeholders.
Backend Config / Options
setting/payment_stripe.go, setting/operation_setting/payment_setting.go, model/option.go
Added StripeMaxTopUp and MaxTopUp config fields (default 0 = no limit) and wired option initialization/update to handle them.
Frontend Top-Up UI
web/src/components/topup/RechargeCard.jsx, web/src/components/topup/index.jsx
Expose and consume maxTopUp prop/state; show max in placeholders, block/tooltip payment options when amount > max, and enforce max in multiple flows (preTopUp, getAmount/getStripeAmount, onlineTopUp).
Frontend Admin Pages
web/src/pages/Setting/Payment/SettingsPaymentGateway.jsx, web/src/pages/Setting/Payment/SettingsPaymentGatewayStripe.jsx
Added input fields for MaxTopUp and StripeMaxTopUp with client-side validation (max must not be less than min) and include values in submission payload.
Frontend i18n
web/src/i18n/locales/*.json (en.json,fr.json,ja.json,ru.json,vi.json,zh-CN.json,zh-TW.json)
Added translation entries for upper-bound messages, "maximum" label, and "0 means no limit" across locales to support UI display of max-topup constraints.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(240,248,255,0.5)
    participant User
    end
    rect rgba(224,255,255,0.5)
    participant Frontend
    end
    rect rgba(255,240,245,0.5)
    participant Backend
    end
    rect rgba(240,255,240,0.5)
    participant Settings
    end
    User->>Frontend: Enter top-up amount & choose method
    Frontend->>Frontend: validate >= min && (<= maxTopUp if >0)
    alt Frontend detects invalid
        Frontend-->>User: show i18n validation error (min/max)
    else valid locally
        Frontend->>Backend: getAmount / request top-up
        Backend->>Settings: read MaxTopUp / StripeMaxTopUp and quota display type
        Settings-->>Backend: return configured limits
        Backend->>Backend: validate amount against min and computed max (with i18n messages)
        alt Backend invalid
            Backend-->>Frontend: error with localized message
            Frontend-->>User: display error
        else valid
            Backend-->>Frontend: success / payment payload (proceed to stripe/pay)
            Frontend->>User: show payment UI / proceed
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion
  • creamlike1024

Poem

🐰 I hopped through code, with keys in paw,
Max and min I checked with law,
i18n sang each bound so sweet,
Settings set the limit neat,
Now top-ups rest in tidy order—hop hooray! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and accurately describes the main feature: adding a configurable maximum top-up amount limit for both Epay and Stripe payment gateways.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
model/option.go (1)

343-356: ⚠️ Potential issue | 🟡 Minor

Clamp negative MaxTopUp values to avoid blocking all top-ups.
Because 0 means “no limit,” a negative value (e.g., misconfigured -1) would effectively reject every top-up. Consider clamping to 0 (or rejecting) when parsing.

✅ Proposed fix (clamp to 0)
 case "MaxTopUp":
-	operation_setting.MaxTopUp, _ = strconv.Atoi(value)
+	maxVal, _ := strconv.Atoi(value)
+	if maxVal < 0 {
+		maxVal = 0
+	}
+	operation_setting.MaxTopUp = maxVal
@@
 case "StripeMaxTopUp":
-	setting.StripeMaxTopUp, _ = strconv.Atoi(value)
+	stripeMax, _ := strconv.Atoi(value)
+	if stripeMax < 0 {
+		stripeMax = 0
+	}
+	setting.StripeMaxTopUp = stripeMax
controller/topup.go (1)

55-65: ⚠️ Potential issue | 🟠 Major

Potential mismatch between API response values and backend validation when QuotaDisplayType is TOKENS.

max_topup (line 59) returns the raw operation_setting.MaxTopUp value (in USD units), but getMaxTopup() (used for server-side validation) converts it to token units when the display type is TOKENS. The frontend uses the raw API value for client-side validation against user input that's in display units, which would cause a mismatch when the display type is TOKENS.

This appears to be a pre-existing pattern (same issue exists for min_topup on line 58), so it's not a regression introduced by this PR, but worth noting for correctness.

Consider returning the converted values in the API response:

Suggested fix
 		"min_topup":           operation_setting.MinTopUp,
-		"max_topup":           operation_setting.MaxTopUp,
+		"max_topup":           getMaxTopup(),
 		"stripe_min_topup":    setting.StripeMinTopUp,
-		"stripe_max_topup":    setting.StripeMaxTopUp,
+		"stripe_max_topup":    getStripeMaxTopup(),
🤖 Fix all issues with AI agents
In `@setting/operation_setting/payment_setting_old.go`:
- Line 18: Remove the stray global variable MaxTopUp from payment_setting_old.go
and add it as a field on the PaymentSetting struct in payment_setting.go (e.g.,
MaxTopUp int with same semantics: 0 means no limit); update any constructors or
JSON/YAML tags and defaulting logic for PaymentSetting to initialize/serialize
this new field and update any code references to use paymentSetting.MaxTopUp
instead of the removed global variable.

In `@web/src/components/topup/index.jsx`:
- Around line 200-203: Add an upper-bound guard to prevent submissions when the
amount exceeds maxTopUp: in the block that currently checks topUpCount <
minTopUp (using variables topUpCount, minTopUp, maxTopUp and function
showError), also validate if topUpCount > maxTopUp, call showError with a
suitable message and return early to avoid opening the confirm modal or sending
requests; apply the same maxTopUp guard inside preTopUp so the pre-check and
confirm flow both reject values above maxTopUp.

In `@web/src/components/topup/RechargeCard.jsx`:
- Around line 347-354: The tooltip uses the raw maxTopUp while elsewhere (line
~292) the UI uses renderQuotaWithAmount(maxTopUp); update the Tooltip content to
use renderQuotaWithAmount(maxTopUp) instead of raw maxTopUp so the max limit is
consistently formatted; locate the Tooltip in RechargeCard.jsx and replace the
unformatted maxTopUp reference with a call to renderQuotaWithAmount(maxTopUp)
(keep the same i18n string concatenation logic).

In `@web/src/pages/Setting/Payment/SettingsPaymentGateway.jsx`:
- Around line 164-166: Before adding MaxTopUp to the options array, validate
that inputs.MaxTopUp is not less than inputs.MinTopUp; if it is, prevent
submission and surface a user-facing error (e.g., set a form validation error or
show a toast) so the invalid configuration cannot be saved. Update the logic
around the options.push for 'MaxTopUp' in SettingsPaymentGateway.jsx to check
inputs.MinTopUp and inputs.MaxTopUp, and only push the MaxTopUp option when
MaxTopUp >= MinTopUp; otherwise block the save flow and display the validation
message.

In `@web/src/pages/Setting/Payment/SettingsPaymentGatewayStripe.jsx`:
- Around line 127-135: Before pushing the StripeMaxTopUp option, validate that
inputs.StripeMaxTopUp is not a positive number smaller than
inputs.StripeMinTopUp; if inputs.StripeMaxTopUp > 0 && inputs.StripeMaxTopUp <
inputs.StripeMinTopUp, prevent the save (do not push into options) and surface a
clear validation error to the user using the component's existing error/display
mechanism (e.g., set form error or show toast). Update the block around
inputs.StripeMaxTopUp/options so the validation runs prior to adding the option
and returns early on failure with a user-facing message like "Max top-up must be
>= Min top-up."

Comment thread web/src/components/topup/index.jsx Resolved

@coderabbitai coderabbitai Bot 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/src/pages/Setting/Payment/SettingsPaymentGateway.jsx (1)

146-173: ⚠️ Potential issue | 🟡 Minor

null value from cleared InputNumber would crash on .toString().

Semi UI's InputNumber can yield null when the user clears the field. The guard on line 171 checks !== '' and !== undefined but not !== null, so null.toString() at line 172 would throw a runtime error.

Proposed fix
-    if (inputs.MaxTopUp !== '' && inputs.MaxTopUp !== undefined) {
+    if (inputs.MaxTopUp != null && inputs.MaxTopUp !== '') {
       options.push({ key: 'MaxTopUp', value: inputs.MaxTopUp.toString() });
     }

Same null guard should be applied to the validation block:

-    if (inputs.MaxTopUp !== '' && inputs.MaxTopUp !== undefined) {
+    if (inputs.MaxTopUp != null && inputs.MaxTopUp !== '') {
       if (inputs.MaxTopUp > 0 && inputs.MaxTopUp < inputs.MinTopUp) {
🤖 Fix all issues with AI agents
In `@web/src/components/topup/index.jsx`:
- Around line 588-590: The check that returns early when value > maxTopUp leaves
the previous computed amount displayed; update the amount state to a cleared
value before returning so the UI doesn't show a stale payment amount (i.e., set
the component's amount/state to an empty/zero value whenever value > maxTopUp),
and apply the same change to the getStripeAmount function where it does the same
value > maxTopUp early return; ensure you reference and update the shared amount
state (the amount variable/state setter) in both places before the return.
🧹 Nitpick comments (3)
controller/topup.go (1)

151-158: getMinTopup() is called twice — consider caching in a local variable.

Both getMinTopup() (lines 151-152) and getMaxTopup() (line 155) perform setting lookups and potential arithmetic. Storing the result avoids redundant computation and a theoretical TOCTOU inconsistency if the setting changes between calls.

The same pattern appears in RequestAmount (lines 343-348).

♻️ Suggested refactor
 func RequestEpay(c *gin.Context) {
 	var req EpayRequest
 	err := c.ShouldBindJSON(&req)
 	if err != nil {
 		c.JSON(200, gin.H{"message": "error", "data": "参数错误"})
 		return
 	}
-	if req.Amount < getMinTopup() {
-		c.JSON(200, gin.H{"message": "error", "data": i18n.T(c, i18n.MsgTopupAmountTooLow, map[string]any{"Min": getMinTopup()})})
+	minTopup := getMinTopup()
+	if req.Amount < minTopup {
+		c.JSON(200, gin.H{"message": "error", "data": i18n.T(c, i18n.MsgTopupAmountTooLow, map[string]any{"Min": minTopup})})
 		return
 	}
web/src/i18n/locales/ja.json (1)

438-442: New i18n keys break the file's existing sort order.

The five new keys are grouped together near "充值数量不能小于", but the rest of the file is sorted. For example, "0 表示不限制" should be near line 31–33 with other "0…" keys, and "最高充值数量" belongs near other "最…" entries (around line 512). Consider running the project's i18n sort tooling (bun run i18n:*) to re-sort the file and keep it consistent with existing conventions.

web/src/components/topup/index.jsx (1)

204-211: Inconsistent formatting between min and max error messages.

The min-topup error displays a raw number (minTopUp), while the max-topup error uses renderQuotaWithAmount(maxTopUp) which prepends a currency symbol (e.g., $5). The same inconsistency exists in preTopUp (lines 176 vs 180). Consider using renderQuotaWithAmount for both or neither, so users see a uniform format.

Proposed fix
     if (topUpCount < minTopUp) {
-      showError(t('充值数量不能小于') + minTopUp);
+      showError(t('充值数量不能小于') + ' ' + renderQuotaWithAmount(minTopUp));
       return;
     }

Apply the same in preTopUp at line 176.

Comment on lines +588 to +590
if (maxTopUp > 0 && value > maxTopUp) {
return;
}

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.

⚠️ Potential issue | 🟡 Minor

Stale amount displayed when the entered value exceeds the max.

When value > maxTopUp, the function returns without updating amount. If the user previously entered a valid value (e.g., $50 → amount shows ¥365), then changes to an invalid value exceeding maxTopUp, the old payment amount remains displayed — potentially misleading.

Consider resetting the amount before returning:

Proposed fix
     if (maxTopUp > 0 && value > maxTopUp) {
+      setAmount(0);
       return;
     }

Apply the same in getStripeAmount (line 617–619).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (maxTopUp > 0 && value > maxTopUp) {
return;
}
if (maxTopUp > 0 && value > maxTopUp) {
setAmount(0);
return;
}
🤖 Prompt for AI Agents
In `@web/src/components/topup/index.jsx` around lines 588 - 590, The check that
returns early when value > maxTopUp leaves the previous computed amount
displayed; update the amount state to a cleared value before returning so the UI
doesn't show a stale payment amount (i.e., set the component's amount/state to
an empty/zero value whenever value > maxTopUp), and apply the same change to the
getStripeAmount function where it does the same value > maxTopUp early return;
ensure you reference and update the shared amount state (the amount
variable/state setter) in both places before the return.

@coderabbitai coderabbitai Bot 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 `@web/src/i18n/locales/en.json`:
- Around line 440-442: Update the English copy for consistency and safe
concatenation: change the values for "充值数量不能大于" and "最高充值数量不能小于最低充值数量" from
using "top-up" to "top up" so styling matches adjacent messages, and add a
trailing space to the value of ",最高 " (currently ", maximum") so it becomes ",
maximum " to prevent words/values like "maximum20" when concatenated; adjust
these three string values accordingly in en.json.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22d7c16 and 34fd64f.

📒 Files selected for processing (7)
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/fr.json
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/ru.json
  • web/src/i18n/locales/vi.json
  • web/src/i18n/locales/zh-CN.json
  • web/src/i18n/locales/zh-TW.json
🚧 Files skipped from review as they are similar to previous changes (6)
  • web/src/i18n/locales/ru.json
  • web/src/i18n/locales/zh-TW.json
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/zh-CN.json
  • web/src/i18n/locales/vi.json
  • web/src/i18n/locales/fr.json

Comment on lines +440 to +442
"充值数量不能大于": "The top up amount cannot be greater than",
"最高充值数量不能小于最低充值数量": "Maximum top-up amount cannot be less than minimum top-up amount",
",最高 ": ", maximum",

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.

⚠️ Potential issue | 🟡 Minor

Fix spacing and wording consistency for concatenated max-limit text.

The fragment on Line 442 should include a trailing space for safe concatenation (otherwise UI may render like maximum20). Also, Line 441 uses top-up while adjacent messages use top up; pick one style for consistency.

✏️ Suggested copy fix
-    "最高充值数量不能小于最低充值数量": "Maximum top-up amount cannot be less than minimum top-up amount",
-    ",最高 ": ", maximum",
+    "最高充值数量不能小于最低充值数量": "Maximum top up amount cannot be less than minimum top up amount",
+    ",最高 ": ", maximum ",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/src/i18n/locales/en.json` around lines 440 - 442, Update the English copy
for consistency and safe concatenation: change the values for "充值数量不能大于" and
"最高充值数量不能小于最低充值数量" from using "top-up" to "top up" so styling matches adjacent
messages, and add a trailing space to the value of ",最高 " (currently ",
maximum") so it becomes ", maximum " to prevent words/values like "maximum20"
when concatenated; adjust these three string values accordingly in en.json.

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.