public async Task <BankAccountBalance> GetBankAccountBalanceAsync(Guid userId, Guid assetId) { AssetBankAccount account = await _bankAccountRepository.GetByAssetIdAsync(userId, assetId); if (account == null) { throw new Exception("Asset bank account not found."); } BankModel bank = _bankService.GetBank(account.BankName); TimeSpan syncSpan = DateTime.UtcNow - account.LastSyncDateTime.Value; BankAccountBalance accountBalance = null; if (syncSpan.TotalSeconds > bank.SyncFreqInSeconds) { IBankIntegrationService bankAccountservice = _bankIntegrationServiceResolver.Resolve(account.BankName); var requestParams = new BankAccountsRequestParams(account.Token, account.BankClientId, account.BankAccountId); IReadOnlyCollection <ExternalAccountBalanceModel> accountBalances = await bankAccountservice.GetAccountsAsync(requestParams); ExternalAccountBalanceModel external = accountBalances.FirstOrDefault(ab => ab.AccountId == account.BankAccountId); accountBalance = new BankAccountBalance(external.BankName, external.AccountId, external.Currency, external.Balance); await _bankAccountRepository.UpdateLastSyncAsync(userId, assetId, DateTime.UtcNow, accountBalance.AccountName); await _unitOfWork.SaveChangesAsync(); } return(accountBalance); }
public async Task <IReadOnlyCollection <ExternalAccountBalanceModel> > GetAccountsAsync(BankAccountsRequestParams request) { PrivatbankAccount account = await _accountService.GetMerchantAccountAsync(request.Token, request.BankClientId, request.CardNumber); ExternalAccountBalanceModel balance = new ExternalAccountBalanceModel(BankName, account.Id, account.Currency, account.Balance); return(new List <ExternalAccountBalanceModel> { balance }); }