diff --git a/src/Altinn.Dan.Plugin.Banking/Plugin.cs b/src/Altinn.Dan.Plugin.Banking/Plugin.cs index de3c607..d8a593d 100644 --- a/src/Altinn.Dan.Plugin.Banking/Plugin.cs +++ b/src/Altinn.Dan.Plugin.Banking/Plugin.cs @@ -188,9 +188,10 @@ private async Task> GetEvidenceValuesBankTransaksjoner(Evide KARResponse karResponse; try { - DateTimeOffset todayDto = new DateTimeOffset(DateTime.Now); + DateTimeOffset fromDateDto = new DateTimeOffset(fromDate); + DateTimeOffset toDateDto = new DateTimeOffset(toDate); //Skipping KAR lookups can be set both in requests and config, useful for testing in different environments to see if all banks are responding as expected - karResponse = await _karService.GetBanksForCustomer(ssn, todayDto, todayDto, accountInfoRequestId, correlationId, skipKAR || _settings.SkipKAR); + karResponse = await _karService.GetBanksForCustomer(ssn, fromDateDto, toDateDto, accountInfoRequestId, correlationId, skipKAR || _settings.SkipKAR); } catch (ApiException e) { diff --git a/src/Altinn.Dan.Plugin.Banking/Services/BankService.cs b/src/Altinn.Dan.Plugin.Banking/Services/BankService.cs index d0121a2..c706a19 100644 --- a/src/Altinn.Dan.Plugin.Banking/Services/BankService.cs +++ b/src/Altinn.Dan.Plugin.Banking/Services/BankService.cs @@ -136,14 +136,14 @@ private async Task GetAccountDetailsV2(Bank_v2.Bank_v2 bankClient,Bank new CancellationTokenSource(TimeSpan.FromSeconds(TransactionRequestTimeoutSecs)); _logger.LogInformation("Getting transactions: bank {0} account {1} dob {2} accountinforequestid {3} correlationid {4}", - account.Servicer.Name, account.AccountIdentifier, account.PrimaryOwner.Identifier.Value.Substring(0,6), accountInfoRequestId, correlationIdTransactions); + account.Servicer.Name, account.AccountIdentifier, account.PrimaryOwner?.Identifier?.Value?.Substring(0,6), accountInfoRequestId, correlationIdTransactions); var transactionsTask = bankClient.ListTransactionsAsync(account.AccountReference, accountInfoRequestId, correlationIdTransactions, "OED", null, null, null, fromDate, toDate, transactionsTimeout.Token); _logger.LogInformation("Getting account details: bank {0} account {1} dob {2} accountinforequestid {4} correlationid {5}", - account.Servicer.Name, account.AccountIdentifier, account.PrimaryOwner.Identifier.Value.Substring(0, 6), accountInfoRequestId, correlationIdDetails); + account.Servicer.Name, account.AccountIdentifier, account.PrimaryOwner?.Identifier?.Value?.Substring(0, 6), accountInfoRequestId, correlationIdDetails); var detailsTimeout = @@ -152,7 +152,7 @@ private async Task GetAccountDetailsV2(Bank_v2.Bank_v2 bankClient,Bank correlationIdDetails, "OED", null, null, null, fromDate , toDate, detailsTimeout.Token); _logger.LogInformation("Retrieved account details: bank {0} account {1} dob {2} details {3} accountinforequestid {4} correlationid {5}", - account.Servicer.Name, account.AccountIdentifier, account.PrimaryOwner.Identifier.Value.Substring(0, 6), details.ResponseDetails.Status, accountInfoRequestId, correlationIdDetails); + account.Servicer.Name, account.AccountIdentifier, account.PrimaryOwner?.Identifier?.Value?.Substring(0, 6), details.ResponseDetails.Status, accountInfoRequestId, correlationIdDetails); if (details.Account == null) { diff --git a/src/Altinn.Dan.Plugin.Banking/Services/KARService.cs b/src/Altinn.Dan.Plugin.Banking/Services/KARService.cs index 839170d..47944f4 100644 --- a/src/Altinn.Dan.Plugin.Banking/Services/KARService.cs +++ b/src/Altinn.Dan.Plugin.Banking/Services/KARService.cs @@ -10,6 +10,7 @@ using Altinn.Dan.Plugin.Banking.Config; using Altinn.Dan.Plugin.Banking.Models; using Altinn.Dan.Plugin.Banking.Services.Interfaces; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Altinn.Dan.Plugin.Banking.Services; @@ -21,18 +22,21 @@ public class KARService : IKARService private readonly IHttpClientFactory _httpClientFactory; private readonly IMaskinportenService _maskinportenService; private readonly ApplicationSettings _settings; + private readonly ILogger _Logger; - public KARService(IHttpClientFactory httpClientFactory, IMaskinportenService maskinportenService, IOptions applicationSettings) + public KARService(IHttpClientFactory httpClientFactory, IMaskinportenService maskinportenService, IOptions applicationSettings, ILoggerFactory loggerFactory) { _httpClientFactory = httpClientFactory; _maskinportenService = maskinportenService; _settings = applicationSettings.Value; + _Logger = loggerFactory.CreateLogger(); } public async Task GetBanksForCustomer(string ssn, DateTimeOffset fromDate, DateTimeOffset toDate, Guid accountInfoRequestId, Guid correlationId, bool skipKAR) { if (skipKAR) { + _Logger.LogInformation("Skipping KAR for accountinforequestid {accountinforequestid} and correlationid {correlationId}", accountInfoRequestId.ToString(), correlationId.ToString()); return await GetAllImplementedBanks(); } @@ -46,8 +50,12 @@ public async Task GetBanksForCustomer(string ssn, DateTimeOffset fr var karTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(KarRequestTimeoutSecs)); - return await kar.Get(ssn, token.AccessToken, fromDate.ToString("yyyy-MM-dd"), toDate.ToString("yyyy-MM-dd"), + var result = await kar.Get(ssn, token.AccessToken, fromDate.ToString("yyyy-MM-dd"), toDate.ToString("yyyy-MM-dd"), accountInfoRequestId, correlationId, karTimeout.Token); + + _Logger.LogInformation("Retrieved from Kar {accountsCount} from accountinforequestid {accountinforequestid} and correlationid {correlationid}", result.Banks.Count, accountInfoRequestId.ToString(), correlationId.ToString()); + + return result; } private static readonly KARResponse ImplementedBanksCache = new() { Banks = new List() };