Show the card's daily periodic rate instead of APR/12

JA
2d ago
+67-24

Closes #5444
Fork pre-flight: jaysbeekay/sure#1017 (same commits)

Stacked on up/card-daily-interest.

Verified on the stack's top commit 6f85ab855 (up/card-next-statement, with current main merged in at the bottom and each slice merged up the chain): full unit suite 19760 runs, 0 failures, 8 errors, 9 skips (the 8 are ReleaseNotesWorkflowTest, no node in the test container); the card system test credit_card_limit_chart_test 8 runs, 0 failures.

Summary

The card Overview's APR card showed "Monthly rate" as APR / 12 beside an "Estimated interest" figure that up/card-daily-interest works out at APR / 365 (or / 360). It now shows "Daily rate": the APR over the card's basis days, to five decimal places, which is the rate the interest line uses and the rate a card statement quotes. At 18% that is 0.04932% on actual/365 and 0.05000% on actual/360, where it used to say 1.500%.

What changed

  • CreditCard#daily_rate (public): apr / DAY_COUNT_BASES.fetch(day_count_convention), nil without an APR. It replaces the private monthly_rate, and the StatementSummary member monthly_rate becomes daily_rate.
  • credit_cards/tabs/_overview.html.erb: the row reads daily_rate_label and formats the rate with number_to_percentage(..., precision: 5).
  • credit_cards.tabs.overview.monthly_rate_label → daily_rate_label in en and the 8 locales that translated it: de, es, fr, id, nb, nl, pt-BR, zh-CN. nb.yml keeps its CRLF line endings.
  • CreditCard#cycle_interest_money charges balance_days * daily_rate / 100 instead of recomputing APR / basis days inline, so the rate shown and the rate charged cannot drift apart. The interest figures do not change.

Tests (red on the base branch, green here)

test/models/credit_card_test.rb

  • new "the daily rate divides the APR by the card's interest basis days": 18.99% → 0.05203% (actual/365) and 0.05275% (actual/360), formatted as the Overview formats them. 18.99 is fractional, so rounding the APR (19 / 365 = 0.05205%) fails it. Before: NoMethodError: undefined method 'daily_rate'.
  • "the statement summary shows the interest the open cycle has accrued so far": assert_equal 1, summary.monthly_rate → assert_equal BigDecimal(12) / 365, summary.daily_rate. Before: NoMethodError on StatementSummary#daily_rate.
  • "the statement summary has no interest estimate without an APR": also asserts summary.daily_rate is nil.

test/controllers/accounts_controller_test.rb

  • "credit card overview shows what the cycle costs...": the monthly_rate_label and "1.000%" assertions are replaced by "Daily rate" and 0.03288% (12% / 365), and the page must no longer contain "Monthly rate" or 1.000%. Before: Translation missing: en.credit_cards.tabs.overview.daily_rate_label.
  • new "credit card overview shows the daily rate on the card's interest basis": an actual/360 card at 12% shows 0.03333% and not 0.03288%. Before: Expected /0\.03333%/ to match.
  • unchanged: "credit card overview hides the APR card when APR is blank".

test/i18n_test.rb#test_card_interest_lines_exist_beside_the_interest_label: daily_rate_label joins the keys every locale that translates estimated_interest_label must carry. Before: en: ... daily_rate_label is missing, de: ... daily_rate_label is missing.

Red run on the base branch's code with the new tests: 261 runs, 3 failures, 3 errors, all of them the six above.

Added after review (code-review follow-ups):

  • test/models/credit_card_test.rb new "cycle interest charges the daily rate the Overview shows": stubs daily_rate at 0.1% and expects the interest to follow it. Before: Expected: 0.3e2 Actual: 0.1479e2 (the inline APR / 365 ignored the shown rate).
  • The Overview test now also checks that no available locale still carries monthly_rate_label (refute I18n.exists?(..., locale) for each). Shown red by putting the key back in de.yml: de still has the monthly rate label.

Mutations (each applied alone; credit_card, accounts_controller and i18n tests re-run)

