Repository navigation
fix(payment): support up to 6 decimals for balance recharge multiplier - #8642
Merged
Wei-Shaw merged 1 commit intoNov 10, 2026
Merged
Conversation
Persist BALANCE_RECHARGE_MULTIPLIER with up to 6 decimal places so operators can track a live FX rate (e.g. 1 USD = 7.100000 CNY -> 0.140845). Values with more than 6 decimals are rejected instead of being silently truncated. Credited balance still rounds to settlement-currency precision, so order and ledger semantics are unchanged. Adds backend unit tests and a frontend formatter test; updates the admin input step/preview and the checkout rate display.
Contributor
|
All contributors have signed the CLA. ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
BALANCE_RECHARGE_MULTIPLIERwith up to 6 decimal places instead of silently truncating to 2.Motivation
Operators that collect CNY through the balance recharge flow need to track a live FX rate. With the current 2-decimal limit, a rate of 1 USD = 7.100000 CNY can only be stored as
0.14or0.15, producing a 0.7%–7% error for every recharge.With 6 decimals an operator can store the live rate (e.g.
0.140845) and refresh it from a daily CronJob:This is a minimal, backward-compatible step toward CNY billing. It does not change the USD ledger currency or the payment order schema; full settlement/recharge currency separation is tracked in #5219 and the CNY request in #7087.
Changes
Backend
formatBalanceRechargeMultiplierformatter that stores up to 6 decimals without trailing zeros.balanceRechargeMultiplierHasExcessPrecisionvalidation; values with > 6 decimals returnINVALID_BALANCE_RECHARGE_MULTIPLIERinstead of being silently rounded.calculateCreditedBalancekeepsRound(2), so balances/orders remain at currency precision.0.1 + 0.2), legacy 2-decimal values, and rejection of 7-decimal values.Frontend
step/minchanged from0.01to0.000001.Compatibility
0.14→0.14,0.5→0.50).users.balanceis alreadynumeric(20,8);payment_orders.amountremainsnumeric(20,2)and credited amounts continue to round to cents.Test plan
go vet ./internal/servicego test ./internal/service -run 'TestParsePaymentConfig|TestUpdatePaymentConfig|TestCalculateCreditedBalance' -count=1pnpm vitest run src/utils/__tests__/rechargeBonus.spec.ts src/views/user/__tests__/PaymentView.spec.ts src/views/admin/__tests__/SettingsView.spec.tspnpm exec vue-tsc --noEmitpnpm exec eslint src/views/admin/SettingsView.vue src/views/user/PaymentView.vue src/utils/rechargeBonus.ts src/utils/__tests__/rechargeBonus.spec.tsAll passed locally on commit
ee58c0013c76ccd3f36439881bc848d342ec1c9d.Related