From ec312d581de58ce093dd102b632dc1a6d60a9190 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Mar 2026 14:45:12 +0000 Subject: [PATCH 1/2] Initial plan From 93d6e303cf402f14d602c3b809816b798523aaf1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Mar 2026 14:56:43 +0000 Subject: [PATCH 2/2] Refactor merchant deposit complexity Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Services/MerchantDomainService.cs | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs index c1af5881..0846395f 100644 --- a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs @@ -175,6 +175,23 @@ private SettlementSchedule ConvertSettlementSchedule(DataTransferObjects.Respons _ => SettlementSchedule.NotSet }; + private MerchantDepositSource ConvertDepositSource(DataTransferObjects.Requests.Merchant.MerchantDepositSource depositSource) => + depositSource switch + { + DataTransferObjects.Requests.Merchant.MerchantDepositSource.Manual => MerchantDepositSource.Manual, + _ => MerchantDepositSource.Automatic, + }; + + private Result EnsureMerchantDepositListCreated(MerchantDepositListAggregate merchantDepositListAggregate, + MerchantAggregate merchantAggregate, + DateTime depositDateTime) { + if (merchantDepositListAggregate.IsCreated) { + return Result.Success(); + } + + return merchantDepositListAggregate.Create(merchantAggregate, depositDateTime); + } + public async Task CreateMerchant(MerchantCommands.CreateMerchantCommand command, CancellationToken cancellationToken) { try { @@ -310,19 +327,12 @@ public async Task MakeMerchantDeposit(MerchantCommands.MakeMerchantDepos return ResultHelpers.CreateFailure(getDepositListResult); MerchantDepositListAggregate merchantDepositListAggregate = getDepositListResult.Data; - if (merchantDepositListAggregate.IsCreated == false) - { - Result createResult = merchantDepositListAggregate.Create(merchantAggregate, command.RequestDto.DepositDateTime); - if (createResult.IsFailed) - return ResultHelpers.CreateFailure(createResult); - } + Result createResult = this.EnsureMerchantDepositListCreated(merchantDepositListAggregate, merchantAggregate, command.RequestDto.DepositDateTime); + if (createResult.IsFailed) + return ResultHelpers.CreateFailure(createResult); PositiveMoney amount = PositiveMoney.Create(Money.Create(command.RequestDto.Amount)); - MerchantDepositSource depositSource = command.DepositSource switch - { - DataTransferObjects.Requests.Merchant.MerchantDepositSource.Manual => MerchantDepositSource.Manual, - _ => MerchantDepositSource.Automatic, - }; + MerchantDepositSource depositSource = this.ConvertDepositSource(command.DepositSource); Result stateResult = merchantDepositListAggregate.MakeDeposit(depositSource, command.RequestDto.Reference, command.RequestDto.DepositDateTime, amount); if (stateResult.IsFailed) return ResultHelpers.CreateFailure(stateResult);