Skip to content

Commit

Permalink
kar api v2 changes, improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
erlendoksvoll committed Oct 23, 2024
1 parent 04a7ded commit 1bf038b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Altinn.Dan.Plugin.Banking/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ private async Task<List<EvidenceValue>> 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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Altinn.Dan.Plugin.Banking/Services/BankService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ private async Task<BankInfo> 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 =
Expand All @@ -152,7 +152,7 @@ private async Task<BankInfo> 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)
{
Expand Down
12 changes: 10 additions & 2 deletions src/Altinn.Dan.Plugin.Banking/Services/KARService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> applicationSettings)
public KARService(IHttpClientFactory httpClientFactory, IMaskinportenService maskinportenService, IOptions<ApplicationSettings> applicationSettings, ILoggerFactory loggerFactory)
{
_httpClientFactory = httpClientFactory;
_maskinportenService = maskinportenService;
_settings = applicationSettings.Value;
_Logger = loggerFactory.CreateLogger<KARService>();
}

public async Task<KARResponse> 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();
}

Expand All @@ -46,8 +50,12 @@ public async Task<KARResponse> 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<CustomerRelation>() };
Expand Down

0 comments on commit 1bf038b

Please sign in to comment.