Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(enable-banking): gracefully skip PDNG fetch for ASPSPs that don't support it (#1789)

CrossDrain7b21a619ec9d
diff --git a/app/models/enable_banking_item/importer.rb b/app/models/enable_banking_item/importer.rb
index 7086642124..696b4f673c 100644
--- a/app/models/enable_banking_item/importer.rb
+++ b/app/models/enable_banking_item/importer.rb
@@ -243,12 +243,17 @@ class EnableBankingItem::Importer
pending_transactions = []
if include_pending
# Also fetch pending transactions (visible for 1-3 days before they become BOOK) if setting is enabled
- pending_transactions = fetch_paginated_transactions(
- enable_banking_account,
- start_date: start_date,
- transaction_status: "PDNG",
- psu_headers: enable_banking_item.build_psu_headers
- )
+ begin
+ pending_transactions = fetch_paginated_transactions(
+ enable_banking_account,
+ start_date: start_date,
+ transaction_status: "PDNG",
+ psu_headers: enable_banking_item.build_psu_headers
+ )
+ rescue Provider::EnableBanking::EnableBankingError => e
+ raise unless e.error_type == :validation_error && e.message.include?("transactionStatus")
+ Rails.logger.warn "EnableBankingItem::Importer - ASPSP does not support PDNG transaction status for account #{enable_banking_account.uid}, skipping pending transactions. API error: #{e.message}"
+ end
end
book_fingerprints = all_transactions
diff --git a/test/models/enable_banking_item/importer_error_handling_test.rb b/test/models/enable_banking_item/importer_error_handling_test.rb
index 305f079738..e5b9192cbf 100644
--- a/test/models/enable_banking_item/importer_error_handling_test.rb
+++ b/test/models/enable_banking_item/importer_error_handling_test.rb
@@ -63,6 +63,42 @@ class EnableBankingItem::ImporterErrorHandlingTest < ActiveSupport::TestCase
assert @enable_banking_item.reload.requires_update?
end
+ test "fetch_and_store_transactions succeeds and skips pending when ASPSP rejects PDNG transaction_status" do
+ enable_banking_account = EnableBankingAccount.new(uid: "test_uid")
+ @importer.stubs(:determine_sync_start_date).returns(Date.today)
+ @importer.stubs(:include_pending?).returns(true)
+
+ pdng_error = Provider::EnableBanking::EnableBankingError.new(
+ "Validation error from Enable Banking API: {\"message\":\"Wrong transactionStatus provided in getAccountTransactions call: PDNG\"}",
+ :validation_error
+ )
+
+ @importer.stubs(:fetch_paginated_transactions).with(enable_banking_account, has_entries(transaction_status: "BOOK")).returns([])
+ @importer.stubs(:fetch_paginated_transactions).with(enable_banking_account, has_entries(transaction_status: "PDNG")).raises(pdng_error)
+
+ result = @importer.send(:fetch_and_store_transactions, enable_banking_account)
+
+ assert result[:success]
+ end
+
+ test "fetch_and_store_transactions fails when validation error is unrelated to transactionStatus" do
+ enable_banking_account = EnableBankingAccount.new(uid: "test_uid")
+ @importer.stubs(:determine_sync_start_date).returns(Date.today)
+ @importer.stubs(:include_pending?).returns(true)
+
+ date_error = Provider::EnableBanking::EnableBankingError.new(
+ "Validation error from Enable Banking API: {\"message\":\"Invalid date_from format\"}",
+ :validation_error
+ )
+
+ @importer.stubs(:fetch_paginated_transactions).with(enable_banking_account, has_entries(transaction_status: "BOOK")).returns([])
+ @importer.stubs(:fetch_paginated_transactions).with(enable_banking_account, has_entries(transaction_status: "PDNG")).raises(date_error)
+
+ result = @importer.send(:fetch_and_store_transactions, enable_banking_account)
+
+ assert_not result[:success]
+ end
+
test "fetch_and_update_balance updates status to requires_update on unauthorized error" do
enable_banking_account = EnableBankingAccount.new(uid: "test_uid")
def @mock_provider.get_account_balances(**args)