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/ResponseFactory.cs b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs new file mode 100644 index 0000000..3e59a79 --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using TransactionProcessorACL.Models; +using ContractContactResponse = TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse; +using ModelContactResponse = TransactionProcessorACL.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 6767e04..3d13108 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -521,82 +521,11 @@ 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.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); - } - } - - 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 }); - } - } - - if (result.Data.Contracts != null) { - - 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); - } - } - - if (result.Data.Devices != null) { - foreach (KeyValuePair device in result.Data.Devices) { - merchantResponse.Devices.Add(device.Key, device.Value); - } - } - - if (result.Data.Operators != null) { - - 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 - }); - } - } + MerchantResponse merchantResponse = ResponseFactory.Build(result.Data); return merchantResponse; } #endregion } -} \ No newline at end of file +} diff --git a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs index 1e31a5e..3a66e39 100644 --- a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs @@ -96,11 +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 = 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); + string? accessToken = null; + await Retry.For(async () => { + 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. @@ -485,4 +489,4 @@ public async Task WhenIGetTheMerchantContractInformationForMerchantForEstateTheR #endregion } -} \ No newline at end of file +}