← Back to Pull requests

Store a card's intro APR expiry and step-up rate #1025

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

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

Stack: base up/card-minimum-percent (jaysbeekay/sure#1024) ← jaysbeekay/sure#1023 ← jaysbeekay/sure#1022 ← jaysbeekay/sure#1021 ← jaysbeekay/sure#1020 ← jaysbeekay/sure#1006. Sibling: fork #1009's daily-rate slice (another branch on #1006) edits the same APR tile's "Monthly rate" row; expect one small textual conflict there.

Summary

A card can now record an introductory rate as one dated step. The apr column holds the intro rate, labelled Intro rate on the form while an end date is stored. Intro rate ends on is when it stops, and Rate after the intro applies from that date. Every APR reader uses the rate in force on its own date, so interest no longer runs on at the teaser rate past the expiry. Clearing the end date makes the rate after the intro the card's APR. Per the revised plan, the chart step moved to the payoff projection (jaysbeekay/sure#903).

What changed

  • CreditCard#effective_apr(on:): apr before intro_apr_expires_on, after_intro_apr from that date itself.

  • Validation both ways, with named messages (config/locales/models/credit_card/en.yml): an expiry needs a step-up rate, a step-up rate needs an expiry, and an intro needs an apr; the step-up rate is ≥ 0.

  • before_validation :end_intro_rate: a save that clears intro_apr_expires_on while a rate after the intro is set moves that rate into apr and clears after_intro_apr, so an ended intro can be removed without falling back to the intro rate. Every other save stores the rates as typed. The intro days of an open cycle keep the intro rate after the expiry (a new rate after the intro saved on 1 Oct still gives 7.40 for the 11 Sep–10 Oct cycle; re-pricing those days would give 14.79).

  • APR readers (grep of apr in app/ — every one is listed):

  • - cycle_interest_money (#1006): each day charged at that day's effective_apr (cycle_balance_days → cycle_rated_balance_days), still summed then rounded once. #1006's comment "the current APR applies to the whole cycle" is updated.
    - StatementSummary#monthly_rate: effective_apr(on: as_of) / 12.
    - Overview APR tile: effective_apr(on: today) and "Until <date> (n days), then <rate>" while the intro runs; show_apr still keys on apr.
    - GetAccounts#credit_card_terms: apr is the rate on as_of_date; after_intro_apr and intro_apr_expires_on added.
    - PlaidAccount::Liabilities::CreditProcessor#write_apr, through enrich_attribute(..., source: "plaid"):
    - while an intro runs, Plaid's APR is skipped, so the intro rate stays;
    - once the intro has ended, Plaid's APR is written to after_intro_apr, so the days before the expiry keep the intro rate;
    - with no intro, it overwrites apr (ignore_locks: true), as main does for every Plaid card field;
    - the APR is the aprs entry whose apr_type is purchase_apr, or the first entry when none is;
    - a nil APR changes nothing;
    - the card is restored and its errors are cleared before the write, so a refused minimum or cycle update cannot stop it, and an APR the model refuses is logged against the Plaid connection ("Plaid card APR refused by the model").

    Plaid reports no expiry, so the expiry has no provider writer.
    - Left alone: RedbarkAccount::CreditCardDetailsProcessor (already fills only a blank, unlocked APR); the form/controller/importer (they carry the column).

  • Form: the end date and "Rate after the intro", with a hint that ends "Clear the end date to make the rate after the intro your APR.", before the interest basis. The apr field is labelled "Intro rate" when an end date is stored (it follows the stored date, so a refused submit does not relabel it) and "APR" otherwise. Every field stays editable. The fields are permitted and carried by the importer.

  • GetAccounts description: apr is the rate in force on the date asked, and it says what after_intro_apr and intro_apr_expires_on mean.
  • Tests (red on #1024: 9 errors unknown attribute 'after_intro_apr' / undefined method 'effective_apr', 1 failure no form input)

    test/models/credit_card_test.rb

  • expiry 5 Jan 2027: 4 Jan → 0, 5 Jan → 22.9, 6 Jan → 22.9; no intro → 18.99 on any date

  • expiry without rate and rate without expiry refused with the named messages; both set valid

  • 1,000 owed over 11 Sep–10 Oct, 0% until 26 Sep then 18% → 7.40 (all-0% gives 0, all-18% 14.79)

  • summary monthly rate 0 on 20 Sep, 1.5 on 1 Oct
  • accounts_controller_test.rb: on 6 Dec the tile shows 0.000% and "Until January 05, 2027 (30 days), then 22.900%"; on 5 Jan it shows 22.900% and no intro line.
    get_accounts_test.rb: apr 0 with after_intro_apr 22.9 and the date; on the expiry date apr 22.9.
    plaid_account/liabilities/credit_processor_test.rb: "keeps the intro APR while the intro rate runs" (0 survives a sync reporting 15; minimum still updated).
    credit_cards_controller_test.rb, data_importer_test.rb: form saves both; round trip.

    Added after the Gatekeeper review (each failed first as noted, or is a guard caught by a mutation):

  • credit_card_test.rb:

  • - "an intro rate needs an APR";
    - "the step-up rate cannot be negative" (−0.01 refused, 0 valid);
    - "clearing the intro's end date makes the rate after the intro the APR" (before: RecordInvalid) and its guard "clearing the intro's end date and its rate after keeps the APR";
    - "after the intro has ended, a new APR is saved as the intro rate" (before: 0.0, expected 1.9);
    - "a new APR while the intro runs keeps the intro rate", "after the intro has ended, a save that leaves the APR alone keeps the intro rate", "an APR saved with its intro fields keeps them after the expiry";
    - "a new rate after the intro saved after the expiry keeps the cycle's intro days at the intro rate" (7.40).
  • credit_cards_controller_test.rb:

  • - "the edit form offers the intro rate and saves it" now sends apr: 0 and asserts the APR is locked, which ties a form save to the lock;
    - "clearing the intro's end date in the form makes the rate after the intro the APR" (before: 422);
    - "after the intro has ended, the edit form still edits the intro rate and the rate after it";
    - "an intro rate entered after the intro has ended is saved as given";
    - "a card without an intro rate edits its APR";
    - "a refused first intro rate re-renders the form with the APR label".
  • credit_processor_test.rb:

  • - "keeps the APR when Plaid sends none";
    - "after the intro has ended, takes Plaid's APR as the rate after the intro" (before: 0.0, expected 24.9);
    - "overwrites a locked APR when no intro rate runs, as for the other Plaid card fields" (before: 15, expected 27.9);
    - "takes the purchase APR from Plaid's list" and "takes Plaid's first APR when none is a purchase APR";
    - "an APR the model refuses is logged against the Plaid connection";
    - "an unchanged APR is not logged as refused after another attribute failed";
    - "Plaid's APR saves on its own after the other card fields are refused" (before: a numeric overflow raised out of the sync).
  • get_accounts_test.rb: "describes a card's APR in force and its intro rate keys".
  • Mutations (each alone)

    | # | Mutation | Caught by |
    |---|---|---|
    | M1 | step-up the day after expiry | effective APR, cycle interest |
    | M2 | cycle interest at the column APR | cycle interest 7.40 |
    | M3 | monthly rate from the column | summary monthly rate |
    | M4 | expiry without rate accepted | validation |
    | M5 | rate without expiry accepted | validation |
    | M6 | tile reads the column | Overview |
    | M7 | intro line after expiry | Overview |
    | M8 | GetAccounts reads the column | GetAccounts |
    | M9 | Plaid writes the APR while the intro runs | "keeps the intro APR while the intro rate runs" |
    | M10 | Plaid APR not written | 2 Plaid tests |
    | M11 | not permitted | form test |
    | M12 | dropped from importer | round trip |
    | M13 | unless apr.nil? removed | keeps-when-none |
    | M14 | accountable.lock_saved_attributes! dropped | form lock assertion |
    | M15 | step-up >= 0 dropped | cannot-be-negative |
    | M16 | apr not required with an intro | intro-needs-an-APR |
    | M17 | end_intro_rate without the nil guard, or without moving/clearing the rate | the clearing tests |
    | M18 | end_intro_rate fires on any expiry change, or whenever the expiry is nil | form intro test and 7 others; validation and Plaid log tests |
    | M19 | Plaid always writes apr | after-the-intro Plaid test |
    | M20 | restore_attributes dropped before the write | saves-on-its-own test |
    | M21 | label always "APR", or from the submitted date | the two label tests |

    Verification

  • Full unit suite (beastpc) on fb5418e78 (262d65aae with the updated lower slices merged): 19642 runs, 0 failures, 8 errors (8 ReleaseNotesWorkflowTest errors, no node). Targeted card, Plaid, importer, assistant and Redbark files: 652 runs, 0 failures, 0 errors.

  • System accounts_test (it fills "APR" on card creation): 12 runs, 0 failures.

  • bin/rubocop: no offenses. erb_lint (2 files): no errors. bin/brakeman: 0 warnings.
  • Screenshots

    Same seeded card with APR 0% (the intro rate). Before (#1024): nothing says the 0% ends. After: 24.9% from 40 days out, shown on the APR tile. Before = #1024.

    | 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 (262d65aae): the edit form for a card whose intro ended 20 days ago (intro 0%, rate after 24.9%). Both rates are labelled and editable, and the hint says how to clear the intro. On the reviewed head (d2e59ca39) the same two fields were labelled "APR" and "APR after the intro rate".

    | View | After |
    |---|---|
    | Edit form, intro ended — light, desktop | !after |
    | Edit form, intro ended — light, phone | !after |
    | Edit form, intro ended — dark, desktop | !after |
    | Edit form, intro ended — dark, phone | !after |

    Migration notes

    20261128120400_add_intro_apr_to_credit_cards: intro_apr_expires_on date and after_intro_apr decimal(10,2), both nullable; existing rows NULL (no intro, effective_apr = apr).

    Blast radius

  • cycle_interest_money → statement_summary.estimated_interest and the helper's wording: a card without intro fields multiplies by the same apr every day, so the sum is unchanged (all #1006 interest tests unchanged).

  • Plaid: a card with no intro is written exactly as before, a hand-edited APR included (main's adapter path ignores locks for every card field). The changes are only for intro cards: the APR is skipped while the intro runs, and after it ends Plaid's APR becomes the rate after the intro. Separately, the purchase APR is picked by type, and a refused APR is logged.

  • end_intro_rate fires only on a save that clears the end date. Family::DataImporter builds new cards only, where the expiry goes nil → nil, so it never fires there.

  • Not changed here: Enrichable#enrich_attributes reads locked? before its transaction, so a lock saved mid-sync can still lose to that sync. The code is shared by every enrich_attribute caller and is left alone here. Plaid's APR path reads no lock: it skips the APR while an intro runs and passes ignore_locks: true otherwise.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: jaysbeekay Review duration: 3177m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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%
    46%
    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
    Real PR Conversation Timeline
    1 comments
    "Review active on #1025"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%