You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(topup): match highest qualifying amount discount threshold - #8438
本地验证: 已按变更路径实际验证,并写明命令与观察结果。仅声明 go build 通过或测试通过,不视为有效证明。
安全合规: 代码中无敏感凭据,且符合项目代码规范。
Summary by CodeRabbit
New Features
Recharge discounts now apply by amount tier: eligible payments receive the rate for the highest qualifying threshold, including between configured tiers.
Discount handling reflects the selected payment method, with Stripe continuing to use exact-amount matches.
Recharge presets display savings based on the applicable discount rate.
Bug Fixes
Savings labels are no longer shown when the discount does not result in a positive displayed percentage.
Discounted payment amounts now use consistent tier matching across supported recharge methods.
No actionable comments were generated in the recent review.
Walkthrough
Backend top-up calculations and wallet discount handling now use the highest qualifying positive discount threshold. Stripe retains exact-amount matching in the wallet. Wallet preset displays and discount labels reflect the selected discount rate.
MatchAmountDiscount selects the rate for the greatest positive threshold at or below the amount. It returns 1.0 when no threshold matches. Tests cover tier selection and fallback cases.
Wallet helpers use threshold matching for non-Stripe payment types and exact-key matching for Stripe. Preset merging uses the matched rate, and discount labels suppress non-positive discounts. Tests cover matching and preset discounts.
Wallet payment selection and display web/src/features/wallet/components/recharge-form-card.tsx, web/src/features/wallet/index.tsx, web/src/features/wallet/__tests__/copy.test.tsx
The wallet passes the active payment type to preset cards. Cards select the corresponding discount behavior. Rendering tests cover Stripe-only and multi-gateway configurations.
QuantumNous/new-api#8400: This PR implements the same tiered amount-discount matching behavior in backend calculations and wallet discount handling.
Suggested reviewers: seefs001, calcium-ion
Merge Risk: Minimal · up to 3ca48
The change makes top-up discounts follow the highest qualifying tier for Epay, Waffo, and Waffo Pancake, while Stripe keeps exact matching. The tests reported for the matcher, gateway calculations, and wallet display cover the changed behavior, so merge risk is minimal.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "feat(topup): match highest qualifying amount discount threshold" describes the main change. The PR replaces exact-key AmountDiscount lookup with largest qualifying threshold matching (Match…
Linked Issues check
Issue #8436 requires selecting the largest threshold k with 0 < k <= amount and rate > 0, otherwise returning 1.0. At head 3ca4865, PaymentSetting.MatchAmountDiscount in setting/operation_setting/paym…
Out of Scope Changes check
The changed files relate to the tiered AmountDiscount feature. The backend matcher and the three gateway pricing functions implement the issue. The cross-gateway and matcher tests verify that feature.…
Full details: Title check
Explanation
The title "feat(topup): match highest qualifying amount discount threshold" describes the main change. The PR replaces exact-key AmountDiscount lookup with largest qualifying threshold matching (MatchAmountDiscount) for Epay, Waffo, and Waffo Pancake, and keeps exact matching for Stripe. The wallet UI discount display also follows the active payment type. The title is specific and concise, and it follows a conventional commit style.
Full details: Linked Issues check
Explanation
Issue #8436 requires selecting the largest threshold k with 0 < k <= amount and rate > 0, otherwise returning 1.0. At head 3ca4865, PaymentSetting.MatchAmountDiscount in setting/operation_setting/payment_setting.go implements this rule. It returns 1.0 for a nil receiver, amount <= 0, an empty map, or no qualifying threshold. The head source of controller/topup.go shows getPayMoney calling MatchAmountDiscount(amount), which covers Epay. The PR summary states the same call in getWaffoPayMoney (controller/topup_waffo.go) and getWaffoPancakePayMoney (controller/topup_waffo_pancake.go). Stripe (controller/topup_stripe.go) is not in the changed files and keeps exact-key matching, as the issue requires. Frontend helpers in web/src/features/wallet/lib/format.ts (getMatchedAmountDiscount, getDiscountRateForPaymentType) apply threshold matching to non-Stripe types and exact lookup to Stripe. mergePresetAmounts, the Wallet callback, and RechargeFormCard use these helpers for preset cards and payable amounts. Automated tests cover the matcher (TestPaymentSettingMatchAmountDiscount), cross-gateway pricing, and frontend display (copy.test.tsx). Limits: the incremental diff from previous head 73fafcd to head could not be read, so changes in that range were checked only through head source and the change summary. The custom-amount hint path was checked only through the summary, not a full UI code read. Real payment gateways were not exercised, as the PR states.
Full details: Out of Scope Changes check
Explanation
The changed files relate to the tiered AmountDiscount feature. The backend matcher and the three gateway pricing functions implement the issue. The cross-gateway and matcher tests verify that feature. The frontend format, payment, wallet, and recharge-form changes implement the wallet display and payable-amount consistency that the issue requests. The change to controller/topup_waffo_pancake_test.go (non-positive-discount case moves from amount 20 to amount 5) is a required fixture update, because amount 20 now matches the threshold-10 discount. Head source of setting/operation_setting/payment_setting.go contains no unrelated code. The incremental diff from previous head 73fafcd could not be read, so unrelated changes in that range cannot be ruled out from diff evidence. The change summary lists no such change.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks the threshold row, And finds the highest tier to show. Stripe keeps its exact-key way, While wallet cards display the pay. Soft paws hop as savings glow.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: f33d36ae-72ce-4fab-a176-64c7a096965d
Commits
Reviewing files that changed from the base of the PR and between 73fafcd and 3ca4865.
Files selected for processing: 1
controller/topup_waffo_pancake_test.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The tests add a second new backend test file and duplicate an existing settings fixture, violating the project’s requirement to extend suitable existing tests and add at most one new file for a small feature.
Implements #8436 by applying the highest qualifying recharge discount threshold across supported non-Stripe gateways and synchronizing wallet displays. Stripe retains its existing exact-match behavior.
Changes:
Adds shared threshold matching for Epay, Waffo, and Waffo Pancake pricing.
Makes wallet discount displays depend on the active payment method.
Adds regression coverage for threshold boundaries, gateway pricing, and Stripe-specific displays.
File
Description
web/src/features/wallet/lib/payment.ts
Applies threshold discounts to preset amounts.
web/src/features/wallet/lib/format.ts
Adds discount matchers and suppresses empty discount labels.
web/src/features/wallet/index.tsx
Uses the active payment method when resolving discounts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 关联任务 / Related Issue
🚀 变更类型 / Type of change
📝 变更描述 / Description
将充值金额折扣
AmountDiscount从精确键值匹配调整为“匹配不超过充值金额的最大正阈值”,并同步前后端与不同支付网关的优惠展示与计价口径:setting/operation_setting/payment_setting.go新增PaymentSetting.MatchAmountDiscount(amount int64) float64,在配置映射中选取0 < threshold <= amount且rate > 0的最大阈值对应折扣(未命中返回1.0),并在controller/topup.go(getPayMoney)、controller/topup_waffo.go(getWaffoPayMoney)与controller/topup_waffo_pancake.go(getWaffoPancakePayMoney)中统一调用。controller/topup_stripe.go的精确键值逻辑不变(Stripe Checkout 当前使用固定StripePriceId + Quantity与AllowPromotionCodes,未更改结账定价方式),避免报价与 Stripe Checkout 实际扣款脱节。web/src/features/wallet/lib/format.ts新增getMatchedAmountDiscount与getDiscountRateForPaymentType(Stripe 走精确匹配、其他网关走阶梯匹配),同步更新mergePresetAmounts、Wallet的getDiscountRate与RechargeFormCard(根据当前激活支付方式activePaymentType门控阶梯折扣展示,确保预设卡片价格、应付金额与确认弹窗一致)。📸 运行证明 / Proof of Work
gofmt -l setting/operation_setting/payment_setting.go setting/operation_setting/payment_setting_test.go controller/topup.go controller/topup_waffo.go controller/topup_waffo_pancake.go controller/topup_waffo_pancake_test.go输出为空。main6627f0e在golang:1.26.10-alpine容器执行):go test -p 1 -v ./setting/operation_setting -count=1全包 13 项测试全部 PASS(含TestPaymentSettingMatchAmountDiscount11 个边界用例:精确命中、区间命中、低于最低档、零金额、空/nil map、非正键/倍率过滤)。go test -p 1 -v ./controller -run "TestGetWaffoPancakePayMoney" -count=1全部 PASS:在AmountDiscount={5: 0, 10: 0.8, 100: 0.95, 200: 0.90, 1500000: 0.5}、Price=1.0时,getPayMoney/getWaffoPayMoney返回9 -> 9.0、99 -> 79.2(命中 10 档)、105 -> 99.75(命中 100 档)、250 -> 225.0(命中 200 档);getWaffoPancakePayMoney(UnitPrice=2.5)返回105 -> 249.375、250 -> 562.5。web/):bun check -b:No type errors in 1,501 files across 2 projects(8.80s)。bun --bun x vitest run src/features/wallet/__tests__/copy.test.tsx:9/9 用例全部 PASS(1.76s):验证了mergePresetAmounts([50, 105, 200], {100: 0.95})、RechargeFormCard在普通网关对200档显示优惠 5%支付 190 • 节省 10,以及在仅启用 Stripe 或多网关选中 Stripe 时对200档仅显示支付 200而对精确命中档100保持优惠 5%支付 95 • 节省 5。✅ 提交前检查项 / Checklist
New feature,我已关联对应 Issue;若尚无 Issue,我已先自行创建。go build通过或测试通过,不视为有效证明。Summary by CodeRabbit