From bab097ed0a6eaa39c4b3dc67ee3b0f6285ee4e1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:39:56 +0000 Subject: [PATCH 1/8] Initial plan From d472148fbf4bb22c47f5e57ec2e12c587bbe9612 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:44:38 +0000 Subject: [PATCH 2/8] refactor GetMerchant mapping helpers Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- ...tionProcessorACLApplicationServiceTests.cs | 13 ++ ...ansactionProcessorACLApplicationService.cs | 161 +++++++++++------- 2 files changed, 114 insertions(+), 60 deletions(-) diff --git a/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs b/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs index 06ffc95..79c7fce 100644 --- a/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs +++ b/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs @@ -418,6 +418,19 @@ public async Task VoucherManagementACLApplicationService_GetMerchant_MerchantRet merchantResponse.IsSuccess.ShouldBeTrue(); merchantResponse.Data.ShouldNotBeNull(); merchantResponse.Data.MerchantId.ShouldBe(TestData.MerchantId); + merchantResponse.Data.Addresses.Count.ShouldBe(1); + merchantResponse.Data.Addresses[0].AddressLine1.ShouldBe(TestData.AddressLine1); + merchantResponse.Data.Addresses[0].Town.ShouldBe(TestData.Town); + merchantResponse.Data.Contacts.Count.ShouldBe(1); + merchantResponse.Data.Contacts[0].ContactName.ShouldBe(TestData.ContactName); + merchantResponse.Data.Contacts[0].ContactEmailAddress.ShouldBe(TestData.ContactEmail); + merchantResponse.Data.Contracts.Count.ShouldBe(1); + merchantResponse.Data.Contracts[0].ContractId.ShouldBe(TestData.ContractId); + merchantResponse.Data.Contracts[0].ContractProducts.ShouldContain(TestData.ProductId); + merchantResponse.Data.Devices[TestData.DeviceId].ShouldBe(TestData.DeviceIdentifier); + merchantResponse.Data.Operators.Count.ShouldBe(1); + merchantResponse.Data.Operators[0].MerchantNumber.ShouldBe(TestData.MerchantNumber); + merchantResponse.Data.Operators[0].TerminalNumber.ShouldBe(TestData.TerminalNumber); } [Fact] diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index 6767e04..333e1a6 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -521,82 +521,123 @@ public async Task> GetMerchant(Guid estateId, Logger.LogWarning($"in GetMerchant - {JsonConvert.SerializeObject(result.Data)}"); - 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 merchantResponse = this.BuildMerchantResponse(result.Data); + + return merchantResponse; + } + + private MerchantResponse BuildMerchantResponse(TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse merchant) { + MerchantResponse merchantResponse = new() { + MerchantId = merchant.MerchantId, + EstateId = merchant.EstateId, + MerchantName = merchant.MerchantName, + EstateReportingId = merchant.EstateReportingId, + MerchantReference = merchant.MerchantReference, + NextStatementDate = merchant.NextStatementDate, + SettlementSchedule = merchant.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 + }, + Contracts = new(), + Contacts = new(), + Addresses = new(), + Devices = new(), + Operators = new() }; - merchantResponse.Contracts = new(); - merchantResponse.Contacts = new(); - merchantResponse.Addresses = new(); - merchantResponse.Devices = new(); - merchantResponse.Operators = new(); - - if (result.Data.Addresses != null) { - 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); - } + + this.PopulateMerchantAddresses(merchant.Addresses, merchantResponse); + this.PopulateMerchantContacts(merchant.Contacts, merchantResponse); + this.PopulateMerchantContracts(merchant.Contracts, merchantResponse); + this.PopulateMerchantDevices(merchant.Devices, merchantResponse); + this.PopulateMerchantOperators(merchant.Operators, merchantResponse); + + return merchantResponse; + } + + private void PopulateMerchantAddresses(List addresses, + MerchantResponse merchantResponse) { + if (addresses == null) { + return; } - if (result.Data.Contacts != null) { - 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 (TransactionProcessor.DataTransferObjects.Responses.Merchant.AddressResponse address in 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); } + } - if (result.Data.Contracts != null) { + private void PopulateMerchantContacts(List contacts, + MerchantResponse merchantResponse) { + if (contacts == null) { + return; + } - 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); - } + foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse contact in contacts) { + merchantResponse.Contacts.Add(new ContactResponse { + ContactId = contact.ContactId, + ContactName = contact.ContactName, + ContactPhoneNumber = contact.ContactPhoneNumber, + ContactEmailAddress = contact.ContactEmailAddress + }); + } + } - merchantResponse.Contracts.Add(contract); - } + private void PopulateMerchantContracts(List contracts, + MerchantResponse merchantResponse) { + if (contracts == null) { + return; } - if (result.Data.Devices != null) { - foreach (KeyValuePair device in result.Data.Devices) { - merchantResponse.Devices.Add(device.Key, device.Value); + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantContractResponse merchantContract in contracts) { + MerchantContractResponse contract = new() { ContractId = merchantContract.ContractId, IsDeleted = merchantContract.IsDeleted, ContractProducts = new() }; + foreach (Guid contractProduct in merchantContract.ContractProducts) { + contract.ContractProducts.Add(contractProduct); } + + merchantResponse.Contracts.Add(contract); } + } - if (result.Data.Operators != null) { + private void PopulateMerchantDevices(Dictionary devices, + MerchantResponse merchantResponse) { + if (devices == null) { + return; + } - 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 - }); - } + foreach (KeyValuePair device in devices) { + merchantResponse.Devices.Add(device.Key, device.Value); } + } - return merchantResponse; + private void PopulateMerchantOperators(List operators, + MerchantResponse merchantResponse) { + if (operators == null) { + return; + } + + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse merchantOperator in operators) { + merchantResponse.Operators.Add(new MerchantOperatorResponse { + OperatorId = merchantOperator.OperatorId, + IsDeleted = merchantOperator.IsDeleted, + MerchantNumber = merchantOperator.MerchantNumber, + Name = merchantOperator.Name, + TerminalNumber = merchantOperator.TerminalNumber + }); + } } #endregion } -} \ No newline at end of file +} From 537b3c7bf238e0ad0495d77de05649e59393e115 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:50:29 +0000 Subject: [PATCH 3/8] polish GetMerchant helper extraction Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../TransactionProcessorACLApplicationService.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index 333e1a6..9f5a3b1 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -601,22 +601,23 @@ private void PopulateMerchantContracts(List() : new List(merchantContract.ContractProducts) + }; merchantResponse.Contracts.Add(contract); } } - private void PopulateMerchantDevices(Dictionary devices, + private void PopulateMerchantDevices(Dictionary devices, MerchantResponse merchantResponse) { if (devices == null) { return; } - foreach (KeyValuePair device in devices) { + foreach (KeyValuePair device in devices) { merchantResponse.Devices.Add(device.Key, device.Value); } } From 27508f63bd6eae75a7392c703e041757f9b63dd7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:09:57 +0000 Subject: [PATCH 4/8] use static factory for merchant response mapping Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- ...ansactionProcessorACLApplicationService.cs | 191 +++++++++--------- 1 file changed, 97 insertions(+), 94 deletions(-) diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index 9f5a3b1..9ade822 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -521,121 +521,124 @@ public async Task> GetMerchant(Guid estateId, Logger.LogWarning($"in GetMerchant - {JsonConvert.SerializeObject(result.Data)}"); - MerchantResponse merchantResponse = this.BuildMerchantResponse(result.Data); + MerchantResponse merchantResponse = MerchantResponseFactory.Build(result.Data); return merchantResponse; } - private MerchantResponse BuildMerchantResponse(TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse merchant) { - MerchantResponse merchantResponse = new() { - MerchantId = merchant.MerchantId, - EstateId = merchant.EstateId, - MerchantName = merchant.MerchantName, - EstateReportingId = merchant.EstateReportingId, - MerchantReference = merchant.MerchantReference, - NextStatementDate = merchant.NextStatementDate, - SettlementSchedule = merchant.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 - }, - Contracts = new(), - Contacts = new(), - Addresses = new(), - Devices = new(), - Operators = new() - }; - - this.PopulateMerchantAddresses(merchant.Addresses, merchantResponse); - this.PopulateMerchantContacts(merchant.Contacts, merchantResponse); - this.PopulateMerchantContracts(merchant.Contracts, merchantResponse); - this.PopulateMerchantDevices(merchant.Devices, merchantResponse); - this.PopulateMerchantOperators(merchant.Operators, merchantResponse); + private static class MerchantResponseFactory + { + public static MerchantResponse Build(TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse merchant) { + MerchantResponse merchantResponse = new() { + MerchantId = merchant.MerchantId, + EstateId = merchant.EstateId, + MerchantName = merchant.MerchantName, + EstateReportingId = merchant.EstateReportingId, + MerchantReference = merchant.MerchantReference, + NextStatementDate = merchant.NextStatementDate, + SettlementSchedule = merchant.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 + }, + Contracts = new(), + Contacts = new(), + Addresses = new(), + Devices = new(), + Operators = new() + }; - return merchantResponse; - } + PopulateMerchantAddresses(merchant.Addresses, merchantResponse); + PopulateMerchantContacts(merchant.Contacts, merchantResponse); + PopulateMerchantContracts(merchant.Contracts, merchantResponse); + PopulateMerchantDevices(merchant.Devices, merchantResponse); + PopulateMerchantOperators(merchant.Operators, merchantResponse); - private void PopulateMerchantAddresses(List addresses, - MerchantResponse merchantResponse) { - if (addresses == null) { - return; + return merchantResponse; } - foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.AddressResponse address in 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); - } - } + private static void PopulateMerchantAddresses(List addresses, + MerchantResponse merchantResponse) { + if (addresses == null) { + return; + } - private void PopulateMerchantContacts(List contacts, - MerchantResponse merchantResponse) { - if (contacts == null) { - return; + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.AddressResponse address in 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 contacts) { - merchantResponse.Contacts.Add(new ContactResponse { - ContactId = contact.ContactId, - ContactName = contact.ContactName, - ContactPhoneNumber = contact.ContactPhoneNumber, - ContactEmailAddress = contact.ContactEmailAddress - }); - } - } + private static void PopulateMerchantContacts(List contacts, + MerchantResponse merchantResponse) { + if (contacts == null) { + return; + } - private void PopulateMerchantContracts(List contracts, - MerchantResponse merchantResponse) { - if (contracts == null) { - return; + foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse contact in contacts) { + merchantResponse.Contacts.Add(new ContactResponse { + ContactId = contact.ContactId, + ContactName = contact.ContactName, + ContactPhoneNumber = contact.ContactPhoneNumber, + ContactEmailAddress = contact.ContactEmailAddress + }); + } } - foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantContractResponse merchantContract in contracts) { - MerchantContractResponse contract = new() { - ContractId = merchantContract.ContractId, - IsDeleted = merchantContract.IsDeleted, - ContractProducts = merchantContract.ContractProducts == null ? new List() : new List(merchantContract.ContractProducts) - }; + private static void PopulateMerchantContracts(List contracts, + MerchantResponse merchantResponse) { + if (contracts == null) { + return; + } - merchantResponse.Contracts.Add(contract); - } - } + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantContractResponse merchantContract in contracts) { + MerchantContractResponse contract = new() { + ContractId = merchantContract.ContractId, + IsDeleted = merchantContract.IsDeleted, + ContractProducts = merchantContract.ContractProducts == null ? new List() : new List(merchantContract.ContractProducts) + }; - private void PopulateMerchantDevices(Dictionary devices, - MerchantResponse merchantResponse) { - if (devices == null) { - return; + merchantResponse.Contracts.Add(contract); + } } - foreach (KeyValuePair device in devices) { - merchantResponse.Devices.Add(device.Key, device.Value); - } - } + private static void PopulateMerchantDevices(Dictionary devices, + MerchantResponse merchantResponse) { + if (devices == null) { + return; + } - private void PopulateMerchantOperators(List operators, - MerchantResponse merchantResponse) { - if (operators == null) { - return; + foreach (KeyValuePair device in devices) { + merchantResponse.Devices.Add(device.Key, device.Value); + } } - foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse merchantOperator in operators) { - merchantResponse.Operators.Add(new MerchantOperatorResponse { - OperatorId = merchantOperator.OperatorId, - IsDeleted = merchantOperator.IsDeleted, - MerchantNumber = merchantOperator.MerchantNumber, - Name = merchantOperator.Name, - TerminalNumber = merchantOperator.TerminalNumber - }); + private static void PopulateMerchantOperators(List operators, + MerchantResponse merchantResponse) { + if (operators == null) { + return; + } + + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse merchantOperator in operators) { + merchantResponse.Operators.Add(new MerchantOperatorResponse { + OperatorId = merchantOperator.OperatorId, + IsDeleted = merchantOperator.IsDeleted, + MerchantNumber = merchantOperator.MerchantNumber, + Name = merchantOperator.Name, + TerminalNumber = merchantOperator.TerminalNumber + }); + } } } From 13706e12c1526fe10807490e2346b0a0d03dcf25 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:20:12 +0000 Subject: [PATCH 5/8] extract response factory to dedicated file Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Services/ResponseFactory.cs | 124 ++++++++++++++++++ ...ansactionProcessorACLApplicationService.cs | 118 +---------------- 2 files changed, 125 insertions(+), 117 deletions(-) create mode 100644 TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs diff --git a/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs new file mode 100644 index 0000000..cf5f807 --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using TransactionProcessorACL.BusinessLogic.Models; +using ContractContactResponse = TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse; +using ModelContactResponse = TransactionProcessorACL.BusinessLogic.Models.ContactResponse; + +namespace TransactionProcessorACL.BusinessLogic.Services +{ + public static class ResponseFactory + { + public static MerchantResponse Build(TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse merchant) { + MerchantResponse merchantResponse = new() { + MerchantId = merchant.MerchantId, + EstateId = merchant.EstateId, + MerchantName = merchant.MerchantName, + EstateReportingId = merchant.EstateReportingId, + MerchantReference = merchant.MerchantReference, + NextStatementDate = merchant.NextStatementDate, + SettlementSchedule = merchant.SettlementSchedule switch { + TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Immediate => SettlementSchedule.Immediate, + TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Weekly => SettlementSchedule.Weekly, + TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Monthly => SettlementSchedule.Monthly, + _ => SettlementSchedule.NotSet + }, + Contracts = new(), + Contacts = new(), + Addresses = new(), + Devices = new(), + Operators = new() + }; + + PopulateMerchantAddresses(merchant.Addresses, merchantResponse); + PopulateMerchantContacts(merchant.Contacts, merchantResponse); + PopulateMerchantContracts(merchant.Contracts, merchantResponse); + PopulateMerchantDevices(merchant.Devices, merchantResponse); + PopulateMerchantOperators(merchant.Operators, merchantResponse); + + return merchantResponse; + } + + private static void PopulateMerchantAddresses(List addresses, + MerchantResponse merchantResponse) { + if (addresses == null) { + return; + } + + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.AddressResponse address in 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); + } + } + + private static void PopulateMerchantContacts(List contacts, + MerchantResponse merchantResponse) { + if (contacts == null) { + return; + } + + foreach (ContractContactResponse contact in contacts) { + merchantResponse.Contacts.Add(new ModelContactResponse { + ContactId = contact.ContactId, + ContactName = contact.ContactName, + ContactPhoneNumber = contact.ContactPhoneNumber, + ContactEmailAddress = contact.ContactEmailAddress + }); + } + } + + private static void PopulateMerchantContracts(List contracts, + MerchantResponse merchantResponse) { + if (contracts == null) { + return; + } + + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantContractResponse merchantContract in contracts) { + MerchantContractResponse contract = new() { + ContractId = merchantContract.ContractId, + IsDeleted = merchantContract.IsDeleted, + ContractProducts = merchantContract.ContractProducts == null ? new List() : new List(merchantContract.ContractProducts) + }; + + merchantResponse.Contracts.Add(contract); + } + } + + private static void PopulateMerchantDevices(Dictionary devices, + MerchantResponse merchantResponse) { + if (devices == null) { + return; + } + + foreach (KeyValuePair device in devices) { + merchantResponse.Devices.Add(device.Key, device.Value); + } + } + + private static void PopulateMerchantOperators(List operators, + MerchantResponse merchantResponse) { + if (operators == null) { + return; + } + + foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse merchantOperator in operators) { + merchantResponse.Operators.Add(new MerchantOperatorResponse { + OperatorId = merchantOperator.OperatorId, + IsDeleted = merchantOperator.IsDeleted, + MerchantNumber = merchantOperator.MerchantNumber, + Name = merchantOperator.Name, + TerminalNumber = merchantOperator.TerminalNumber + }); + } + } + } +} diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index 9ade822..3d13108 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -521,127 +521,11 @@ public async Task> GetMerchant(Guid estateId, Logger.LogWarning($"in GetMerchant - {JsonConvert.SerializeObject(result.Data)}"); - MerchantResponse merchantResponse = MerchantResponseFactory.Build(result.Data); + MerchantResponse merchantResponse = ResponseFactory.Build(result.Data); return merchantResponse; } - private static class MerchantResponseFactory - { - public static MerchantResponse Build(TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse merchant) { - MerchantResponse merchantResponse = new() { - MerchantId = merchant.MerchantId, - EstateId = merchant.EstateId, - MerchantName = merchant.MerchantName, - EstateReportingId = merchant.EstateReportingId, - MerchantReference = merchant.MerchantReference, - NextStatementDate = merchant.NextStatementDate, - SettlementSchedule = merchant.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 - }, - Contracts = new(), - Contacts = new(), - Addresses = new(), - Devices = new(), - Operators = new() - }; - - PopulateMerchantAddresses(merchant.Addresses, merchantResponse); - PopulateMerchantContacts(merchant.Contacts, merchantResponse); - PopulateMerchantContracts(merchant.Contracts, merchantResponse); - PopulateMerchantDevices(merchant.Devices, merchantResponse); - PopulateMerchantOperators(merchant.Operators, merchantResponse); - - return merchantResponse; - } - - private static void PopulateMerchantAddresses(List addresses, - MerchantResponse merchantResponse) { - if (addresses == null) { - return; - } - - foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.AddressResponse address in 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); - } - } - - private static void PopulateMerchantContacts(List contacts, - MerchantResponse merchantResponse) { - if (contacts == null) { - return; - } - - foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse contact in contacts) { - merchantResponse.Contacts.Add(new ContactResponse { - ContactId = contact.ContactId, - ContactName = contact.ContactName, - ContactPhoneNumber = contact.ContactPhoneNumber, - ContactEmailAddress = contact.ContactEmailAddress - }); - } - } - - private static void PopulateMerchantContracts(List contracts, - MerchantResponse merchantResponse) { - if (contracts == null) { - return; - } - - foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantContractResponse merchantContract in contracts) { - MerchantContractResponse contract = new() { - ContractId = merchantContract.ContractId, - IsDeleted = merchantContract.IsDeleted, - ContractProducts = merchantContract.ContractProducts == null ? new List() : new List(merchantContract.ContractProducts) - }; - - merchantResponse.Contracts.Add(contract); - } - } - - private static void PopulateMerchantDevices(Dictionary devices, - MerchantResponse merchantResponse) { - if (devices == null) { - return; - } - - foreach (KeyValuePair device in devices) { - merchantResponse.Devices.Add(device.Key, device.Value); - } - } - - private static void PopulateMerchantOperators(List operators, - MerchantResponse merchantResponse) { - if (operators == null) { - return; - } - - foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse merchantOperator in operators) { - merchantResponse.Operators.Add(new MerchantOperatorResponse { - OperatorId = merchantOperator.OperatorId, - IsDeleted = merchantOperator.IsDeleted, - MerchantNumber = merchantOperator.MerchantNumber, - Name = merchantOperator.Name, - TerminalNumber = merchantOperator.TerminalNumber - }); - } - } - } - #endregion } } From 332a7b1f48095c7c934ef99db2cbe7f9023674fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 16:17:43 +0000 Subject: [PATCH 6/8] fix response factory model namespace Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Services/ResponseFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs index cf5f807..3e59a79 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; -using TransactionProcessorACL.BusinessLogic.Models; +using TransactionProcessorACL.Models; using ContractContactResponse = TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse; -using ModelContactResponse = TransactionProcessorACL.BusinessLogic.Models.ContactResponse; +using ModelContactResponse = TransactionProcessorACL.Models.ContactResponse; namespace TransactionProcessorACL.BusinessLogic.Services { From 56f393a175afb70ae7e5d825eda7773efaf34a05 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 17:05:56 +0000 Subject: [PATCH 7/8] stabilize reconciliation login retry Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Shared/SharedSteps.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs index 1e31a5e..82798b1 100644 --- a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs @@ -96,10 +96,12 @@ public async Task GivenIAmLoggedInAsWithPasswordForMerchantForEstateWithClient(S EstateDetails1 estateDetails = this.TestingContext.GetEstateDetails(estateName); Guid merchantId = estateDetails.EstateDetails.GetMerchantId(merchantName); ClientDetails clientDetails = this.TestingContext.GetClientDetails(clientId); - - Result tokenResponseResult = await this.TestingContext.DockerHelper.SecurityServiceClient - .GetToken(username, password, clientId, clientDetails.ClientSecret, CancellationToken.None).ConfigureAwait(false); - tokenResponseResult.IsSuccess.ShouldBeTrue(); + Result tokenResponseResult = null; + await Retry.For(async () => { + tokenResponseResult = await this.TestingContext.DockerHelper.SecurityServiceClient + .GetToken(username, password, clientId, clientDetails.ClientSecret, CancellationToken.None).ConfigureAwait(false); + tokenResponseResult.IsSuccess.ShouldBeTrue(); + }); estateDetails.AddMerchantUserToken(merchantId, username, tokenResponseResult.Data.AccessToken); } /// @@ -485,4 +487,4 @@ public async Task WhenIGetTheMerchantContractInformationForMerchantForEstateTheR #endregion } -} \ No newline at end of file +} From fb9d894ff456bca72bb8a34278786f377751de9f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 17:12:20 +0000 Subject: [PATCH 8/8] stabilize merchant login in integration tests Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Shared/SharedSteps.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs index 82798b1..3a66e39 100644 --- a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs @@ -96,13 +96,15 @@ public async Task GivenIAmLoggedInAsWithPasswordForMerchantForEstateWithClient(S EstateDetails1 estateDetails = this.TestingContext.GetEstateDetails(estateName); Guid merchantId = estateDetails.EstateDetails.GetMerchantId(merchantName); ClientDetails clientDetails = this.TestingContext.GetClientDetails(clientId); - Result tokenResponseResult = null; + string? accessToken = null; await Retry.For(async () => { - tokenResponseResult = await this.TestingContext.DockerHelper.SecurityServiceClient - .GetToken(username, password, clientId, clientDetails.ClientSecret, CancellationToken.None).ConfigureAwait(false); - tokenResponseResult.IsSuccess.ShouldBeTrue(); - }); - estateDetails.AddMerchantUserToken(merchantId, username, tokenResponseResult.Data.AccessToken); + Result tokenResponseResult = await this.TestingContext.DockerHelper.SecurityServiceClient + .GetToken(username, password, clientId, clientDetails.ClientSecret, CancellationToken.None).ConfigureAwait(false); + tokenResponseResult.IsSuccess.ShouldBeTrue($"Failed to get merchant user token for '{username}' using client '{clientId}': {tokenResponseResult.Message}"); + accessToken = tokenResponseResult.Data.AccessToken; + }); + accessToken.ShouldNotBeNull(); + estateDetails.AddMerchantUserToken(merchantId, username, accessToken); } /// /// Givens the i am logged in as with password for merchant for estate with client.