Repository navigation
fix(subscription): charge Epay subscriptions at the price per USD (HQ-Task T261105-08) - #4
Merged
Conversation
…-Task T261105-08)
Epay subscription orders sent the plan's USD list price to the gateway as
the payment amount, so a $10 plan was charged 10.00 instead of
10 × 每美元余额收费金额 (73.00 at the default 7.3), while Epay top-ups
already converted through getPayMoney.
- controller/topup.go: payMoneyFromUSD (usd × operation_setting.Price) is
the single exchange-rate step shared by getPayMoney and subscriptions.
- controller/subscription_payment_epay.go: convert the plan price, reject
sub-cent amounts before rounding, store the rounded gateway amount in
SubscriptionOrder.Money (the unit TopUp.Money already uses for Epay),
and verify the callback money against the order in notify/return before
completing it. Order creation and callback outcomes are logged.
- web: the purchase dialog shows the converted "Online payment amount"
(status.price, as the top-up page) and the Epay button reads
"Pay {{amount}}"; wallet passes priceRatio through. New locale key in
all seven languages.
- tests: controller/subscription_payment_epay_test.go and
web/src/features/subscriptions/__tests__/purchase-dialog-epay-amount.test.tsx.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This was referenced Nov 6, 2026
Merged
1 of 5 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
HQ-Task: T261105-08
Agent
Links
User request
Out of scope — refuse
Open gate — do not open unless all are satisfied
go buildor tests passed: yesKind
Issue facts
$10paid through Epay creates a gateway order withmoney=10.00; the top-up page charges10 × 每美元充值价格 (7.3) = 73.00for the same$10of credit.controller/subscription_payment_epay.go(fork-main 1f7d6cb) passesplan.PriceAmountunchanged asepay.PurchaseArgs.Money, whilecontroller/topup.gogetPayMoneymultiplies byoperation_setting.Pricefor top-ups.SubscriptionOrder.Money,epay.PurchaseArgs.Money), price-per-USD settingoperation_setting.Price.web/src/features/subscriptions/components/dialogs/subscription-purchase-dialog.tsx).Change
controller/topup.go: newpayMoneyFromUSD(usd decimal.Decimal)=usd × operation_setting.Price.getPayMoneynow calls it (same multiplication order as before, so top-up amounts are unchanged); it is the single exchange-rate source for Epay top-ups and Epay subscriptions.controller/subscription_payment_epay.go:subscriptionEpayMoney(plan)=payMoneyFromUSD(plan.PriceAmount); the handler rejects it below0.01before rounding (same bound asgetPayMoney), then rounds half-away-from-zero to 2 decimals. That rounded value goes to bothSubscriptionOrder.Moneyandepay.PurchaseArgs.Money(StringFixed(2)). Top-up group ratio and top-up preset discounts are not applied: plans carry a fixed list price and the discounts are keyed by top-up amount, so they have no meaning for a plan; nothing optional was added.completeEpaySubscriptionOrder(shared by/api/subscription/epay/notifyand/api/subscription/epay/return): after the signature check it loads the order by trade number, checksPaymentProvider == epay, and compares the callbackmoneywithorder.Moneyat 2 decimals (epayCallbackMoneyMatches); a mismatch or unparsable amount is logged and answered withfail/?pay=fail, and the order stays pending. Only then does it call the unchangedmodel.CompleteSubscriptionOrder.Epay subscription order created … price_usd=10.00 price_per_usd=7.3000 money=73.00), with zh-CN lines incommon/log_text.zh-CN.json.SubscriptionOrder.Moneysemantics: for Epay orders it is now the amount charged by the gateway in the gateway currency, which is whatTopUp.Moneyalready means for Epay top-ups and whatupsertSubscriptionTopUpTxcopies into the mirroredtopupsrow (billing history "Payment" column) and what the "Subscription purchased … payment amount: {{amount}}" log prints. Order record, Epay callbackmoneyand the log therefore all read73.00. No column was added: the USD list price is still reachable throughplan_id, no consumer needs a USD snapshot on the order, and avoiding a schema change keeps this PR free of the 3-database migration matrix (MySQL cannot be pulled on the test host, see "Not verified"). Balance / Stripe / Creem / Waffo orders keep writingplan.PriceAmountas before.priceRatio(thepricefield/api/statusalready exposes, the same source the top-up page uses — no new endpoint) and, when Epay is available, shows "Online payment amount" =formatLocalCurrencyAmount(round2(price_amount × priceRatio))and renders the Epay button asPay {{amount}}.subscription-plans-card.tsxandwallet/index.tsxonly pass the prop through. New keyOnline payment amountin all 7 locale files, inserted in sorted position without touching existing lines.Research
Duplicate / prior art
gh pr list --repo AdoreJc/new-api --state all(only feat(channel): Claude Subscription (OAuth) channel with usage and reset credits; Codex browser OAuth flow #1–feat(subscription): bind an OAuth channel account to a user subscription (HQ-Task T261105-02) #3, none about subscription payment amounts); upstreamcontroller/subscription_payment_epay.goon QuantumNous/new-api main has the sameMoney: plan.PriceAmountcode path.getPayMoney) already converts USD → pay money; the subscription Epay path never did. No open PR covers it.Docs and code
Pricewas taken from the settings UI label (How much to charge for each US dollar of balance (Epay)/ 「每美元余额(Epay)的收费金额」 in the payment settings) and fromgetPayMoney, which is the only other consumer..agents/rules/billing.md(read in full; this change does not touch quota conversion, it only converts money for the gateway),AGENTS.mdbackend/frontend rules.controller/topup.gogetPayMoney/RequestEpay/EpayNotify+model.RechargeEpay(top-up: converts money, but the notify path does not compare the callback amount either);controller/subscription_payment_epay.go+model.CompleteSubscriptionOrder/upsertSubscriptionTopUpTx(order money is copied intotopups.moneyand the log);web/src/features/wallet/index.tsxpassesstatus.priceaspriceRatioto the recharge card, so the same value is passed to the subscription card.Alternatives considered
SubscriptionOrder.Moneyas the USD price and add a newpay_moneycolumn with the converted amount. Rejected: needs anAutoMigratecolumn on three databases, and every existing consumer ofMoney(mirrored top-up row, log) wants the gateway amount anyway.model.CompleteSubscriptionOrder. Rejected: that function is shared by Stripe, Creem and Waffo callbacks whose amounts live in different payloads; the Epay-specific check sits next to the Epay signature check instead, and the completing transaction still re-reads the order under lock.Files
controller/topup.gopayMoneyFromUSDshared conversion;getPayMoneyuses itcontroller/subscription_payment_epay.gocontroller/subscription_payment_epay_test.gocommon/log_text.zh-CN.jsonweb/src/features/subscriptions/components/dialogs/subscription-purchase-dialog.tsxPay {{amount}}buttonweb/src/features/wallet/components/subscription-plans-card.tsx,web/src/features/wallet/index.tsxpriceRatio(status.price) throughweb/src/features/subscriptions/__tests__/purchase-dialog-epay-amount.test.tsxweb/src/i18n/locales/*.json(7)Online payment amountBehavior
$10plan, price per USD 7.3 → Epay formmoney=10.00, ordermoney=10, log "payment amount: 10.00"; callback amount never compared; dialog shows only$10.00.money=73.00, ordermoney=73, mirrored top-upmoney=73, log "payment amount: 73.00"; a signed callback whosemoneydiffers from the order is rejected (fail/ redirectpay=fail, order stays pending); dialog shows "Online payment amount ¥73.00" (currency per display settings) and the button reads "Pay ¥73.00". Price per USD = 1 keeps$10 → 10.00.Verification
GOWORK=off go build ./...(afterbun run build, the embed needsweb/dist): ok.GOWORK=off go vet ./controller/ ./model/: clean.gofmt -l controller/: empty.cd relaykit && GOWORK=off go build ./.../cd tokenkit && GOWORK=off go build ./...: ok.GOWORK=off go test ./controller/ -run 'TestPayMoneyFromUSD|TestSubscriptionRequestEpay|TestSubscriptionEpay' -count=1 -v: 6/6 PASS (ok github.com/QuantumNous/new-api/controller 5.591s); the log lines showprice_usd=10.00 price_per_usd=7.3000 money=73.00,price_per_usd=1.0000 money=10.00, andcallback money mismatch … order_money=73.00 callback_money="10.00".GOWORK=off go test ./controller/ -count=1: 40--- FAIL, every one of them the known Windowstesting.go:1464: TempDir RemoveAll cleanup: unlinkat …�udit.db: The process cannot access the file because it is being used by another process(all subtests PASS, no assertion failures). The same test names fail the same way on a cleanorigin/fork-main(1f7d6cb) worktree.GOWORK=off go test ./model/ -run 'Subscription|TopUp|Topup|Payment|Epay': ok.cd web && bun install --frozen-lockfile(no changes)&& bun run test: 209 files / 2503 tests passed;bun run build: ok.tsgo -b(Bun 1.4.0 here cannot runbun run typecheck): clean.oxlint+oxfmt --checkon the four touched TS/TSX files: clean.bun run i18n:sync: no-op.docker build -t new-api-fork:t261105-08(logC:\Docker ew-api-t261105-08�uild.log) →docker run -d --name new-api-t06 -p 39684:3000 -v C:\Docker ew-api-t261105-08\data:/data new-api-fork:t261105-08: container up,New API ready in 1132 ms,GET /api/status→ 200, no panic indocker logs. Setup wizard completed with a test admin; price per USD set to 7.3 and Epay placeholders entered on the payment settings page.$10plan → Epay order → gateway formmoney=73.00): pending. Subscription purchase on this build is behind the payment-compliance attestation dialog, which the agent was not permitted to submit on the user's behalf; the HQ user will confirm it on the test instance, after which the purchase step is re-run and this section updated.controller/subscription_payment_epay_test.go(6 tests:payMoneyFromUSDtable 7.3→73.00 / 1→10.00 / 7.333→7.33; order creation sendsmoney=73.00and stores 73; price 1 sends10.00;$0.001plan rejected with "Plan amount is too low" and no order; notify withmoney=10.00→fail+ order pending + no subscription, thenmoney=73.00→success+ subscription + mirrored top-up 73 + log contains73.00, duplicate stays idempotent; return URL with wrong money redirects topay=fail).web/src/features/subscriptions/__tests__/purchase-dialog-epay-amount.test.tsx(3 tests: converted amount and button at ratio 7.3, ratio 1, no Epay → no row)./api/subscription/pay/epayresponse and the container log.TestSubscriptionRequestEpay_ChargesConvertedMoney, which readsmoney=73.00from the signed gateway form); a real Epay gateway callback; MySQL / PostgreSQL (no schema or query change, only an extraSELECTbytrade_noonsubscription_ordersthrough GORM); Stripe / Creem / Waffo subscription flows (unchanged).Risks
moneyin its callback would now be rejected (logged as "callback money mismatch"); amounts are compared afterdecimalparsing at 2 decimals, so73,73.0and73.00all match. A price-per-USD change between order creation and callback does not matter: the callback is compared with the stored order amount.getPayMoneyonly delegates the× Pricestep).EpayNotify→model.RechargeEpay) also never compares the callbackmoneywithtopups.money; same hardening could be applied there.stripe_price_id(amount defined in Stripe) and Creem usescreem_product_id(amount defined in Creem): not affected by this bug; their orders still recordplan.PriceAmount(USD) inMoney, which is a display-only inconsistency with Epay orders. Waffo Pancake sendsplan.PriceAmountwithStringFixed(2)as the amount in the Waffo currency and does not apply price-per-USD either; whether that is intended depends on how the Waffo account currency is configured, left as-is per the task.Scope check
🤖 Generated with Claude Code