Work a card's minimum payment out from its statement balance

JA
6h ago
+1162-17

Closes #5443
Fork pre-flight: jaysbeekay/sure#1024 (same commits)

Stacked on up/card-statement-cycle.

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

A card's minimum payment can now be a rule: Minimum payment % and Minimum payment floor. The minimum on a statement is that share of its balance, truncated to the cent (as Bankwest prints it: all eight statements listed in #5443 match), raised to the floor and never more than the balance. Without a percentage, the fixed minimum_payment works exactly as before. On a Plaid-linked card, the minimum the bank reported for the current statement wins over the percentage and is shown as "Bank's minimum". The Overview's statement card shows the minimum, and the above-minimum warning, the shortfall check and the assistant's last_statement_minimum all quote the same figure. minimum_payment keeps its stored meaning.

What changed

  • CreditCard#minimum_payment_for(balance, as_of:): nil for a zero or credit balance; the fixed minimum without a percentage; otherwise min(balance, max(floor || 0, truncate(balance × % / 100))), nil when that is 0 (the owner's decision: 0% with no floor is no minimum).

  • The bank's minimum wins on a percentage card when provider_reported_minimum?(as_of:) holds. All of these must be true:

    • Plaid wrote the stored minimum, so its plaid provenance value equals it;
    • the minimum is unchanged since;
    • the card is still Plaid-linked (legacy plaid_account or an AccountProvider);
    • Plaid's last_statement_issue_date is no earlier than the last close minus 4 days, or the card has no cycle.

    The bank's figure is capped at the statement balance, and a 0 is no minimum. When the statement balance is unknown, the bank's figure is shown as reported. A missing or unreadable issue date falls back to the percentage. The check is memoised per as_of and cleared on reload.

  • StatementSummary#minimum. minimum_payment_shortfall?(as_of:, balance:) compares the balance with minimum_payment_for, and is false when the balance is unknown.

  • Folded in: the above-minimum warning is hidden once the statement is paid in full. minimum_payment_shortfall? takes the statement's remaining: and is false when it is zero, and the Overview passes summary.remaining. A partly paid statement (some, but not all, of it paid since the close; StatementSummary#partly_paid?) instead names what is left: "$242.12 of this statement is still unpaid and is charged interest at this APR." (new key unpaid_after_payment, in en and the 8 locales that translate above_minimum, machine-translated). Owner decision 2026-11-29. Test "credit card overview has no minimum warning once the statement is paid" failed first with Expected /above the $44.84 minimum/ to not match.

  • Overview: "Minimum $44.84" on the Statement Balance card for a percentage minimum, "Bank's minimum $120.00" for a bank-reported one (also when the statement balance is unknown), and "Unknown" otherwise when the balance is unknown. A fixed minimum shows nothing there; its only place stays the warning, as the partial's comment argues. The warning quotes summary.minimum.

  • PlaidAccount::Liabilities::CreditProcessor: the minimum goes through enrich_attribute(:minimum_payment, …, source: "plaid", ignore_locks: true) instead of a plain update!. As before, Plaid's figure replaces a hand-typed one, and a nil from Plaid leaves the stored value alone. The plaid provenance row is recorded even when the value has not changed, so existing Plaid cards count. The card is restored and its errors cleared before the write, so a refused statement-cycle update neither blocks the minimum nor is logged as a refused minimum. A refused minimum is logged ("Plaid card minimum payment refused by the model").

  • Validations, each checked only when the value changes, so stored rows that predate them still save other edits:

    • minimum_payment_floor ≥ 0;
    • minimum_payment ≥ 0 and below 10**8. That is the decimal(10,2) column's range; a larger Plaid figure raised a numeric overflow and stopped the card's liability processing.
  • Family::DataImporter drops a negative floor or an out-of-range minimum instead of rolling back the whole import.

  • GetAccounts#credit_card_terms: minimum_payment is the stored figure, as before. The computed minimum on the last statement is a new key, last_statement_minimum, on percentage cards only (absent when nil), beside minimum_payment_percent / minimum_payment_floor. The description says what each key means, including Plaid's figure and the cap.

  • Form: the two fields under the minimum/APR row. One hint covers the rule: what is left out (over-limit and arrears components), that a floor applies only with a percentage, and that a bank-reported minimum takes precedence on a Plaid-linked card. Both fields are permitted and carried by the importer.

Tests (red on up/card-statement-cycle: 9 errors unknown attribute 'minimum_payment_percent' / undefined method 'minimum_payment_for', 1 failure no form input)

test/models/credit_card_test.rb

  • 2% / $20 on the eight balances in #5443 → the eight printed minimums (36.26, 23.19, 28.10, 21.72, 74.56, 21.95, 63.16, 44.84); half-up would miss four. we-promise/sure#5443's's table lists six of the eight (not 1,086.24 → 21.72 or 1,097.76 → 21.95); on those six, half-up misses three
  • 500 → 20; 15 → 15; 0, −50, nil → nil
  • no percentage: fixed 100 as before; no fixed either → nil
  • 0% no floor → nil; 0% floor 20 → 20
  • percent 0, 100, nil valid; −0.01, 100.01 invalid
  • 2,242.12: summary.minimum 44.84, shortfall; floor 5,000 → minimum is the whole bill, no shortfall

