← Back to Pull requests

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

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 28, 2026 12:17 UTC
Author

Fixes jaysbeekay/sure#896
Upstream issue: we-promise/sure#5443
Upstream PR: not opened yet; same branch, same commit.

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; 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 (owner, 2026-11-29): 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 108. 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 #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.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 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 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)

    | # | 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 (8 ReleaseNotesWorkflowTest errors, no node). 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 | !before | !after |
    | Overview — light, phone | !before | !after |
    | Overview — dark, desktop | !before | !after |
    | Overview — dark, phone | !before | !after |
    | Edit form — light, desktop | !before | !after |
    | Edit form — light, phone | !before | !after |
    | Edit form — dark, desktop | !before | !after |
    | Edit form — dark, phone | !before | !after |

    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 | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/form-light-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/form-dark-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/form-light-phone.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/form-dark-phone.png) |
    | Percent | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-percent-light-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-percent-dark-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-percent-light-phone.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-percent-dark-phone.png) |
    | Bank | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-light-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-dark-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-light-phone.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-dark-phone.png) |
    | Bank, balance unknown | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-unknown-light-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-unknown-dark-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-unknown-light-phone.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-bank-unknown-dark-phone.png) |
    | Stale | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-stale-light-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-stale-dark-desktop.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-stale-light-phone.png) | ![](https://raw.githubusercontent.com/jaysbeekay/sure/assets/pr-1024-screenshots-r2/after/overview-stale-dark-phone.png) |

    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).
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: jaysbeekay Review duration: 3188m
    All Vouch review confidence checks passed
    Residual risk 0.42 = Change Risk (0.75) × (1 − Review Confidence (0.44)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #1024"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 44.2% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.2% · Lower = rushed or shallow review
    44.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 42.0% · Moderate risk
    42.0%