mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
fix: Properly compute credit card balance for Enable Banking accounts (#663)
* fix: Properly compute credit card balance for Enable Banking accounts * fix: Use right balance type codes * fix: Update comment
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user