fix(Enable Banking): Restore legacy fallback for credit card balance calculation (#1477)

* fix: Restore legacy fallback for credit card balance calculation in Enable Banking

* test: update test following new behavior

* test: keep old test

* fix: use absolute value for balance computation
This commit is contained in:
Alessio Cappa
2026-04-15 23:25:41 +02:00
committed by GitHub
parent 156694494d
commit 3eedf5137d
2 changed files with 23 additions and 0 deletions

View File

@@ -55,6 +55,12 @@ class EnableBankingAccount::Processor
unless account.accountable.present?
Rails.logger.warn "EnableBankingAccount::Processor - CreditCard accountable missing for account #{account.id}"
end
elsif account.accountable&.available_credit.present?
# Fallback: no credit_limit from API — compute it using available_credit defined at account level
Rails.logger.info "Using stored available_credit fallback for account #{account.id}"
available_credit = account.accountable.available_credit
outstanding = balance.abs
balance = [ available_credit - outstanding, 0 ].max
else
# Fallback: no credit_limit from API — display raw outstanding balance
# We cannot derive available credit without knowing the limit; leave balance unchanged.

View File

@@ -59,9 +59,26 @@ class EnableBankingAccount::ProcessorTest < ActiveSupport::TestCase
end
end
test "falls back to stored available_credit when credit_limit is absent" do
cc_account = accounts(:credit_card)
cc_account.accountable.update!(available_credit: 1000.0)
@enable_banking_account.update!(current_balance: 300.00, credit_limit: nil)
AccountProvider.find_by(provider: @enable_banking_account)&.destroy
AccountProvider.create!(account: cc_account, provider: @enable_banking_account)
EnableBankingAccount::Processor.new(@enable_banking_account).process
assert_equal 700.0, cc_account.reload.cash_balance
end
test "sets CC balance to raw outstanding when credit_limit is absent" do
cc_account = accounts(:credit_card)
cc_account.accountable.update!(available_credit: nil)
@enable_banking_account.update!(current_balance: 300.00, credit_limit: nil)
AccountProvider.find_by(provider: @enable_banking_account)&.destroy
AccountProvider.create!(account: cc_account, provider: @enable_banking_account)