#MutationCaught by
M1divisor fixed at 365 (apr / 365)daily rate model test (actual/360), Overview actual/360 test
M2APR rounded before dividing (apr.round / ...)daily rate model test, summary test, both Overview tests
M3daily_rate_label dropped from de.ymli18n interest lines test
M4Overview formats with precision: 3both Overview tests
M5nil-APR guard removedsummary without APR, "hides the APR card when APR is blank" (2 errors)
M6daily_rate divided by a further 1000the new cycle-interest test and 9 other CreditCardTest interest tests
M7cycle_interest_money back to the inline APR / basis"cycle interest charges the daily rate the Overview shows"

Verification

  • Full unit suite on 30c3e6778 (this change plus up/card-daily-interest's latest head merged in): 19501 runs, 0 failures, 8 errors; the 8 errors are ReleaseNotesWorkflowTest (no node in the container), environment noise. On d2e64acc6, before that merge: 19490 runs, 0 failures, 8 errors.
  • Targeted: credit_card, accounts_controller, i18n, credit_cards_controller and credit_cards_helper tests: 312 runs, 0 failures, 0 errors.
  • bin/rubocop (changed Ruby files): no offenses. erb_lint (_overview.html.erb): no errors. bin/brakeman: 0 warnings. No JS, no migration.
  • Checked against upstream AGENTS.md: text through t(), functional tokens only (the row's existing classes are unchanged), no new comments carrying history.

Screenshots

Before = up/card-daily-interest's head 71d3ff766, after = this branch at 68a2b238e (the later fixes change no markup); same data (18% APR, actual/365, $600 carried, due date passed). Only the row under the APR changes: "Monthly rate 1.500%" becomes "Daily rate 0.04932%".

ViewBeforeAfter
Overview, APR card, light, desktopbeforeafter
Overview, APR card, light, phonebeforeafter
Overview, APR card, dark, desktopbeforeafter
Overview, APR card, dark, phonebeforeafter

Blast radius

  • StatementSummary#monthly_rate → daily_rate: read only by credit_cards/tabs/_overview.html.erb (grep -rn monthly_rate app test, loan methods aside). No other view, API or job reads it.
  • Loan::AmortizationMath.monthly_rate and Loan::Insurance#monthly_rate are separate methods and untouched.
  • CreditCard#daily_rate is read by statement_summary (the Overview's Daily rate row) and by cycle_interest_money, whose only caller is statement_summary. The interest figure is unchanged; it now comes from the same method as the row.
  • DAY_COUNT_BASES is still read by daily_rate, the validation and the form helper.

Overlap with we-promise/sure#5271 (annual fees, open)

git merge-tree of this branch with #5271's's head (49db1a05) conflicts only in db/schema.rb and Family::DataImporter::CREDIT_CARD_DETAIL_ATTRIBUTES, the same two conflicts up/card-daily-interest already has; this change adds none. #5271 leaves monthly_rate and its row as they are, so credit_card.rb, _overview.html.erb and en.yml auto-merge.


Summary by cubic

The card Overview's APR card showed "Monthly rate" as APR/12, but the interest estimate beside it uses APR/365 (or /360). It now shows "Daily rate"—the APR over the card's basis days, to five decimal places—so the displayed rate matches the rate the interest line and card statements use (e.g., 1.500% → 0.04932% at 18% on actual/365).

What changed

  • Replaces CreditCard#monthly_rate and StatementSummary#monthly_rate with daily_rate (APR ÷ basis days, nil without an APR); the Overview formats it with precision: 5.
  • cycle_interest_money now charges via daily_rate instead of recomputing APR / basis days inline, so the shown and charged rates can't drift; interest figures are unchanged.
  • Renames the monthly_rate_label translation to daily_rate_label in all 9 locales that had it; the I18n test now requires it wherever the interest lines are translated.
  • Rewords the interest deadline wording in Spanish, French, Indonesian, Dutch, and Simplified Chinese from "before" to an inclusive form, since a payment on the due date itself counts.

Closes we-promise/sure#5444.

Summary by CodeRabbit

  • Updates
    • Credit card summaries now show the daily interest rate instead of the monthly rate, displayed to five decimal places.
    • Interest calculations use the card’s configured day-count basis, such as 365 or 360 days, so the displayed daily rate matches the rate used in the calculation.
    • The daily-rate label is available across supported languages, replacing the monthly-rate label in credit card overviews.