using System; using System.Collections.Generic; using System.Threading.Tasks; using LCU.Library.Internal.ApiSecurity.Enums; using LCU.Library.Internal.ApiSecurity.Models; using LCU.Library.Internal.CoreApiWrapperLib.Configuration; using LCU.Library.Internal.CoreApiWrapperLib.CoreApiUtilities; using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities; using LCU.Library.Internal.CoreApiWrapperLib.Utilities; using LCU.Library.Internal.CoreApiWrapperModel.Constants; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Transaction; using LCU.Library.Internal.LcuHttpClient.HttpRequest; namespace LCU.Library.Internal.CoreApiWrapperLib.DataAccess { public class TransactionDao : BaseCoreDao, ITransactionDao { private readonly CoreApiConfiguration _coreApiConfiguration; private readonly CoreSoapApiConfiguration _coreSoapApiConfiguration; private readonly ApiSecurityConfiguration _apiSecurityConfiguration; private readonly ICoreDbExecution _coreDbExecution; private readonly IPostRequest _postRequest; private const string SoapClientKeyValue = "CoreSoapApiWrapper"; private const string GetExternalDescriptionsWithSSNQuery = "Transaction/GetExternalDescriptionsWithSSNQuery"; private const string UpdateExternalDescriptionQuery = "Transaction/UpdateExternalDescriptionQuery"; private const string GetTransactionsByDateSpanQuery = "Transaction/GetTransactionsByDateSpanQuery"; private const string RtxnTypCdQueryVerifyHolder = "{RtxnTypCdQueryVerifyHolder}"; private const string RtxnTypCdQueryParamHolder = "{RtxnTypCdQueryParamHolder}"; public TransactionDao(ICoreRequest coreRequest, CoreConfiguration coreConfiguration, ApiSecurityConfiguration apiSecurityConfiguration, ICoreDbExecution coreDbExecution, IPostRequest postRequest) : base(coreRequest) { _coreApiConfiguration = coreConfiguration.CoreApiConfiguration; _coreSoapApiConfiguration = coreConfiguration.CoreSoapApiConfiguration; _apiSecurityConfiguration = apiSecurityConfiguration; _coreDbExecution = coreDbExecution; _postRequest = postRequest; } /// /// Calls Core API to search based the AccountId and filled out TransactionHistoryRequest model. /// Default Included: Standard, Graph /// /// /// /// /// IEnumerable public async Task> FindTransactionHistoryById(CoreRequestParameters coreRequestParameters, TransactionHistoryRequest request, string accountId) { var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters); var endpoint = HttpUtilities.ReplaceRootParameter(_coreApiConfiguration.CoreEndPointConfiguration.AccountsTransactionHistoryQueryAccountNumber, RequestRootParameters.AccountId, accountId); var jsonBody = HttpUtilities.BuildJsonOfNonNullProperties(request); var result = await _coreRequest.PostRequestObject>>( endpoint, endpointParameters, jsonBody); return result?.MessageBody; } public async Task> AddMonetaryTransactions(List monetaryTransactionRequests) { var endpoint = HttpUtilities.BuildHttpsUri(_coreSoapApiConfiguration.CoreSoapApiWrapperHost, _coreSoapApiConfiguration.CoreSoapEndpointConfiguration.PostMonetaryTransactions); var headers = LcuHttpClient.Utilities.HttpUtilities.GetApiKeyHeaders(SoapClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(SoapClientKeyValue, ApiKeySetName.InternalKeySet)); return await _postRequest.Async, List>(endpoint, monetaryTransactionRequests, headers, 0); } public async Task> FindExternalDescriptionsWithSsn() { var query = QueryUtilities.GetQuery(GetExternalDescriptionsWithSSNQuery); return await _coreDbExecution.ExecuteQuery(query); } public async Task> PostFundsToAccount(List fundsToAccount) { var endpoint = HttpUtilities.BuildHttpsUri(_coreSoapApiConfiguration.CoreSoapApiWrapperHost, _coreSoapApiConfiguration.CoreSoapEndpointConfiguration.PostFundsToAccount); var headers = LcuHttpClient.Utilities.HttpUtilities.GetApiKeyHeaders(SoapClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(SoapClientKeyValue, ApiKeySetName.InternalKeySet)); return await _postRequest.Async, List>(endpoint, fundsToAccount, headers, 0); } /// /// Note: ExecuteQuery does not return anything when running an Update statement. /// /// public void UpdateExternalDescription(ExternalDescription externalTransactionDescription) { var query = QueryUtilities.GetQuery(UpdateExternalDescriptionQuery); var param = new { externaldescriptionnumber = externalTransactionDescription.ExternalDescriptionNumber, externaldescriptiontext = externalTransactionDescription.ExternalDescriptionText }; var result = _coreDbExecution.ExecuteQuery(query, param).Result; } public async Task> GetTransactionsByDateSpan(DateTime startDateRange, DateTime endDateRange, string rtxnTypCdToExcludeParams, string rtxnTypCdToExcludeVerify) { var query = QueryUtilities.GetQuery(GetTransactionsByDateSpanQuery); var alteredQuery = query.Replace(RtxnTypCdQueryVerifyHolder, rtxnTypCdToExcludeVerify)//; .Replace(RtxnTypCdQueryParamHolder, rtxnTypCdToExcludeParams); var param = new { startDateTime = startDateRange.ToString("yyyy-MM-dd HH:mm:ss"), endDateTime = endDateRange.ToString("yyyy-MM-dd HH:mm:ss") }; return await _coreDbExecution.ExecuteQuery(alteredQuery, param); } } }