← Back to Pull requests

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

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

Closes #5445
Fork pre-flight: jaysbeekay/sure#1025 (same commits)

Stacked on up/card-minimum-percent.

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 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 (#5447).

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 (up/card-daily-interest): each day charged at that day's effective_apr (cycle_balance_days → cycle_rated_balance_days), still summed then rounded once. up/card-daily-interest's comment "the current APR applies to the whole cycle" is updated.
    - CreditCard#daily_rate(on:) (from up/card-daily-rate) and StatementSummary#daily_rate: effective_apr(on:) over the basis days, so the Overview's daily rate is the one charged on as_of.
    - 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 up/card-minimum-percent: 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 daily rate 0 on 20 Sep, 18/365 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 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 | daily rate from the column | summary daily 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 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 (up/card-minimum-percent): nothing says the 0% ends. After: 24.9% from 40 days out, shown on the APR tile. Before = up/card-minimum-percent.

    | 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 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 up/card-daily-interest 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.
  • <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Closes #5445. Adds a credit card introductory APR as one dated step: an intro rate, an expiry date, and a step-up rate from that date. All interest and APR displays now use effective_apr(on:), so the teaser rate never runs past its expiry.

    What changed

  • Cycle interest charges each day at that day's rate; an intro expiry splits the cycle.

  • Validation requires the expiry and step-up rate together; clearing the expiry promotes the step-up rate to apr when it is a readable number within range, and an unreadable, out-of-range, or unreal value is refused as invalid, keeping the card's APR.

  • The step-up rate is capped at the credit limit ceiling. An import drops the whole intro when a rate is out of range or any part is missing, reading out-of-range rates the same way validation does; a bare step-up rate becomes the APR, while a bare end date leaves the APR unknown.

  • Plaid keeps the intro rate while it runs, writes the step-up rate after the expiry, and logs a refused write.

  • The overview APR tile shows "Until <date> (n days), then <rate>" while the intro runs; the card form and family importer carry the new fields.
  • Migration

  • Adds nullable intro_apr_expires_on and after_intro_apr columns; existing cards are unchanged.
  • <sup>Written for commit d82f472d0d58a17ec5203f86985dc0b6ebf980f0. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/we-promise/sure/pull/5993?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/we-promise/sure/5993?returnTo=https%3A%2F%2Fgithub.com%2Fwe-promise%2Fsure%2Fpull%2F5993&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Credit cards now support introductory APRs, expiration dates, and the rates that apply afterward.
    The overview displays the effective APR and, while an introductory rate is active, its expiration date, time remaining, and subsequent rate.
    Credit-card forms, imports, and account details support introductory APR information; reported APRs reflect the rate effective on the requested date.
    * Interest calculations account for APR changes during a billing cycle.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jaysbeekay Review duration: 6962m
    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 #5993"
    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%