diff --git a/app/models/enable_banking_account/processor.rb b/app/models/enable_banking_account/processor.rb index 3b5741b17..ada55916f 100644 --- a/app/models/enable_banking_account/processor.rb +++ b/app/models/enable_banking_account/processor.rb @@ -38,8 +38,12 @@ class EnableBankingAccount::Processor account = enable_banking_account.current_account balance = enable_banking_account.current_balance || 0 + # For credit cards, compute balance based on credit limit + if account.accountable_type == "CreditCard" + available_credit = account.accountable.available_credit || 0 + balance = available_credit - balance # For liability accounts, ensure positive balances - if account.accountable_type == "CreditCard" || account.accountable_type == "Loan" + elsif account.accountable_type == "Loan" balance = -balance end diff --git a/app/models/enable_banking_item/importer.rb b/app/models/enable_banking_item/importer.rb index 60b1e4d04..178d146f2 100644 --- a/app/models/enable_banking_item/importer.rb +++ b/app/models/enable_banking_item/importer.rb @@ -134,9 +134,11 @@ class EnableBankingItem::Importer balances = balance_data[:balances] || [] return if balances.empty? - # Find the most relevant balance (prefer "closingBooked" or "expected") - balance = balances.find { |b| b[:balance_type] == "closingBooked" } || - balances.find { |b| b[:balance_type] == "expected" } || + # Find the most relevant balance (prefer "ITAV" or "CLAV" types) + balance = balances.find { |b| b[:balance_type] == "ITAV" } || + balances.find { |b| b[:balance_type] == "CLAV" } || + balances.find { |b| b[:balance_type] == "ITBD" } || + balances.find { |b| b[:balance_type] == "CLBD" } || balances.first if balance.present?