Store a card's intro APR expiry and step-up rate
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:):aprbeforeintro_apr_expires_on,after_intro_aprfrom 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 anapr; the step-up rate is ≥ 0. before_validation :end_intro_rate: a save that clearsintro_apr_expires_onwhile a rate after the intro is set moves that rate intoaprand clearsafter_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
aprin app/ — every one is listed):-
cycle_interest_money(up/card-daily-interest): each day charged at that day'seffective_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:)(fromup/card-daily-rate) andStatementSummary#daily_rate:effective_apr(on:)over the basis days, so the Overview's daily rate is the one charged onas_of. -
Overview APR tile:
effective_apr(on: today)and "Until (n days), then " while the intro runs;show_aprstill keys onapr. -
GetAccounts#credit_card_terms:apris the rate onas_of_date;after_intro_aprandintro_apr_expires_onadded. -
PlaidAccount::Liabilities::CreditProcessor#write_apr, throughenrich_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
aprsentry whoseapr_typeispurchase_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
aprfield 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. GetAccountsdescription:apris the rate in force on the date asked, and it says whatafter_intro_aprandintro_apr_expires_onmean.
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: 0and 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".
- "the edit form offers the intro rate and saves it" now sends
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(8ReleaseNotesWorkflowTesterrors, nonode). 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 | ![]() | ![]() |
| 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 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 | ![]() |
| Edit form, intro ended — light, phone | ![]() |
| Edit form, intro ended — dark, desktop | ![]() |
| Edit form, intro ended — dark, phone | ![]() |
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_interestand the helper's wording: a card without intro fields multiplies by the sameaprevery day, so the sum is unchanged (allup/card-daily-interestinterest 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_ratefires only on a save that clears the end date.Family::DataImporterbuilds new cards only, where the expiry goes nil → nil, so it never fires there.- Not changed here:
Enrichable#enrich_attributesreadslocked?before its transaction, so a lock saved mid-sync can still lose to that sync. The code is shared by everyenrich_attributecaller and is left alone here. Plaid's APR path reads no lock: it skips the APR while an intro runs and passesignore_locks: trueotherwise.
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
aprwhen 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 (n days), then " while the intro runs; the card form and family importer carry the new fields.
Migration
- Adds nullable
intro_apr_expires_onandafter_intro_aprcolumns; existing cards are unchanged.
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.



















