diff --git a/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs b/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs index d322901..12be9c1 100644 --- a/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs +++ b/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs @@ -34,6 +34,7 @@ public MediatorTests() this.Requests.Add(TestData.GetVoucherQuery); this.Requests.Add(TestData.RedeemVoucherCommand); this.Requests.Add(TestData.GetMerchantContractsQuery); + this.Requests.Add(TestData.GetMerchantQuery); } [Fact] @@ -149,5 +150,11 @@ public async Task>> GetMerchantContracts(Guid esta CancellationToken cancellationToken) { return Result.Success(new List()); } + + public async Task> GetMerchant(Guid estateId, + Guid merchantId, + CancellationToken cancellationToken) { + return Result.Success(new MerchantResponse()); + } } } diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs new file mode 100644 index 0000000..8629eeb --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using SimpleResults; +using TransactionProcessorACL.BusinessLogic.Requests; +using TransactionProcessorACL.BusinessLogic.Services; +using TransactionProcessorACL.Models; + +namespace TransactionProcessorACL.BusinessLogic.RequestHandlers; + +public class MerchantRequestHandler : IRequestHandler>>, +IRequestHandler> { + #region Fields + + private readonly ITransactionProcessorACLApplicationService ApplicationService; + + #endregion + + public MerchantRequestHandler(ITransactionProcessorACLApplicationService applicationService) { + this.ApplicationService = applicationService; + } + + public async Task>> Handle(MerchantQueries.GetMerchantContractsQuery request, + CancellationToken cancellationToken) { + return await this.ApplicationService.GetMerchantContracts(request.EstateId, request.MerchantId, cancellationToken); + } + + public async Task> Handle(MerchantQueries.GetMerchantQuery request, + CancellationToken cancellationToken) { + return await this.ApplicationService.GetMerchant(request.EstateId, request.MerchantId, cancellationToken); + } +} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs index eea634b..fdc1019 100644 --- a/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs +++ b/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs @@ -1,6 +1,5 @@ using MediatR; using System; -using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; @@ -50,21 +49,4 @@ public async Task> Handle(VoucherCommands.RedeemVo #endregion } - - public class MerchantRequestHandler : IRequestHandler>> { - #region Fields - - private readonly ITransactionProcessorACLApplicationService ApplicationService; - - #endregion - - public MerchantRequestHandler(ITransactionProcessorACLApplicationService applicationService) { - this.ApplicationService = applicationService; - } - - public async Task>> Handle(MerchantQueries.GetMerchantContractsQuery request, - CancellationToken cancellationToken) { - return await this.ApplicationService.GetMerchantContracts(request.EstateId, request.MerchantId, cancellationToken); - } - } } diff --git a/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs b/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs index 21ca24c..5d0ff8f 100644 --- a/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs +++ b/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs @@ -3,7 +3,9 @@ using System.Diagnostics.CodeAnalysis; using MediatR; using SimpleResults; +using TransactionProcessor.DataTransferObjects.Responses.Merchant; using TransactionProcessorACL.Models; +using MerchantResponse = TransactionProcessorACL.Models.MerchantResponse; namespace TransactionProcessorACL.BusinessLogic.Requests; @@ -40,5 +42,6 @@ public record ProcessReconciliationCommand(Guid EstateId, [ExcludeFromCodeCoverage] public record MerchantQueries { public record GetMerchantContractsQuery(Guid EstateId,Guid MerchantId) : IRequest>>; + public record GetMerchantQuery(Guid EstateId, Guid MerchantId) : IRequest>; } \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs index 48a066d..5d9da57 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs @@ -55,5 +55,9 @@ Task RedeemVoucher(Guid estateId, Task>> GetMerchantContracts(Guid estateId, Guid merchantId, CancellationToken cancellationToken); + + Task> GetMerchant(Guid estateId, + Guid merchantId, + CancellationToken cancellationToken); } } diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index 2e805f2..54f1299 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -496,7 +496,7 @@ public async Task RedeemVoucher(Guid estateId, List models = new(); foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse contractResponse in result.Data) { - var contractModel = new ContractResponse { + ContractResponse contractModel = new ContractResponse { ContractId = contractResponse.ContractId, ContractReportingId = contractResponse.ContractReportingId, Description = contractResponse.Description, @@ -508,7 +508,7 @@ public async Task RedeemVoucher(Guid estateId, }; foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProduct contractResponseProduct in contractResponse.Products) { - var productModel = new ContractProduct { + ContractProduct productModel = new ContractProduct { Value = contractResponseProduct.Value, DisplayText = contractResponseProduct.DisplayText, Name = contractResponseProduct.Name, @@ -524,7 +524,7 @@ public async Task RedeemVoucher(Guid estateId, }; foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProductTransactionFee contractProductTransactionFee in contractResponseProduct.TransactionFees) { - var transactionFeeModel = new ContractProductTransactionFee { + ContractProductTransactionFee transactionFeeModel = new ContractProductTransactionFee { Value = contractProductTransactionFee.Value, Description = contractProductTransactionFee.Description, CalculationType = contractProductTransactionFee.CalculationType switch { @@ -550,6 +550,103 @@ public async Task RedeemVoucher(Guid estateId, return Result.Success(models); } + public async Task> GetMerchant(Guid estateId, + Guid merchantId, + CancellationToken cancellationToken) { + // Get a client token to call the Transaction Processor + String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId"); + String clientSecret = ConfigurationReader.GetValue("AppSettings", "ClientSecret"); + + TokenResponse accessToken = await this.SecurityServiceClient.GetToken(clientId, clientSecret, cancellationToken); + + ProcessLogonTransactionResponse response = null; + + Result result = await this.TransactionProcessorClient.GetMerchant(accessToken.AccessToken, estateId, merchantId, cancellationToken); + + if (result.IsFailed) + return Result.Failure($"Error getting merchant contracts {result.Message}"); + MerchantResponse merchantResponse = new(); + merchantResponse.MerchantId = result.Data.MerchantId; + merchantResponse.EstateId = result.Data.EstateId; + merchantResponse.MerchantName = result.Data.MerchantName; + merchantResponse.EstateReportingId = result.Data.EstateReportingId; + merchantResponse.MerchantReference = result.Data.MerchantReference; + merchantResponse.NextStatementDate = result.Data.NextStatementDate; + merchantResponse.SettlementSchedule = result.Data.SettlementSchedule switch { + TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Immediate => Models.SettlementSchedule.Immediate, + TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Weekly => SettlementSchedule.Weekly, + TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Monthly => SettlementSchedule.Monthly, + _ => SettlementSchedule.NotSet + }; + merchantResponse.Contracts = new(); + merchantResponse.Contacts = new(); + merchantResponse.Addresses = new(); + merchantResponse.Devices = new(); + merchantResponse.Operators = new(); + + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.AddressResponse address in result.Data.Addresses) + { + AddressResponse addressResponse = new() + { + AddressId = address.AddressId, + AddressLine1 = address.AddressLine1, + AddressLine2 = address.AddressLine2, + AddressLine3 = address.AddressLine3, + AddressLine4 = address.AddressLine4, + Country = address.Country, + PostalCode = address.PostalCode, + Region = address.Region, + Town = address.Town + }; + merchantResponse.Addresses.Add(addressResponse); + } + + foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse contact in result.Data.Contacts) + { + merchantResponse.Contacts.Add(new ContactResponse + { + ContactId = contact.ContactId, + ContactName = contact.ContactName, + ContactPhoneNumber = contact.ContactPhoneNumber, + ContactEmailAddress = contact.ContactEmailAddress + }); + } + + foreach (var merchantContract in result.Data.Contracts) + { + var contract = new MerchantContractResponse + { + ContractId = merchantContract.ContractId, + IsDeleted = merchantContract.IsDeleted, + ContractProducts = new() + }; + foreach (Guid contractProduct in merchantContract.ContractProducts) + { + contract.ContractProducts.Add(contractProduct); + } + merchantResponse.Contracts.Add(contract); + } + + foreach (KeyValuePair device in result.Data.Devices) + { + merchantResponse.Devices.Add(device.Key, device.Value); + } + + foreach (var merchantOperator in result.Data.Operators) + { + merchantResponse.Operators.Add(new MerchantOperatorResponse + { + OperatorId = merchantOperator.OperatorId, + IsDeleted = merchantOperator.IsDeleted, + MerchantNumber = merchantOperator.MerchantNumber, + Name = merchantOperator.Name, + TerminalNumber = merchantOperator.TerminalNumber + }); + } + + return merchantResponse; + } + #endregion } } \ No newline at end of file diff --git a/TransactionProcessorACL.DataTransferObjects/Responses/MerchantResponse.cs b/TransactionProcessorACL.DataTransferObjects/Responses/MerchantResponse.cs new file mode 100644 index 0000000..ff10544 --- /dev/null +++ b/TransactionProcessorACL.DataTransferObjects/Responses/MerchantResponse.cs @@ -0,0 +1,139 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace TransactionProcessorACL.DataTransferObjects.Responses { + + [ExcludeFromCodeCoverage] + public class MerchantResponse + { + [JsonProperty("addresses")] + public List Addresses { get; set; } + + [JsonProperty("contacts")] + public List Contacts { get; set; } + + [JsonProperty("devices")] + public Dictionary Devices { get; set; } + + [JsonProperty("estate_id")] + public Guid EstateId { get; set; } + + [JsonProperty("estate_reporting_id")] + public int EstateReportingId { get; set; } + + [JsonProperty("merchant_id")] + public Guid MerchantId { get; set; } + + [JsonProperty("merchant_reporting_id")] + public int MerchantReportingId { get; set; } + + [JsonProperty("merchant_name")] + public string MerchantName { get; set; } + + [JsonProperty("merchant_reference")] + public string MerchantReference { get; set; } + + [JsonProperty("next_statement_date")] + public DateTime NextStatementDate { get; set; } + + [JsonProperty("operators")] + public List Operators { get; set; } + + [JsonProperty("settlement_schedule")] + public SettlementSchedule SettlementSchedule { get; set; } + + [JsonProperty("contracts")] + public List Contracts { get; set; } + } + + [ExcludeFromCodeCoverage] + public class AddressResponse + { + [JsonProperty("address_id")] + public Guid AddressId { get; set; } + + [JsonProperty("address_line_1")] + public string AddressLine1 { get; set; } + + [JsonProperty("address_line_2")] + public string AddressLine2 { get; set; } + + [JsonProperty("address_line_3")] + public string AddressLine3 { get; set; } + + [JsonProperty("address_line_4")] + public string AddressLine4 { get; set; } + + [JsonProperty("country")] + public string Country { get; set; } + + [JsonProperty("postal_code")] + public string PostalCode { get; set; } + + [JsonProperty("region")] + public string Region { get; set; } + + [JsonProperty("town")] + public string Town { get; set; } + } + + [ExcludeFromCodeCoverage] + public class ContactResponse + { + [JsonProperty("contact_email_address")] + public string ContactEmailAddress { get; set; } + + [JsonProperty("contact_id")] + public Guid ContactId { get; set; } + + [JsonProperty("contact_name")] + public string ContactName { get; set; } + + [JsonProperty("contact_phone_number")] + public string ContactPhoneNumber { get; set; } + } + + [ExcludeFromCodeCoverage] + public class MerchantOperatorResponse + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("operator_id")] + public Guid OperatorId { get; set; } + + [JsonProperty("merchant_number")] + public string MerchantNumber { get; set; } + + [JsonProperty("terminal_number")] + public string TerminalNumber { get; set; } + + [JsonProperty("is_deleted")] + public bool IsDeleted { get; set; } + } + + [ExcludeFromCodeCoverage] + public class MerchantContractResponse + { + [JsonProperty("contract_id")] + public Guid ContractId { get; set; } + + [JsonProperty("is_deleted")] + public bool IsDeleted { get; set; } + + [JsonProperty("contract_products")] + public List ContractProducts { get; set; } + + public MerchantContractResponse() => this.ContractProducts = new List(); + } + + public enum SettlementSchedule + { + NotSet, + Immediate, + Weekly, + Monthly, + } +} \ No newline at end of file diff --git a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs index 69427e7..f5fe690 100644 --- a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs @@ -155,8 +155,8 @@ public async Task GivenIHaveAssignedTheFollowingDevicesToTheMerchants(DataTable List estates = this.TestingContext.Estates.Select(e => e.EstateDetails).ToList(); List<(EstateDetails, Guid, AddMerchantDeviceRequest)> requests = table.Rows.ToAddMerchantDeviceRequests(estates); - List<(EstateDetails, MerchantResponse, String)> results = await this.TransactionProcessorSteps.GivenIHaveAssignedTheFollowingDevicesToTheMerchants(this.TestingContext.AccessToken, requests); - foreach ((EstateDetails, MerchantResponse, String) result in results){ + List<(EstateDetails, TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse, String)> results = await this.TransactionProcessorSteps.GivenIHaveAssignedTheFollowingDevicesToTheMerchants(this.TestingContext.AccessToken, requests); + foreach ((EstateDetails, TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse, String) result in results){ this.TestingContext.Logger.LogInformation($"Device {result.Item3} assigned to Merchant {result.Item2.MerchantName} Estate {result.Item1.EstateName}"); } } @@ -291,9 +291,9 @@ public async Task WhenIAssignTheFollowingOperatorToTheMerchants(DataTable table) List estates = this.TestingContext.Estates.Select(e => e.EstateDetails).ToList(); List<(EstateDetails, Guid, AssignOperatorRequest)> requests = table.Rows.ToAssignOperatorRequests(estates); - List<(EstateDetails, MerchantOperatorResponse)> results = await this.TransactionProcessorSteps.WhenIAssignTheFollowingOperatorToTheMerchants(this.TestingContext.AccessToken, requests); + List<(EstateDetails, TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse)> results = await this.TransactionProcessorSteps.WhenIAssignTheFollowingOperatorToTheMerchants(this.TestingContext.AccessToken, requests); - foreach ((EstateDetails, MerchantOperatorResponse) result in results){ + foreach ((EstateDetails, TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse) result in results){ this.TestingContext.Logger.LogInformation($"Operator {result.Item2.Name} assigned to Estate {result.Item1.EstateName}"); } } @@ -322,12 +322,12 @@ public async Task WhenICreateTheFollowingEstates(DataTable table){ [Given("I create the following merchants")] [When(@"I create the following merchants")] public async Task WhenICreateTheFollowingMerchants(DataTable table){ - var estates = this.TestingContext.Estates.Select(e => e.EstateDetails).ToList(); + List estates = this.TestingContext.Estates.Select(e => e.EstateDetails).ToList(); List<(EstateDetails estate, CreateMerchantRequest)> requests = table.Rows.ToCreateMerchantRequests(estates); - List verifiedMerchants = await this.TransactionProcessorSteps.WhenICreateTheFollowingMerchants(this.TestingContext.AccessToken, requests); + List verifiedMerchants = await this.TransactionProcessorSteps.WhenICreateTheFollowingMerchants(this.TestingContext.AccessToken, requests); - foreach (MerchantResponse verifiedMerchant in verifiedMerchants){ + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse verifiedMerchant in verifiedMerchants){ EstateDetails1 estateDetails = this.TestingContext.GetEstateDetails(verifiedMerchant.EstateId); estateDetails.EstateDetails.AddMerchant(verifiedMerchant); this.TestingContext.Logger.LogInformation($"Merchant {verifiedMerchant.MerchantName} created with Id {verifiedMerchant.MerchantId} for Estate {estateDetails.EstateDetails.EstateName}"); diff --git a/TransactionProcessorACL.Models/MerchantResponse.cs b/TransactionProcessorACL.Models/MerchantResponse.cs new file mode 100644 index 0000000..958215d --- /dev/null +++ b/TransactionProcessorACL.Models/MerchantResponse.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TransactionProcessorACL.Models +{ + public class MerchantResponse + { + public List Addresses { get; set; } + + public List Contacts { get; set; } + + public Dictionary Devices { get; set; } + + public Guid EstateId { get; set; } + + public int EstateReportingId { get; set; } + + public Guid MerchantId { get; set; } + + public int MerchantReportingId { get; set; } + + public string MerchantName { get; set; } + + public string MerchantReference { get; set; } + + public DateTime NextStatementDate { get; set; } + + public List Operators { get; set; } + + public SettlementSchedule SettlementSchedule { get; set; } + + public List Contracts { get; set; } + } + + [ExcludeFromCodeCoverage] + public class AddressResponse + { + public Guid AddressId { get; set; } + + public string AddressLine1 { get; set; } + + public string AddressLine2 { get; set; } + + public string AddressLine3 { get; set; } + + public string AddressLine4 { get; set; } + + public string Country { get; set; } + + public string PostalCode { get; set; } + + public string Region { get; set; } + + public string Town { get; set; } + } + + [ExcludeFromCodeCoverage] + public class ContactResponse + { + public string ContactEmailAddress { get; set; } + + public Guid ContactId { get; set; } + + public string ContactName { get; set; } + + public string ContactPhoneNumber { get; set; } + } + + [ExcludeFromCodeCoverage] + public class MerchantOperatorResponse + { + public string Name { get; set; } + + public Guid OperatorId { get; set; } + + public string MerchantNumber { get; set; } + + public string TerminalNumber { get; set; } + public bool IsDeleted { get; set; } + } + + [ExcludeFromCodeCoverage] + public class MerchantContractResponse + { + public Guid ContractId { get; set; } + + public bool IsDeleted { get; set; } + + public List ContractProducts { get; set; } + + public MerchantContractResponse() => this.ContractProducts = new List(); + } + + public enum SettlementSchedule + { + NotSet, + Immediate, + Weekly, + Monthly, + } +} diff --git a/TransactionProcessorACL.Testing/TestData.cs b/TransactionProcessorACL.Testing/TestData.cs index b8c62b4..ebc86b0 100644 --- a/TransactionProcessorACL.Testing/TestData.cs +++ b/TransactionProcessorACL.Testing/TestData.cs @@ -240,6 +240,7 @@ public class TestData public static VersionCheckCommands.VersionCheckCommand VersionCheckCommand = new(TestData.ApplicationVersion); public static VoucherCommands.RedeemVoucherCommand RedeemVoucherCommand => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); public static MerchantQueries.GetMerchantContractsQuery GetMerchantContractsQuery => new(EstateId,MerchantId); + public static MerchantQueries.GetMerchantQuery GetMerchantQuery => new(EstateId, MerchantId); public static VoucherQueries.GetVoucherQuery GetVoucherQuery => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); diff --git a/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs b/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs index 2fb4cda..a39b398 100644 --- a/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs +++ b/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs @@ -37,6 +37,7 @@ public MediatorRegistry() this.AddSingleton>, VoucherRequestHandler>(); this.AddSingleton>>, MerchantRequestHandler>(); + this.AddSingleton>, MerchantRequestHandler>(); } #endregion diff --git a/TransactionProcessorACL/Controllers/MerchantController.cs b/TransactionProcessorACL/Controllers/MerchantController.cs index d91684c..780dae7 100644 --- a/TransactionProcessorACL/Controllers/MerchantController.cs +++ b/TransactionProcessorACL/Controllers/MerchantController.cs @@ -132,6 +132,113 @@ public async Task GetMerchantContracts([FromQuery] String applica return Result.Success(responses).ToActionResultX(); } + [HttpGet] + [Route("")] + public async Task GetMerchant([FromQuery] String applicationVersion, + CancellationToken cancellationToken) + { + if (ClaimsHelper.IsPasswordToken(this.User) == false) + { + return this.Forbid(); + } + + // Do the software version check + VersionCheckCommand versionCheckCommand = new(applicationVersion); + Result versionCheckResult = await this.Mediator.Send(versionCheckCommand, cancellationToken); + if (versionCheckResult.IsFailed) + return this.StatusCode(505); + + Result<(Guid estateId, Guid merchantId)> claimsResult = TransactionController.GetRequiredClaims(this.User); + if (claimsResult.IsFailed) + return this.Forbid(); + + MerchantQueries.GetMerchantQuery query = new(claimsResult.Data.estateId, claimsResult.Data.merchantId); + Result result = await this.Mediator.Send(query, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result).ToActionResultX(); + + // Now need to convert to the DTO type for returning to the caller + DataTransferObjects.Responses.MerchantResponse response = new() { + EstateId = result.Data.EstateId, + MerchantId = result.Data.MerchantId, + EstateReportingId = result.Data.EstateReportingId, + MerchantName = result.Data.MerchantName, + MerchantReference = result.Data.MerchantReference, + MerchantReportingId = result.Data.MerchantReportingId, + NextStatementDate = result.Data.NextStatementDate, + SettlementSchedule = result.Data.SettlementSchedule switch + { + SettlementSchedule.Weekly => DataTransferObjects.Responses.SettlementSchedule.Weekly, + SettlementSchedule.Monthly => DataTransferObjects.Responses.SettlementSchedule.Monthly, + _ => DataTransferObjects.Responses.SettlementSchedule.NotSet + }, + Addresses = new(), + Contacts = new(), + Contracts = new(), + Devices = new(), + Operators = new() + }; + + foreach (AddressResponse addressModel in result.Data.Addresses) + { + DataTransferObjects.Responses.AddressResponse addressResponse = new() + { + AddressId = addressModel.AddressId, + AddressLine1 = addressModel.AddressLine1, + AddressLine2 = addressModel.AddressLine2, + AddressLine3 = addressModel.AddressLine3, + AddressLine4 = addressModel.AddressLine4, + Country = addressModel.Country, + PostalCode = addressModel.PostalCode, + Region = addressModel.Region, + Town = addressModel.Town + }; + response.Addresses.Add(addressResponse); + } + + foreach (ContactResponse contactResponse in result.Data.Contacts) { + response.Contacts.Add(new DataTransferObjects.Responses.ContactResponse + { + ContactId = contactResponse.ContactId, + ContactName = contactResponse.ContactName, + ContactPhoneNumber = contactResponse.ContactPhoneNumber, + ContactEmailAddress = contactResponse.ContactEmailAddress + }); + } + + foreach (MerchantContractResponse merchantContractResponse in result.Data.Contracts) { + var contract = new DataTransferObjects.Responses.MerchantContractResponse + { + ContractId = merchantContractResponse.ContractId, + IsDeleted = merchantContractResponse.IsDeleted, + ContractProducts = new() + }; + foreach (Guid contractProduct in merchantContractResponse.ContractProducts) { + contract.ContractProducts.Add(contractProduct); + } + response.Contracts.Add(contract); + } + + foreach (KeyValuePair device in result.Data.Devices) + { + response.Devices.Add(device.Key, device.Value); + } + + foreach (MerchantOperatorResponse merchantOperatorResponse in result.Data.Operators) { + response.Operators.Add(new DataTransferObjects.Responses.MerchantOperatorResponse + { + OperatorId = merchantOperatorResponse.OperatorId, + IsDeleted = merchantOperatorResponse.IsDeleted, + MerchantNumber = merchantOperatorResponse.MerchantNumber, + Name = merchantOperatorResponse.Name, + TerminalNumber = merchantOperatorResponse.TerminalNumber + }); + } + + return Result.Success(response).ToActionResultX(); + } + #region Others ///