Work a card's minimum payment out from its statement balance
Fixes jaysbeekay/sure#896
Upstream issue: we-promise/sure#5443
Upstream PR: https://github.com/we-promise/sure/pull/5992 (we-promise/sure#5992, draft, position 7 of the native stack https://github.com/we-promise/sure/stack/5995); same branch, same commits.
Stack: base up/card-statement-cycle (jaysbeekay/sure#1023) ← jaysbeekay/sure#1022 ← jaysbeekay/sure#1021 ← jaysbeekay/sure#1020 ← jaysbeekay/sure#1006.
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 jaysbeekay/sure#896 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; otherwisemin(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
plaidprovenance value equals it; - the minimum is unchanged since;
- the card is still Plaid-linked (legacy
plaid_accountor anAccountProvider); - Plaid's
last_statement_issue_dateis 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_ofand cleared onreload. - Plaid wrote the stored minimum, so its
-
StatementSummary#minimum.minimum_payment_shortfall?(as_of:, balance:)compares the balance withminimum_payment_for, and is false when the balance is unknown. -
Folded in (owner, 2026-11-29): the above-minimum warning is hidden once the statement is paid in full.
minimum_payment_shortfall?takes the statement'sremaining:and is false when it is zero, and the Overview passessummary.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 keyunpaid_after_payment, in en and the 8 locales that translateabove_minimum, machine-translated). Owner decision 2026-11-29. Test "credit card overview has no minimum warning once the statement is paid" failed first withExpected /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 throughenrich_attribute(:minimum_payment, …, source: "plaid", ignore_locks: true)instead of a plainupdate!. As before, Plaid's figure replaces a hand-typed one, and a nil from Plaid leaves the stored value alone. Theplaidprovenance 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::DataImporterdrops a negative floor or an out-of-range minimum instead of rolling back the whole import. -
GetAccounts#credit_card_terms:minimum_paymentis 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), besideminimum_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 #1023: 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 jaysbeekay/sure#896 → 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 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.minimum44.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 the Gatekeeper 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
plaidrow) - "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"
- "records the minimum it writes as Plaid's" (before: no
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)
| # | Mutation | Caught by |
|---|---|---|
| M1 | round instead of truncate | eight-statement test |
| M2 | no floor | 3 tests |
| M3 | not capped at the balance | 15 → 15 |
| M4 | 0% no floor gives 0 | 0% test |
| M5 | credit balance gets a minimum | zero/credit test |
| M6 | shortfall keeps the fixed minimum | shortfall test |
| M7 | warning quotes the fixed minimum | Overview 44.84 |
| M8 | minimum line for fixed minimums | fixed-minimum Overview |
| M9 | no "Unknown" | unknown Overview |
| M10 | GetAccounts reports the fixed field | GetAccounts |
| M11 | percent up to 101 | 0–100 test |
| M12 | floor not permitted | form test |
| M13 | dropped from importer | round trip |
| M14 | summary.minimum is the fixed field | summary test |
| M15 | floor validation dropped, or run on every save | floor tests |
| M16 | minimum-payment range dropped, or run on every save | column-range and stored-row tests, processor overflow test |
| M17 | bank's minimum not capped, or a 0 kept | capped test |
| M18 | provenance value match, plaid source, or link check dropped | typed-by-hand, no-longer-linked tests |
| M19 | statement-date check or its 4-day tolerance dropped | earlier-statement test |
| M20 | a missing date counts as current, or the Date::Error rescue dropped | undated test |
| M21 | as_of not passed by the summary or the shortfall | own-date test |
| M22 | memo removed, ignores as_of, or survives reload | once-per-load, earlier-statement, Plaid-wins tests |
| M23 | unknown-balance bank return removed, or the shortfall's nil guard | uncapped and Overview unknown tests |
| M24 | provenance write for an unchanged value removed | marks-already-held test |
| M25 | restore_attributes or errors.clear dropped before the write | refused-cycle tests |
| M26 | ignore_locks dropped, or the nil guard | replaces-typed and keeps-when-none tests |
| M27 | Overview label always plain, or always "Bank's minimum" | the two Overview label tests |
| M28 | importer floor/minimum clamp removed, or applied to any value | importer tests, round trip |
Verification
- Full unit suite (beastpc) on e599f8b03, with the updated lower slices merged in:
19609 runs, 0 failures, 8 errors, 9 skips(8ReleaseNotesWorkflowTesterrors, nonode). 1d272d821 only adds jaysbeekay/sure#1023'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 #1023 (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 = #1023.
| View | Before | After |
|---|---|---|
| Overview — light, desktop | ![]() | ![]() |
| Overview — light, phone | ![]() | ![]() |
| Overview — dark, desktop | ![]() | ![]() |
| Overview — dark, phone | ![]() | ![]() |
| Edit form — light, desktop | ![]() | ![]() |
| Edit form — light, phone | ![]() | ![]() |
| Edit form — dark, desktop | ![]() | ![]() |
| Edit form — dark, phone | ![]() | ![]() |
After the Gatekeeper 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.
| View | Light, desktop | Dark, desktop | Light, phone | Dark, 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_moneycallers: the warning (nowsummary.minimum) and nothing else in app code; it stays for the fixed case.minimum_payment_shortfall?callers: the Overview only.StatementSummaryis built only instatement_summary; the new member is appended, so no positional construction breaks.GetAccountsadds a statement read per card only when a percentage is set, plus a few queries for the Plaid check on those cards.terms.minimum_paymentkeeps its stored meaning; the computed figure is the newlast_statement_minimum.PlaidAccount::Liabilities::CreditProcessoris the only writer ofminimum_paymentfrom 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_paymentin ~20 locales; the new keys fall back to English (the I18n test suite passes).



