accounts_controller_test.rb: statement card and warning both say $44.84 with a fixed $100 also set (no "$100.00 minimum"); fixed minimum → no minimum line, warning still "$25.00"; foreign-currency statement → "Unknown".
get_accounts_test.rb: last_statement_minimum 44.84 with percent and floor reported, and minimum_payment the stored figure.

Added after review (each failed first as noted):

  • credit_card_test.rb
    • "the minimum floor is not negative" (before: −0.01 valid) and "an existing card with a negative floor still saves other changes"
    • "a minimum payment is not negative and fits its column", and "an existing card with a negative minimum payment still saves other changes"
    • "on a Plaid-synced card the minimum Plaid reported wins over the percentage" (before: 44.84, expected 120)
    • "a minimum typed by hand on a Plaid-linked card does not override the percentage" (before: 120)
    • "Plaid's minimum is capped at the statement balance and a zero minimum is none" (before: 120, expected 50)
    • "Plaid's minimum stands uncapped when the statement balance is unknown" (before: nil)
    • "a minimum Plaid reported for an earlier statement gives way to the percentage" (issue dates 10 Oct, 5 Nov, 6 Nov at the edge)
    • "a Plaid minimum without a readable statement date gives way to the percentage"
    • "the statement summary and the shortfall judge Plaid's minimum on their own date"
    • "the Plaid minimum check is worked out once per load"
    • guards: "a card no longer linked to Plaid uses the percentage", "a Plaid-synced card with no reported minimum uses the percentage", "a card synced from a provider that reports no minimum keeps the percentage"
  • credit_processor_test.rb
    • "records the minimum it writes as Plaid's" (before: no plaid row)
    • "marks a minimum the card already holds as Plaid's" (before: nil)
    • "a refused cycle update does not stop a new minimum" (before: the minimum stayed 90 and a refusal was logged)
    • "a minimum beyond the column's range is logged as refused and the sync continues" (before: PG::NumericValueOutOfRange)
    • "a minimum the card refuses is logged", "a refused cycle update is not logged as a refused minimum" and "replaces a minimum typed by hand and keeps it when Plaid sends none"
  • get_accounts_test.rb
    • "keeps a card's stored minimum when its percentage minimum cannot be worked out" (before: 0.0, expected 100)
    • "reports no last statement minimum for a card without a percentage"
  • accounts_controller_test.rb
    • "credit card overview labels the minimum Plaid reported as the bank's" (before: translation missing)
    • "credit card overview shows the bank's minimum when the statement is unknown" (before: "Minimum Unknown")
  • data_importer_test.rb: "imports a credit card without a minimum floor it would refuse" and "…without a minimum payment it would refuse" (before: RecordInvalid)
  • credit_cards_controller_test.rb: the form hint is the one translated string, exactly
    credit_cards_controller_test.rb: form renders and saves both. data_importer_test.rb: round trip.

Mutations (each alone)

#MutationCaught by
M1round instead of truncateeight-statement test
M2no floor3 tests
M3not capped at the balance15 → 15
M40% no floor gives 00% test
M5credit balance gets a minimumzero/credit test
M6shortfall keeps the fixed minimumshortfall test
M7warning quotes the fixed minimumOverview 44.84
M8minimum line for fixed minimumsfixed-minimum Overview
M9no "Unknown"unknown Overview
M10GetAccounts reports the fixed fieldGetAccounts
M11percent up to 1010–100 test
M12floor not permittedform test
M13dropped from importerround trip
M14summary.minimum is the fixed fieldsummary test
M15floor validation dropped, or run on every savefloor tests
M16minimum-payment range dropped, or run on every savecolumn-range and stored-row tests, processor overflow test
M17bank's minimum not capped, or a 0 keptcapped test
M18provenance value match, plaid source, or link check droppedtyped-by-hand, no-longer-linked tests
M19statement-date check or its 4-day tolerance droppedearlier-statement test
M20a missing date counts as current, or the Date::Error rescue droppedundated test
M21as_of not passed by the summary or the shortfallown-date test
M22memo removed, ignores as_of, or survives reloadonce-per-load, earlier-statement, Plaid-wins tests
M23unknown-balance bank return removed, or the shortfall's nil guarduncapped and Overview unknown tests
M24provenance write for an unchanged value removedmarks-already-held test
M25restore_attributes or errors.clear dropped before the writerefused-cycle tests
M26ignore_locks dropped, or the nil guardreplaces-typed and keeps-when-none tests
M27Overview label always plain, or always "Bank's minimum"the two Overview label tests
M28importer floor/minimum clamp removed, or applied to any valueimporter tests, round trip

