public async Task <List <BankAccountTransactionModel> > GetBankAccountTransactionsAsync(Guid userId, Guid assetId) { string cacheKey = $"{assetId}_{nameof(BankAccountTransactionModel)}s"; AssetBankAccount account = await _bankAccountRepository.GetByAssetIdAsync(userId, assetId); if (account == null) { throw new Exception("Asset bank account not found."); } if (_cache.TryGetValue(cacheKey, out List <BankAccountTransactionModel> transactions)) { return(transactions); } IBankIntegrationService bankAccountservice = _bankIntegrationServiceResolver.Resolve(account.BankName); // TODO: Remove hard-coded dates. DateTime now = DateTime.UtcNow; DateTime from = new DateTime(now.Year, now.Month, 1); var requestParams = new AccountStatementRequestParams(account.Token, account.BankAccountId, account.BankClientId, from, now); var accountTransactions = await bankAccountservice.GetAccountTransactionsAsync(requestParams); transactions = accountTransactions .Select(t => new BankAccountTransactionModel(assetId, t.TransactionDate, t.Description, t.Currency, t.Amount, t.Balance)) .ToList(); _cache.Set(cacheKey, transactions, TimeSpan.FromMinutes(5)); return(transactions); }
public async Task <IReadOnlyCollection <ExternalAccountTransactionModel> > GetAccountTransactionsAsync(AccountStatementRequestParams requestParams) { IReadOnlyCollection <MonobankAccountTransaction> statementItems = await _accountService.GetAccountTransactionsAsync(requestParams.Token, requestParams.Account, requestParams.From, requestParams.To); List <ExternalAccountTransactionModel> transactions = statementItems .Select(i => new ExternalAccountTransactionModel(i.Id, i.TransactionDate, i.Description, i.Currency.Name, i.Amount, i.Balance)) .ToList(); return(transactions); }
public async Task <IReadOnlyCollection <ExternalAccountTransactionModel> > GetAccountTransactionsAsync(AccountStatementRequestParams requestParams) { PrivatbankAccountStatement statement = await _accountService.GetMerchantAccountStatementAsync( requestParams.Token, requestParams.BankClientId, requestParams.Account, requestParams.From, requestParams.To); if (statement == null || statement.Items == null) { return(new List <ExternalAccountTransactionModel>()); } List <ExternalAccountTransactionModel> transactions = statement.Items .Select(i => new ExternalAccountTransactionModel( i.AppCode, i.TransactionDate, i.Description, i.TransactionAmount.Currency, i.TransactionAmount.Value, i.AccountBalance.Value)) .ToList(); return(transactions); }