Skip to content

fix(creem): fix manual refill and billing log for Creem orders(#4179) - #4708

Open
yanghong20050 wants to merge 4 commits into
QuantumNous:mainfrom
yanghong20050:main
Open

yanghong20050 wants to merge 4 commits into
QuantumNous:mainfrom
yanghong20050:main

Conversation

@yanghong20050

@yanghong20050 yanghong20050 commented May 9, 2026 •

Copy link
Copy Markdown

问题背景

Creem 支付通道的产品配置中,quota 字段由管理员直接填写系统内部 raw quota 值(例如填 25000000 表示给用户充值 $50 额度),与 Stripe/Waffo 等通道的 Amount 语义不同(后者存的是美元数量,需乘以 QuotaPerUnit 换算)。

修复内容

Bug 1:管理员补单(ManualCompleteTopUp)给 Creem 订单额度错误

原代码对所有非 Stripe 通道统一执行 Amount × QuotaPerUnit,Creem 订单会被错误地再乘以 500,000:

补单实际到账 = 25,000,000 × 500,000 = 12,500,000,000,000(约 $25 亿!)

修复:为 Creem 单独分支,直接使用 topUp.Amount,不做换算。

Bug 2:账单日志显示原始数字而非可读金额

Creem 充值成功的账单记录使用 %v, quota 直接打印原始数字(如 25000000),而 Stripe、Waffo 等通道使用 logger.FormatQuota() 格式化为 $50.00,用户体验不一致。

修复:改用 logger.FormatQuota(int(quota)) 与其他通道保持一致。

变更文件

  • model/topup.go

Summary by CodeRabbit

  • Bug Fixes

    • Fixed top-up quota calculation so credits are computed correctly per payment provider (Stripe, Creem, others).
  • Improvements

    • Clarified recharge logging for clearer transaction amounts.
    • Improved quota formatting in top-up and billing history views so amounts display appropriately by payment method.
  • New Features

    • Localized email templates for verification, password reset, and channel enable/disable notifications (subject and HTML content adapt to recipient language).

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5192dbc2-6244-4a91-8209-a3a53a0e34a0

📥 Commits

Reviewing files that changed from the base of the PR and between 266dd94 and a2e1ed0.

📒 Files selected for processing (2)
  • web/classic/src/components/topup/modals/TopupHistoryModal.jsx
  • web/default/src/features/wallet/components/dialogs/billing-history-dialog.tsx

Walkthrough

This PR makes provider-specific quota calculations and Creem logging changes in the top-up model, adds email i18n keys/locales and wires i18n into controller and service emails, and updates frontend billing/top-up UIs to format Creem quota values specially.

Changes

Payment Provider Quota Handling

Layer / File(s) Summary
Provider-Specific Quota Calculation
model/topup.go
ManualCompleteTopUp branches quota computation by PaymentProvider: Stripe multiplies Money by QuotaPerUnit, Creem uses raw Amount as internal quota, and fallback multiplies Amount by QuotaPerUnit. Comments clarify unit meanings.
Creem Quota Semantics and Logging
model/topup.go
RechargeCreem documents that Creem quota config is stored as raw internal quota (no QuotaPerUnit). Success log label changed to “充值金额” and quota is logged via logger.FormatQuota(int(quota)).

Email Internationalization & Notifications

Layer / File(s) Summary
i18n Keys & Locales
i18n/keys.go, i18n/locales/en.yaml, i18n/locales/zh-CN.yaml, i18n/locales/zh-TW.yaml
Adds email-related i18n keys and appends email.* translation entries (verification, password reset, channel disabled/enabled) across English, zh-CN, and zh-TW locales.
Controller Email Localization
controller/misc.go
Imports i18n and uses i18n.Translate to build localized subjects and HTML content for SendEmailVerification and SendPasswordResetEmail, then calls common.SendEmail.
Service Channel Notifications
service/channel.go
Adds getRootUserLang() and replaces fmt.Sprintf-based channel enable/disable notification strings with i18n.Translate templates populated with channel data and disable reason.

Frontend Quota Display

Layer / File(s) Summary
TopupHistory modal
web/classic/src/components/topup/modals/TopupHistoryModal.jsx
Imports renderQuota/renderQuotaWithAmount and conditionally formats the “充值额度” column: payment_method === 'creem' uses renderQuota(amount), others use renderQuotaWithAmount.
BillingHistory dialog
web/default/src/features/wallet/components/dialogs/billing-history-dialog.tsx
Imports formatQuotaWithCurrency and uses it for records where payment_method === 'creem'; other payment methods retain formatCurrencyFromUSD.

Sequence Diagram(s):

sequenceDiagram
  participant Client
  participant Controller
  participant i18n
  participant Mailer
  Client->>Controller: HTTP request (verification/reset)
  Controller->>i18n: Translate(lang, key, data)
  Controller->>Mailer: common.SendEmail(subject, content)
  Mailer->>Mailer: deliver email
Loading
sequenceDiagram
  participant Service
  participant Model
  participant i18n
  participant Mailer
  Service->>Model: GetRootUser()
  Service->>i18n: Translate(rootLang, key, data)
  Service->>Mailer: common.SendEmail(subject, content)
  Mailer->>Mailer: deliver email
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

🐰
Stripe multiplies, Creem keeps it raw,
Templates now speak the language you saw,
I hop through code with a curious paw,
Localized emails and quotas, hurrah!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: fixing manual refill (ManualCompleteTopUp) quota calculations and billing log formatting for Creem orders.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
fancygirllll added a commit to fancygirllll/new-api that referenced this pull request Sep 16, 2026
RechargeCreem previously credited topUp.Amount as raw quota, so a $19
purchase only credited 19 quota (~$0.0000376). Align Creem with all
other topup paths (manual complete / Stripe / Waffo) by multiplying
Amount (USD) by QuotaPerUnit; reject non-positive quotas. Upstream
context: QuantumNous#4179, PR QuantumNous#4708 (unmerged, opposite fix).

This branch has not been deployed

No deployments
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.

1 participant