Verification

  • Full unit suite on e599f8b03, with the updated lower slices merged in: 19609 runs, 0 failures, 8 errors, 9 skips (8 ReleaseNotesWorkflowTest errors, no node). 1d272d821 only adds up/card-statement-cycle's one-line residual-flag fix; targeted card, Plaid, importer and assistant files: 620 runs, 0 failures, 0 errors.
  • System accounts_test + credit_card_limit_chart_test: 15 runs, 0 failures.
  • bin/rubocop: no offenses. erb_lint (2 files): no errors. bin/brakeman: 0 warnings.

Screenshots

Same seeded card as up/card-statement-cycle (statement $1,813.38, fixed minimum $25), after: 2% with a $20 floor. The statement card shows Minimum $36.26 and the warning quotes it instead of $25.00. Before = up/card-statement-cycle.

ViewBeforeAfter
Overview — light, desktopbeforeafter
Overview — light, phonebeforeafter
Overview — dark, desktopbeforeafter
Overview — dark, phonebeforeafter
Edit form — light, desktopbeforeafter
Edit form — light, phonebeforeafter
Edit form — dark, desktopbeforeafter
Edit form — dark, phonebeforeafter

After the review fixes (fb3d8cd41):

  • "Form" shows the one hint, with the floor and Plaid sentences.
  • "Percent" is a percentage card with no bank figure: "Minimum".
  • "Bank" is a Plaid card whose minimum is for the current statement: "Bank's minimum $120.00".
  • "Bank, balance unknown" shows "Bank's minimum $120.00" where it used to show "Minimum Unknown".
  • "Stale" has a Plaid minimum from a statement issued 10 Sep, viewed on 16 Oct. It shows "Minimum $44.84", the percentage, not the bank's old figure.
ViewLight, desktopDark, desktopLight, phoneDark, phone
Form
Percent
Bank
Bank, balance unknown
Stale

Migration notes

20261128120300_add_minimum_payment_rule_to_credit_cards: minimum_payment_percent decimal(5,2) with a 0–100 check constraint, minimum_payment_floor decimal(10,2); both nullable, existing rows NULL (fixed minimum as before).

Blast radius

  • minimum_payment_money callers: the warning (now summary.minimum) and nothing else in app code; it stays for the fixed case.
  • minimum_payment_shortfall? callers: the Overview only. StatementSummary is built only in statement_summary; the new member is appended, so no positional construction breaks.
  • GetAccounts adds a statement read per card only when a percentage is set, plus a few queries for the Plaid check on those cards. terms.minimum_payment keeps its stored meaning; the computed figure is the new last_statement_minimum.
  • PlaidAccount::Liabilities::CreditProcessor is the only writer of minimum_payment from a provider; its sync behaviour is unchanged apart from the provenance row, the overflow refusal and the log.
  • Not changed here: the "Paying only the minimum…" warning still shows on a paid statement. The condition predates this PR (we-promise/sure#4270); this PR changes only the figure it quotes.
  • en.yml only: upstream translates minimum_payment in ~20 locales; the new keys fall back to English (the I18n test suite passes).

Summary by cubic

Allows a credit card's minimum payment to be worked out from each statement as a percentage of its balance with a floor, instead of only a fixed amount. Without a percentage, the fixed minimum_payment works exactly as before.

  • The statement minimum is that share of the balance (truncated to the cent), raised to the floor and capped at the balance; a 0% minimum with no floor is no minimum.
  • The Overview statement card shows the minimum ("Unknown" when the balance is unknown and the bank reports none), and the above-minimum warning, the shortfall check, and the assistant's GetAccounts terms all quote the same figure.
  • minimum_payment keeps its stored meaning; the computed figure on a percentage card is a new last_statement_minimum key.
  • On a Plaid-linked card, the minimum the bank reported for the current statement wins over the percentage and is labeled "Bank's minimum"; one for an earlier or a later statement, one without a readable statement date, or a negative one, gives way to the percentage and never counts as the bank's.
  • New minimum_payment_percent and minimum_payment_floor fields and form inputs; the importer drops out-of-range values instead of failing the whole import.
  • A Plaid minimum beyond the column's range is logged as refused and the sync continues; a refused statement-cycle update neither blocks the minimum nor is logged as a refused one.
  • The above-minimum warning is hidden once the statement is paid in full, and a partly paid statement names the remaining unpaid amount with wording that changes once the due date passes.
  • New validations bound the minimum, percent, and floor to their columns' ranges, checked only when they change.

Summary by CodeRabbit

  • New Features
    • Configure a credit-card minimum payment as a percentage of the statement balance, with an optional minimum floor.
    • View calculated or bank-reported minimum payments and clearer information about partially paid balances and potential interest.
    • Include minimum-payment settings when importing credit-card details.
  • Improvements
    • Minimum-payment estimates account for statement data and bank-reported amounts, with safeguards for invalid or unavailable values.
    • Explanations of unpaid statement balances are available in supported languages.