The personal finance app for everyone (by everyone)
Ruby
Fetch Plaid liabilities for credit accounts of any subtype (#3531)
Brian Espinoza4fde3ffb1037
diff --git a/app/models/plaid_account/processor.rb b/app/models/plaid_account/processor.rbindex 4f2af022d5..35279040fc 100644--- a/app/models/plaid_account/processor.rb+++ b/app/models/plaid_account/processor.rb@@ -111,12 +111,19 @@ class PlaidAccount::Processorenddef process_liabilities- case [ plaid_account.plaid_type, plaid_account.plaid_subtype ]- when [ "credit", "credit card" ]+ type = plaid_account.plaid_type+ subtype = plaid_account.plaid_subtype++ # The `credit` branch is deliberately subtype-agnostic, mirroring+ # AccountsSnapshot#can_fetch_liabilities?. Matching only "credit card"+ # here meant a credit/paypal account fetched and stored the raw+ # liabilities response but never updated minimum_payment or apr, leaving+ # the user-visible figures blank.+ if type == "credit"PlaidAccount::Liabilities::CreditProcessor.new(plaid_account).process- when [ "loan", "mortgage" ]+ elsif type == "loan" && subtype == "mortgage"PlaidAccount::Liabilities::MortgageProcessor.new(plaid_account).process- when [ "loan", "student" ]+ elsif type == "loan" && subtype == "student"PlaidAccount::Liabilities::StudentLoanProcessor.new(plaid_account).processendrescue => ediff --git a/app/models/plaid_item/accounts_snapshot.rb b/app/models/plaid_item/accounts_snapshot.rbindex dc62d8ff30..b086544bb2 100644--- a/app/models/plaid_item/accounts_snapshot.rb+++ b/app/models/plaid_item/accounts_snapshot.rb@@ -93,7 +93,11 @@ class PlaidItem::AccountsSnapshotdef can_fetch_liabilities?plaid_item.supports_product?("liabilities") &&accounts.any? do |a|- a.type == "credit" && a.subtype == "credit card" ||+ # Plaid's `credit` type has two subtypes: "credit card" and "paypal".+ # Liabilities covers both, so match on the type rather than allow-listing+ # a single subtype -- otherwise a PayPal Credit account leaves+ # `liabilities` in billed_products (i.e. billed) but never fetched.+ a.type == "credit" ||a.type == "loan" && (a.subtype == "mortgage" || a.subtype == "student")endenddiff --git a/test/models/plaid_account/processor_test.rb b/test/models/plaid_account/processor_test.rbindex fffbe26257..dc7bbca2c8 100644--- a/test/models/plaid_account/processor_test.rb+++ b/test/models/plaid_account/processor_test.rb@@ -131,6 +131,23 @@ class PlaidAccount::ProcessorTest < ActiveSupport::TestCasePlaidAccount::Processor.new(@plaid_account).processend+ test "processes credit liability data for non-credit-card subtypes" do+ # Plaid reports PayPal Credit as credit/paypal. Dispatching only on+ # ["credit", "credit card"] left these accounts with a stored liabilities+ # payload but no minimum_payment or apr.+ expect_investment_product_processor_calls+ expect_no_investment_balance_calculator_calls+ expect_depository_product_processor_calls++ @plaid_account.update!(plaid_type: "credit", plaid_subtype: "paypal")++ PlaidAccount::Liabilities::CreditProcessor.any_instance.expects(:process).once+ PlaidAccount::Liabilities::MortgageProcessor.any_instance.expects(:process).never+ PlaidAccount::Liabilities::StudentLoanProcessor.any_instance.expects(:process).never++ PlaidAccount::Processor.new(@plaid_account).process+ end+test "processes mortgage liability data" doexpect_investment_product_processor_callsexpect_no_investment_balance_calculator_calls