mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
feat: Add institution details to Plaid items (#1816)
* feat: Add institution details to Plaid items - Fetch and store institution URL, ID, and primary color for Plaid items - Update PlaidItem model to retrieve and save institution metadata - Add new method in Plaid provider to get institution details - Update account logo view to use institution domain for logo generation * Add institution domain method to Account model - Extract institution domain logic from view to Account model - Simplify logo view by using new institution_domain method - Improve code reusability and separation of concerns
This commit is contained in:
parent
df5f4c83fe
commit
7ba9063e04
7 changed files with 46 additions and 6 deletions
|
@ -32,6 +32,11 @@ class Account < ApplicationRecord
|
|||
|
||||
accepts_nested_attributes_for :accountable, update_only: true
|
||||
|
||||
def institution_domain
|
||||
return nil unless plaid_account&.plaid_item&.institution_url.present?
|
||||
URI.parse(plaid_account.plaid_item.institution_url).host.gsub(/^www\./, "")
|
||||
end
|
||||
|
||||
class << self
|
||||
def by_group(period: Period.all, currency: Money.default_currency.iso_code)
|
||||
grouped_accounts = { assets: ValueGroup.new("Assets", currency), liabilities: ValueGroup.new("Liabilities", currency) }
|
||||
|
|
|
@ -62,6 +62,20 @@ class PlaidItem < ApplicationRecord
|
|||
item = plaid_provider.get_item(access_token).item
|
||||
update!(available_products: item.available_products, billed_products: item.billed_products)
|
||||
|
||||
# Fetch and store institution details
|
||||
if item.institution_id.present?
|
||||
begin
|
||||
institution = plaid_provider.get_institution(item.institution_id)
|
||||
update!(
|
||||
institution_id: item.institution_id,
|
||||
institution_url: institution.institution.url,
|
||||
institution_color: institution.institution.primary_color
|
||||
)
|
||||
rescue Plaid::ApiError => e
|
||||
Rails.logger.warn("Error fetching institution details for item #{id}: #{e.message}")
|
||||
end
|
||||
end
|
||||
|
||||
fetched_accounts = plaid_provider.get_item_accounts(self).accounts
|
||||
data[:accounts] = fetched_accounts || []
|
||||
|
||||
|
|
|
@ -143,6 +143,17 @@ class Provider::Plaid
|
|||
response.liabilities
|
||||
end
|
||||
|
||||
def get_institution(institution_id)
|
||||
request = Plaid::InstitutionsGetByIdRequest.new({
|
||||
institution_id: institution_id,
|
||||
country_codes: country_codes,
|
||||
options: {
|
||||
include_optional_metadata: true
|
||||
}
|
||||
})
|
||||
client.institutions_get_by_id(request)
|
||||
end
|
||||
|
||||
private
|
||||
TransactionSyncResponse = Struct.new :added, :modified, :removed, :cursor, keyword_init: true
|
||||
InvestmentsResponse = Struct.new :holdings, :transactions, :securities, keyword_init: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue