From 7b4602da00c415d2b3e08e811b5c7cd69efa0993 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Sat, 15 Jul 2023 05:57:39 +0100 Subject: [PATCH 1/5] Split settlement streams by merchant --- .../VoucherDomainEventHandlerTests.cs | 14 ++--- .../Manager/VoucherManagementManagerTests.cs | 1 - .../Mediator/DummySettlementDomainService.cs | 1 + .../Requests/RequestTests.cs | 5 +- .../Services/SettlementDomainServiceTests.cs | 4 ++ .../Services/VoucherDomainServiceTests.cs | 2 - ...actionProcessor.BusinessLogic.Tests.csproj | 4 +- .../Common/Extensions.cs | 3 +- .../TransactionDomainEventHandler.cs | 4 +- .../VoucherDomainEventHandler.cs | 2 +- .../Manager/IVoucherManagementManager.cs | 4 +- .../SettlementRequestHandler.cs | 2 +- .../Requests/ProcessSettlementRequest.cs | 55 ++++++------------- .../Services/ISettlementDomainService.cs | 1 + .../Services/SettlementDomainService.cs | 3 +- .../TransactionProcessor.BusinessLogic.csproj | 4 +- .../ITransactionProcessorClient.cs | 9 +-- .../TransactionProcessorClient.cs | 6 +- .../Features/Settlement.feature | 16 +++--- .../Features/Settlement.feature.cs | 12 +++- .../Shared/SharedSteps.cs | 15 +++-- ...ansactionProcessor.IntegrationTests.csproj | 4 +- TransactionProcessor.Testing/TestData.cs | 9 ++- .../Controllers/SettlementController.cs | 13 +++-- 24 files changed, 100 insertions(+), 93 deletions(-) diff --git a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs index 930382d2..5878a3e0 100644 --- a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs @@ -74,13 +74,13 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithEmailAddress_ context.Transactions.Add(new EstateManagement.Database.Entities.Transaction() { TransactionId = TestData.TransactionId, - EstateId = TestData.EstateId, - ContractId = TestData.ContractId + MerchantReportingId = TestData.MerchantReportingId, + ContractReportingId = TestData.ContractReportingId }); context.Contracts.Add(new Contract { ContractId = TestData.ContractId, - EstateId = TestData.EstateId, + EstateReportingId = TestData.EstateReportingId, Description = TestData.OperatorIdentifier }); await context.SaveChangesAsync(CancellationToken.None); @@ -123,13 +123,13 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithRecipientMobi context.Transactions.Add(new EstateManagement.Database.Entities.Transaction() { TransactionId = TestData.TransactionId, - EstateId = TestData.EstateId, - ContractId = TestData.ContractId - }); + MerchantReportingId = TestData.MerchantReportingId, + ContractReportingId = TestData.ContractReportingId + }); context.Contracts.Add(new Contract { ContractId = TestData.ContractId, - EstateId = TestData.EstateId, + EstateReportingId = TestData.EstateReportingId, Description = TestData.OperatorIdentifier }); await context.SaveChangesAsync(CancellationToken.None); diff --git a/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs b/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs index 9156df0f..85ed4946 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs @@ -51,7 +51,6 @@ public async Task VoucherManagementManager_GetVoucherByCode_VoucherRetrieved() EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); await context.Vouchers.AddAsync(new Voucher { - EstateId = TestData.EstateId, VoucherId = TestData.VoucherId, VoucherCode = TestData.VoucherCode, OperatorIdentifier = TestData.OperatorIdentifier, diff --git a/TransactionProcessor.BusinessLogic.Tests/Mediator/DummySettlementDomainService.cs b/TransactionProcessor.BusinessLogic.Tests/Mediator/DummySettlementDomainService.cs index 31fb049d..75aae990 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Mediator/DummySettlementDomainService.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Mediator/DummySettlementDomainService.cs @@ -10,6 +10,7 @@ public class DummySettlementDomainService : ISettlementDomainService { public async Task ProcessSettlement(DateTime pendingSettlementDate, Guid estateId, + Guid merchantId, CancellationToken cancellationToken) { return new ProcessSettlementResponse(); } diff --git a/TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs b/TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs index 7aa6afd9..0aa20383 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs @@ -85,10 +85,13 @@ public void ProcessSaleTransactionRequest_CanBeCreated_IsCreated() { [Fact] public void ProcessSettlementRequest_CanBeCreated_IsCreated() { - ProcessSettlementRequest processSettlementRequest = ProcessSettlementRequest.Create(TestData.SettlementDate, TestData.EstateId); + ProcessSettlementRequest processSettlementRequest = ProcessSettlementRequest.Create(TestData.SettlementDate, + TestData.MerchantId, + TestData.EstateId); processSettlementRequest.ShouldNotBeNull(); processSettlementRequest.EstateId.ShouldBe(TestData.EstateId); + processSettlementRequest.MerchantId.ShouldBe(TestData.MerchantId); processSettlementRequest.SettlementDate.ShouldBe(TestData.SettlementDate); } diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs index 1c1254d7..bfd03203 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs @@ -50,6 +50,7 @@ public async Task SettlementDomainService_ProcessSettlement_SettlementIsProcesse ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate, TestData.EstateId, + TestData.MerchantId, CancellationToken.None); response.ShouldNotBeNull(); @@ -66,6 +67,7 @@ public async Task SettlementDomainService_ProcessSettlement_SettlementAggregateN ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate, TestData.EstateId, + TestData.MerchantId, CancellationToken.None); response.ShouldNotBeNull(); @@ -82,6 +84,7 @@ public async Task SettlementDomainService_ProcessSettlement_SettlementAggregateN ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate, TestData.EstateId, + TestData.MerchantId, CancellationToken.None); response.ShouldNotBeNull(); @@ -98,6 +101,7 @@ public async Task SettlementDomainService_ProcessSettlement_AddSettledFeeThrownE ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate, TestData.EstateId, + TestData.MerchantId, CancellationToken.None); response.ShouldNotBeNull(); diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs index 87bf5602..b9aad91e 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs @@ -237,7 +237,6 @@ public async Task VoucherDomainService_RedeemVoucher_InvalidEstate_ErrorThrown() EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); context.Vouchers.Add(new EstateManagement.Database.Entities.Voucher { VoucherCode = TestData.VoucherCode, - EstateId = TestData.EstateId, OperatorIdentifier = TestData.OperatorIdentifier }); await context.SaveChangesAsync(); @@ -276,7 +275,6 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherIssued() { EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); context.Vouchers.Add(new EstateManagement.Database.Entities.Voucher { VoucherCode = TestData.VoucherCode, - EstateId = TestData.EstateId, OperatorIdentifier = TestData.OperatorIdentifier }); await context.SaveChangesAsync(); diff --git a/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj b/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj index f2c04492..54fc638f 100644 --- a/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj +++ b/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/TransactionProcessor.BusinessLogic/Common/Extensions.cs b/TransactionProcessor.BusinessLogic/Common/Extensions.cs index fa41c47f..f1f21f22 100644 --- a/TransactionProcessor.BusinessLogic/Common/Extensions.cs +++ b/TransactionProcessor.BusinessLogic/Common/Extensions.cs @@ -13,9 +13,10 @@ namespace TransactionProcessor.BusinessLogic.Common public static class Helpers { public static Guid CalculateSettlementAggregateId(DateTime settlementDate, + Guid merchantId, Guid estateId) { - Guid aggregateId = GuidCalculator.Combine(estateId, settlementDate.ToGuid()); + Guid aggregateId = GuidCalculator.Combine(estateId,merchantId, settlementDate.ToGuid()); return aggregateId; } } diff --git a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs index 0da8fc91..42d10963 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs @@ -214,7 +214,7 @@ private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent do // Determine when the fee should be applied DateTime settlementDate = this.CalculateSettlementDate(merchant.SettlementSchedule, domainEvent.CompletedDateTime); - Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate, domainEvent.EstateId); + Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate, domainEvent.MerchantId, domainEvent.EstateId); // We need to add the fees to a pending settlement stream (for today) SettlementAggregate aggregate = await this.SettlementAggregateRepository.GetLatestVersion(aggregateId, cancellationToken); @@ -282,7 +282,7 @@ private async Task HandleSpecificDomainEvent(MerchantFeeAddedToTransactionEvent return; } - Guid aggregateId = Helpers.CalculateSettlementAggregateId(domainEvent.SettlementDueDate, domainEvent.EstateId); + Guid aggregateId = Helpers.CalculateSettlementAggregateId(domainEvent.SettlementDueDate, domainEvent.MerchantId, domainEvent.EstateId); SettlementAggregate pendingSettlementAggregate = await this.SettlementAggregateRepository.GetLatestVersion(aggregateId, cancellationToken); diff --git a/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs index c4e79be0..ed86a270 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs @@ -170,7 +170,7 @@ private async Task GetVoucherOperator(Models.Voucher voucherModel, EstateManagementGenericContext context = await this.DbContextFactory.GetContext(voucherModel.EstateId, ConnectionStringIdentifier, cancellationToken); Transaction transaction = await context.Transactions.SingleOrDefaultAsync(t => t.TransactionId == voucherModel.TransactionId, cancellationToken); - Contract contract = await context.Contracts.SingleOrDefaultAsync(c => c.ContractId == transaction.ContractId); + Contract contract = await context.Contracts.SingleOrDefaultAsync(c => c.ContractReportingId == transaction.ContractReportingId); return contract.Description; } diff --git a/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs b/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs index de13b5cc..1b1fefc4 100644 --- a/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs +++ b/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs @@ -102,8 +102,8 @@ public async Task GetVoucherByTransactionId(Guid estateId, CancellationToken cancellationToken) { EstateManagementGenericContext context = await this.DbContextFactory.GetContext(estateId, ConnectionStringIdentifier, cancellationToken); - - EstateManagement.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.TransactionId == transactionId, cancellationToken); + EstateManagement.Database.Entities.Transaction transaction = await context.Transactions.SingleOrDefaultAsync(t => t.TransactionId == transactionId, cancellationToken); + EstateManagement.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.TransactionReportingId == transaction.TransactionReportingId, cancellationToken); if (voucher == null) { diff --git a/TransactionProcessor.BusinessLogic/RequestHandlers/SettlementRequestHandler.cs b/TransactionProcessor.BusinessLogic/RequestHandlers/SettlementRequestHandler.cs index 1261493c..3857d13f 100644 --- a/TransactionProcessor.BusinessLogic/RequestHandlers/SettlementRequestHandler.cs +++ b/TransactionProcessor.BusinessLogic/RequestHandlers/SettlementRequestHandler.cs @@ -24,7 +24,7 @@ public SettlementRequestHandler(ISettlementDomainService settlementDomainService public async Task Handle(ProcessSettlementRequest request, CancellationToken cancellationToken) { - ProcessSettlementResponse processSettlementResponse = await this.SettlementDomainService.ProcessSettlement(request.SettlementDate, request.EstateId, cancellationToken); + ProcessSettlementResponse processSettlementResponse = await this.SettlementDomainService.ProcessSettlement(request.SettlementDate, request.EstateId, request.MerchantId, cancellationToken); return processSettlementResponse; } diff --git a/TransactionProcessor.BusinessLogic/Requests/ProcessSettlementRequest.cs b/TransactionProcessor.BusinessLogic/Requests/ProcessSettlementRequest.cs index 90ee835e..fd19ce21 100644 --- a/TransactionProcessor.BusinessLogic/Requests/ProcessSettlementRequest.cs +++ b/TransactionProcessor.BusinessLogic/Requests/ProcessSettlementRequest.cs @@ -1,20 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TransactionProcessor.BusinessLogic.Requests -{ +namespace TransactionProcessor.BusinessLogic.Requests{ + using System; using MediatR; using Models; - public class ProcessSettlementRequest : IRequest - { + public class ProcessSettlementRequest : IRequest{ #region Constructors - private ProcessSettlementRequest(DateTime settlementDate, Guid estateId) - { + private ProcessSettlementRequest(DateTime settlementDate, Guid merchantId, Guid estateId){ + this.MerchantId = merchantId; this.EstateId = estateId; this.SettlementDate = settlementDate; } @@ -22,39 +15,23 @@ private ProcessSettlementRequest(DateTime settlementDate, Guid estateId) #endregion #region Properties - - /// - /// Gets the estate identifier. - /// - /// - /// The estate identifier. - /// - public Guid EstateId { get; } - - - public DateTime SettlementDate { get; } - + + public Guid EstateId{ get; } + + public Guid MerchantId{ get; } + + public DateTime SettlementDate{ get; } + #endregion #region Methods - /// - /// Creates the specified estate identifier. - /// - /// The transaction identifier. - /// The estate identifier. - /// The merchant identifier. - /// The device identifier. - /// Type of the transaction. - /// The transaction date time. - /// The transaction number. - /// public static ProcessSettlementRequest Create(DateTime settlementDate, - Guid estateId) - { - return new ProcessSettlementRequest(settlementDate, estateId); + Guid merchantId, + Guid estateId){ + return new ProcessSettlementRequest(settlementDate, merchantId, estateId); } #endregion } -} +} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/Services/ISettlementDomainService.cs b/TransactionProcessor.BusinessLogic/Services/ISettlementDomainService.cs index f6467d00..828fb333 100644 --- a/TransactionProcessor.BusinessLogic/Services/ISettlementDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/ISettlementDomainService.cs @@ -12,6 +12,7 @@ public interface ISettlementDomainService { Task ProcessSettlement(DateTime pendingSettlementDate, Guid estateId, + Guid merchantId, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs b/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs index 925a480c..a90b21f1 100644 --- a/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs @@ -19,11 +19,12 @@ public class SettlementDomainService : ISettlementDomainService public async Task ProcessSettlement(DateTime settlementDate, Guid estateId, + Guid merchantId, CancellationToken cancellationToken) { ProcessSettlementResponse response = new ProcessSettlementResponse(); - Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate,estateId); + Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate, merchantId,estateId); SettlementAggregate settlementAggregate = await this.SettlementAggregateRepository.GetLatestVersion(aggregateId, cancellationToken); diff --git a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj index 12c59347..5ce54357 100644 --- a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj +++ b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/TransactionProcessor.Client/ITransactionProcessorClient.cs b/TransactionProcessor.Client/ITransactionProcessorClient.cs index 0b074b2a..e7b2c80f 100644 --- a/TransactionProcessor.Client/ITransactionProcessorClient.cs +++ b/TransactionProcessor.Client/ITransactionProcessorClient.cs @@ -17,11 +17,13 @@ Task PerformTransaction(String accessToken, Task GetSettlementByDate(String accessToken, DateTime settlementDate, Guid estateId, + Guid merchantId, CancellationToken cancellationToken); Task ProcessSettlement(String accessToken, DateTime settlementDate, Guid estateId, + Guid merchantId, CancellationToken cancellationToken); Task ResendEmailReceipt(String accessToken, @@ -51,13 +53,6 @@ Task GetVoucherByTransactionId(String accessToken, Guid transactionId, CancellationToken cancellationToken); - /// - /// Redeems the voucher. - /// - /// The access token. - /// The redeem voucher request. - /// The cancellation token. - /// Task RedeemVoucher(String accessToken, RedeemVoucherRequest redeemVoucherRequest, CancellationToken cancellationToken); diff --git a/TransactionProcessor.Client/TransactionProcessorClient.cs b/TransactionProcessor.Client/TransactionProcessorClient.cs index 6fa5b362..5e141500 100644 --- a/TransactionProcessor.Client/TransactionProcessorClient.cs +++ b/TransactionProcessor.Client/TransactionProcessorClient.cs @@ -94,11 +94,12 @@ public async Task PerformTransaction(String accessToken, public async Task GetSettlementByDate(String accessToken, DateTime settlementDate, Guid estateId, + Guid merchantId, CancellationToken cancellationToken) { SettlementResponse response = null; - String requestUri = $"{this.BaseAddress}/api/settlements/{settlementDate.Date:yyyy-MM-dd}/estates/{estateId}/pending"; + String requestUri = $"{this.BaseAddress}/api/settlements/{settlementDate.Date:yyyy-MM-dd}/estates/{estateId}/merchants/{merchantId}/pending"; try { @@ -128,9 +129,10 @@ public async Task GetSettlementByDate(String accessToken, public async Task ProcessSettlement(String accessToken, DateTime settlementDate, Guid estateId, + Guid merchantId, CancellationToken cancellationToken) { - String requestUri = $"{this.BaseAddress}/api/settlements/{settlementDate.Date:yyyy-MM-dd}/estates/{estateId}"; + String requestUri = $"{this.BaseAddress}/api/settlements/{settlementDate.Date:yyyy-MM-dd}/estates/{estateId}/merchants/{merchantId}"; try { diff --git a/TransactionProcessor.IntegrationTests/Features/Settlement.feature b/TransactionProcessor.IntegrationTests/Features/Settlement.feature index da161fec..8e92660a 100644 --- a/TransactionProcessor.IntegrationTests/Features/Settlement.feature +++ b/TransactionProcessor.IntegrationTests/Features/Settlement.feature @@ -97,13 +97,13 @@ Scenario: Get Pending Settlement | Test Estate 1 | Test Merchant 3 | 8 | 0000 | SUCCESS | When I get the pending settlements the following information should be returned - | SettlementDate | EstateName | NumberOfFees | - | 2022-01-13 | Test Estate 1 | 1 | - | 2022-02-06 | Test Estate 1 | 1 | + | SettlementDate | EstateName | MerchantName | NumberOfFees | + | 2022-01-13 | Test Estate 1 | Test Merchant 2 | 1 | + | 2022-02-06 | Test Estate 1 | Test Merchant 3 | 1 | When I get the completed settlements the following information should be returned - | SettlementDate | EstateName | NumberOfFees | - | 2022-01-06 | Test Estate 1 | 2 | + | SettlementDate | EstateName | MerchantName | NumberOfFees | + | 2022-01-06 | Test Estate 1 | Test Merchant 1 | 2 | @PRTest Scenario: Process Settlement @@ -146,9 +146,9 @@ Scenario: Process Settlement | Test Estate 1 | Test Merchant 2 | 6 | 0000 | SUCCESS | When I get the pending settlements the following information should be returned - | SettlementDate | EstateName | NumberOfFees | - | 2022-01-13 | Test Estate 1 | 1 | + | SettlementDate | EstateName | MerchantName | NumberOfFees | + | 2022-01-13 | Test Estate 1 | Test Merchant 2 | 1 | - When I process the settlement for '2022-01-13' on Estate 'Test Estate 1' then 1 fees are marked as settled and the settlement is completed + When I process the settlement for '2022-01-13' on Estate 'Test Estate 1' for Merchant 'Test Merchant 2' then 1 fees are marked as settled and the settlement is completed diff --git a/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs b/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs index dcd77db9..ab450838 100644 --- a/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs +++ b/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs @@ -607,14 +607,17 @@ public void GetPendingSettlement() TechTalk.SpecFlow.Table table105 = new TechTalk.SpecFlow.Table(new string[] { "SettlementDate", "EstateName", + "MerchantName", "NumberOfFees"}); table105.AddRow(new string[] { "2022-01-13", "Test Estate 1", + "Test Merchant 2", "1"}); table105.AddRow(new string[] { "2022-02-06", "Test Estate 1", + "Test Merchant 3", "1"}); #line 99 testRunner.When("I get the pending settlements the following information should be returned", ((string)(null)), table105, "When "); @@ -622,10 +625,12 @@ public void GetPendingSettlement() TechTalk.SpecFlow.Table table106 = new TechTalk.SpecFlow.Table(new string[] { "SettlementDate", "EstateName", + "MerchantName", "NumberOfFees"}); table106.AddRow(new string[] { "2022-01-06", "Test Estate 1", + "Test Merchant 1", "2"}); #line 104 testRunner.When("I get the completed settlements the following information should be returned", ((string)(null)), table106, "When "); @@ -900,17 +905,20 @@ public void ProcessSettlement() TechTalk.SpecFlow.Table table113 = new TechTalk.SpecFlow.Table(new string[] { "SettlementDate", "EstateName", + "MerchantName", "NumberOfFees"}); table113.AddRow(new string[] { "2022-01-13", "Test Estate 1", + "Test Merchant 2", "1"}); #line 148 testRunner.When("I get the pending settlements the following information should be returned", ((string)(null)), table113, "When "); #line hidden #line 152 - testRunner.When("I process the settlement for \'2022-01-13\' on Estate \'Test Estate 1\' then 1 fees a" + - "re marked as settled and the settlement is completed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); + testRunner.When("I process the settlement for \'2022-01-13\' on Estate \'Test Estate 1\' for Merchant " + + "\'Test Merchant 2\' then 1 fees are marked as settled and the settlement is comple" + + "ted", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line hidden } this.ScenarioCleanup(); diff --git a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs index b2c3516b..4fe162e9 100644 --- a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs @@ -1053,17 +1053,19 @@ public async Task WhenIGetTheCompletedSettlementsTheFollowingInformationShouldBe { // Get the merchant name EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); + Guid merchantId = estateDetails.GetMerchantId(SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName")); String settlementDateString = SpecflowTableHelper.GetStringRowValue(tableRow, "SettlementDate"); Int32 numberOfFees = SpecflowTableHelper.GetIntValue(tableRow, "NumberOfFees"); DateTime settlementDate = SpecflowTableHelper.GetDateForDateString(settlementDateString, DateTime.UtcNow.Date); - Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate, estateDetails.EstateId); + Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate, merchantId, estateDetails.EstateId); await Retry.For(async () => { TransactionProcessor.DataTransferObjects.SettlementResponse settlements = await this.TestingContext.DockerHelper.TransactionProcessorClient.GetSettlementByDate(this.TestingContext.AccessToken, settlementDate, estateDetails.EstateId, + merchantId, CancellationToken.None); settlements.NumberOfFeesSettled.ShouldBe(numberOfFees, $"Settlement date {settlementDate}"); @@ -1078,17 +1080,19 @@ public async Task WhenIGetThePendingSettlementsTheFollowingInformationShouldBeRe { // Get the merchant name EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); + Guid merchantId = estateDetails.GetMerchantId(SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName")); String settlementDateString = SpecflowTableHelper.GetStringRowValue(tableRow, "SettlementDate"); Int32 numberOfFees = SpecflowTableHelper.GetIntValue(tableRow, "NumberOfFees"); DateTime settlementDate = SpecflowTableHelper.GetDateForDateString(settlementDateString, DateTime.UtcNow.Date); - Guid aggregateid = Helpers.CalculateSettlementAggregateId(settlementDate, estateDetails.EstateId); + Guid aggregateid = Helpers.CalculateSettlementAggregateId(settlementDate,merchantId, estateDetails.EstateId); await Retry.For(async () => { TransactionProcessor.DataTransferObjects.SettlementResponse settlements = await this.TestingContext.DockerHelper.TransactionProcessorClient.GetSettlementByDate(this.TestingContext.AccessToken, settlementDate, estateDetails.EstateId, + merchantId, CancellationToken.None); settlements.NumberOfFeesPendingSettlement.ShouldBe(numberOfFees, $"Settlment date {settlementDate}"); @@ -1096,15 +1100,17 @@ await this.TestingContext.DockerHelper.TransactionProcessorClient.GetSettlementB } } - [When(@"I process the settlement for '([^']*)' on Estate '([^']*)' then (.*) fees are marked as settled and the settlement is completed")] - public async Task WhenIProcessTheSettlementForOnEstateThenFeesAreMarkedAsSettledAndTheSettlementIsCompleted(String dateString, String estateName, Int32 numberOfFeesSettled) + [When(@"I process the settlement for '([^']*)' on Estate '([^']*)' for Merchant '([^']*)' then (.*) fees are marked as settled and the settlement is completed")] + public async Task WhenIProcessTheSettlementForOnEstateThenFeesAreMarkedAsSettledAndTheSettlementIsCompleted(String dateString, String estateName, String merchantName, Int32 numberOfFeesSettled) { DateTime settlementDate = SpecflowTableHelper.GetDateForDateString(dateString, DateTime.UtcNow.Date); EstateDetails estateDetails = this.TestingContext.GetEstateDetails(estateName); + Guid merchantId = estateDetails.GetMerchantId(merchantName); await this.TestingContext.DockerHelper.TransactionProcessorClient.ProcessSettlement(this.TestingContext.AccessToken, settlementDate, estateDetails.EstateId, + merchantId, CancellationToken.None); await Retry.For(async () => @@ -1113,6 +1119,7 @@ await Retry.For(async () => await this.TestingContext.DockerHelper.TransactionProcessorClient.GetSettlementByDate(this.TestingContext.AccessToken, settlementDate, estateDetails.EstateId, + merchantId, CancellationToken.None); settlement.NumberOfFeesPendingSettlement.ShouldBe(0); diff --git a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj index cd1975ba..165adf25 100644 --- a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj +++ b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/TransactionProcessor.Testing/TestData.cs b/TransactionProcessor.Testing/TestData.cs index e2637676..e80937e2 100644 --- a/TransactionProcessor.Testing/TestData.cs +++ b/TransactionProcessor.Testing/TestData.cs @@ -504,6 +504,7 @@ public static Dictionary AdditionalTransactionMetaDataForPataPaw public static ProcessSettlementRequest ProcessSettlementRequest => ProcessSettlementRequest.Create(TestData.SettlementDate, + TestData.MerchantId, TestData.EstateId); public static ProcessLogonTransactionResponse ProcessLogonTransactionResponseModel => @@ -1179,7 +1180,13 @@ public static SettlementAggregate GetSettlementAggregateWithNotAllFeesSettled(In public static RedeemVoucherRequest RedeemVoucherRequest = RedeemVoucherRequest.Create(TestData.EstateId, TestData.VoucherCode, TestData.RedeemedDateTime); private static Decimal RemainingBalance = 1.00m; - + + public static Int32 MerchantReportingId = 1; + + public static Int32 ContractReportingId = 1; + + public static Int32 EstateReportingId = 1; + public static RedeemVoucherResponse RedeemVoucherResponse => new RedeemVoucherResponse { diff --git a/TransactionProcessor/Controllers/SettlementController.cs b/TransactionProcessor/Controllers/SettlementController.cs index 4d3fd248..68adf9ed 100644 --- a/TransactionProcessor/Controllers/SettlementController.cs +++ b/TransactionProcessor/Controllers/SettlementController.cs @@ -13,6 +13,7 @@ namespace TransactionProcessor.Controllers using Factories; using MediatR; using Microsoft.AspNetCore.Authorization; + using Models; using SettlementAggregates; using Shared.DomainDrivenDesign.EventSourcing; using Shared.EventStore.Aggregate; @@ -52,14 +53,15 @@ public SettlementController(IAggregateRepository GetPendingSettlement([FromRoute] DateTime settlementDate, [FromRoute] Guid estateId, + [FromRoute] Guid merchantId, CancellationToken cancellationToken) { // TODO: Convert to using a manager/model/factory // Convert the date passed in to a guid - Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate, estateId); + Guid aggregateId = Helpers.CalculateSettlementAggregateId(settlementDate, merchantId, estateId); Logger.LogInformation($"Settlement Aggregate Id {aggregateId}"); @@ -79,14 +81,15 @@ public async Task GetPendingSettlement([FromRoute] DateTime settl } [HttpPost] - [Route("{settlementDate}/estates/{estateId}")] + [Route("{settlementDate}/estates/{estateId}/merchants/{merchantId}")] public async Task ProcessSettlement([FromRoute] DateTime settlementDate, [FromRoute] Guid estateId, + [FromRoute] Guid merchantId, CancellationToken cancellationToken) { - ProcessSettlementRequest command = ProcessSettlementRequest.Create(settlementDate, estateId); + ProcessSettlementRequest command = ProcessSettlementRequest.Create(settlementDate, merchantId, estateId); - var processSettlementResponse = await this.Mediator.Send(command, cancellationToken); + ProcessSettlementResponse processSettlementResponse = await this.Mediator.Send(command, cancellationToken); return this.Ok(); } From 7ccab7c1c5be585857e8e0448f5c03f7acee8817 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Sat, 15 Jul 2023 06:29:08 +0100 Subject: [PATCH 2/5] Fix issues from last branch --- .../VoucherDomainEventHandlerTests.cs | 2 ++ .../TransactionDomainEventHandler.cs | 2 +- .../SettlementResponse.cs | 2 ++ .../SettlementCreatedForDateEvent.cs | 31 +++---------------- .../DomainEventTests.cs | 3 +- .../SettlementAggregateTests.cs | 26 ++++++++-------- .../SettlementAggregate.cs | 7 +++-- TransactionProcessor.Testing/TestData.cs | 8 ++--- .../Controllers/SettlementController.cs | 1 + TransactionProcessor/Startup.cs | 2 +- 10 files changed, 35 insertions(+), 49 deletions(-) diff --git a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs index 5878a3e0..537934e5 100644 --- a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs @@ -80,6 +80,7 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithEmailAddress_ context.Contracts.Add(new Contract { ContractId = TestData.ContractId, + ContractReportingId = TestData.ContractReportingId, EstateReportingId = TestData.EstateReportingId, Description = TestData.OperatorIdentifier }); @@ -129,6 +130,7 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithRecipientMobi context.Contracts.Add(new Contract { ContractId = TestData.ContractId, + ContractReportingId = TestData.ContractReportingId, EstateReportingId = TestData.EstateReportingId, Description = TestData.OperatorIdentifier }); diff --git a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs index 42d10963..c801d8c5 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs @@ -220,7 +220,7 @@ private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent do SettlementAggregate aggregate = await this.SettlementAggregateRepository.GetLatestVersion(aggregateId, cancellationToken); if (aggregate.IsCreated == false) { - aggregate.Create(transactionAggregate.EstateId, settlementDate); + aggregate.Create(transactionAggregate.EstateId, transactionAggregate.MerchantId, settlementDate); } //Guid eventId = IdGenerationService.GenerateEventId(new { diff --git a/TransactionProcessor.DataTransferObjects/SettlementResponse.cs b/TransactionProcessor.DataTransferObjects/SettlementResponse.cs index ecb8e54b..3fea3846 100644 --- a/TransactionProcessor.DataTransferObjects/SettlementResponse.cs +++ b/TransactionProcessor.DataTransferObjects/SettlementResponse.cs @@ -9,6 +9,8 @@ public class SettlementResponse { public Guid EstateId { get; set; } + public Guid MerchantId { get; set; } + public DateTime SettlementDate { get; set; } public Int32 NumberOfFeesPendingSettlement { get; set; } diff --git a/TransactionProcessor.Settlement.DomainEvents/SettlementCreatedForDateEvent.cs b/TransactionProcessor.Settlement.DomainEvents/SettlementCreatedForDateEvent.cs index 47cbe05d..446eebe6 100644 --- a/TransactionProcessor.Settlement.DomainEvents/SettlementCreatedForDateEvent.cs +++ b/TransactionProcessor.Settlement.DomainEvents/SettlementCreatedForDateEvent.cs @@ -3,31 +3,8 @@ using System; using Shared.DomainDrivenDesign.EventSourcing; - public record SettlementCreatedForDateEvent : DomainEvent - { - #region Properties - - public DateTime SettlementDate { get; init; } - - /// - /// Gets the estate identifier. - /// - /// - /// The estate identifier. - /// - public Guid EstateId { get; init; } - - public Guid SettlementId { get; init; } - - #endregion - - public SettlementCreatedForDateEvent(Guid aggregateId, - Guid estateId, - DateTime settlementDate) : base(aggregateId, Guid.NewGuid()) - { - this.EstateId = estateId; - this.SettlementDate = settlementDate; - this.SettlementId = aggregateId; - } - } + public record SettlementCreatedForDateEvent(Guid SettlementId, + Guid EstateId, + Guid MerchantId, + DateTime SettlementDate) : DomainEvent(SettlementId, Guid.NewGuid()); } \ No newline at end of file diff --git a/TransactionProcessor.SettlementAggregates.Tests/DomainEventTests.cs b/TransactionProcessor.SettlementAggregates.Tests/DomainEventTests.cs index 28f6412e..895d042d 100644 --- a/TransactionProcessor.SettlementAggregates.Tests/DomainEventTests.cs +++ b/TransactionProcessor.SettlementAggregates.Tests/DomainEventTests.cs @@ -18,13 +18,14 @@ public class DomainEventTests public void SettlementCreatedForDateEvent_CanBeCreated_IsCreated() { SettlementCreatedForDateEvent settlementCreatedForDateEvent = - new SettlementCreatedForDateEvent(TestData.SettlementAggregateId, TestData.EstateId, TestData.SettlementDate); + new SettlementCreatedForDateEvent(TestData.SettlementAggregateId, TestData.EstateId,TestData.MerchantId, TestData.SettlementDate); settlementCreatedForDateEvent.ShouldNotBeNull(); settlementCreatedForDateEvent.AggregateId.ShouldBe(TestData.SettlementAggregateId); settlementCreatedForDateEvent.EventId.ShouldNotBe(Guid.Empty); settlementCreatedForDateEvent.SettlementId.ShouldBe(TestData.SettlementAggregateId); settlementCreatedForDateEvent.EstateId.ShouldBe(TestData.EstateId); + settlementCreatedForDateEvent.MerchantId.ShouldBe(TestData.MerchantId); settlementCreatedForDateEvent.SettlementDate.ShouldBe(TestData.SettlementDate); } diff --git a/TransactionProcessor.SettlementAggregates.Tests/SettlementAggregateTests.cs b/TransactionProcessor.SettlementAggregates.Tests/SettlementAggregateTests.cs index 6648747b..09f86f61 100644 --- a/TransactionProcessor.SettlementAggregates.Tests/SettlementAggregateTests.cs +++ b/TransactionProcessor.SettlementAggregates.Tests/SettlementAggregateTests.cs @@ -20,7 +20,7 @@ public void SettlementAggregate_CanBeCreated_IsCreated() public void PendingSettlementAggregate_Create_AggregateIsCreated() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId,TestData.MerchantId, TestData.SettlementDate); aggregate.EstateId.ShouldBe(TestData.EstateId); aggregate.SettlementDate.ShouldBe(TestData.SettlementDate.Date); aggregate.IsCreated.ShouldBeTrue(); @@ -31,11 +31,11 @@ public void PendingSettlementAggregate_Create_AggregateIsCreated() public void SettlementAggregate_Create_AlreadyCreated_ErrorThrown() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); Should.Throw(() => { - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); }); } @@ -43,7 +43,7 @@ public void SettlementAggregate_Create_AlreadyCreated_ErrorThrown() public void SettlementAggregate_AddFee_FeeIsAdded() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); aggregate.AggregateId.ShouldBe(TestData.SettlementAggregateId); @@ -54,7 +54,7 @@ public void SettlementAggregate_AddFee_FeeIsAdded() public void SettlementAggregate_AddFee_TwoFeesAdded_FeesAreAdded() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee2); @@ -66,7 +66,7 @@ public void SettlementAggregate_AddFee_TwoFeesAdded_FeesAreAdded() public void SettlementAggregate_AddFee_TwoFeesAdded_SameFeeIdDifferentTransaction_FeesAreAdded() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId2, TestData.CalculatedFeeMerchantFee()); @@ -91,7 +91,7 @@ public void SettlementAggregate_AddFee_AggregateNotCreated_ErrorThrown() public void SettlementAggregate_AddFee_DuplicateFee_NoErrorThrown() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); Should.NotThrow(() => @@ -105,7 +105,7 @@ public void SettlementAggregate_AddFee_DuplicateFee_NoErrorThrown() public void SettlementAggregate_AddFee_InvalidFeeType_ErrorThrown() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); Should.Throw(() => { aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeServiceProviderFee); @@ -116,7 +116,7 @@ public void SettlementAggregate_AddFee_InvalidFeeType_ErrorThrown() public void SettlementAggregate_MarkFeeAsSettled_FeeIsSettledAndSettlementCompleted() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(1); @@ -132,7 +132,7 @@ public void SettlementAggregate_MarkFeeAsSettled_FeeIsSettledAndSettlementComple public void SettlementAggregate_MarkFeeAsSettled_FeeIsSettled_SettlementNotCompleted() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee2); @@ -149,7 +149,7 @@ public void SettlementAggregate_MarkFeeAsSettled_FeeIsSettled_SettlementNotCompl public void SettlementAggregate_MarkFeeAsSettled_PendingFeeNotFound_NoErrorThrown() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.MarkFeeAsSettled(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee().FeeId); @@ -161,7 +161,7 @@ public void SettlementAggregate_MarkFeeAsSettled_PendingFeeNotFound_NoErrorThrow public void SettlementAggregate_MarkFeeAsSettled_FeeAlreadySettled_NoErrorThrown() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(1); @@ -178,7 +178,7 @@ public void SettlementAggregate_MarkFeeAsSettled_FeeAlreadySettled_NoErrorThrown public void SettlementAggregate_ImmediatelyMarkFeeAsSettled_FeeIsSettledAndSettlementNotCompleted() { SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee()); aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(1); diff --git a/TransactionProcessor.SettlementAggregates/SettlementAggregate.cs b/TransactionProcessor.SettlementAggregates/SettlementAggregate.cs index 7c6b2d73..33217e39 100644 --- a/TransactionProcessor.SettlementAggregates/SettlementAggregate.cs +++ b/TransactionProcessor.SettlementAggregates/SettlementAggregate.cs @@ -129,13 +129,13 @@ public static void AddFee(this SettlementAggregate aggregate, return aggregate.CalculatedFeesPendingSettlement; } - public static void Create(this SettlementAggregate aggregate, Guid estateId, + public static void Create(this SettlementAggregate aggregate, Guid estateId,Guid merchantId, DateTime settlementDate) { aggregate.CheckHasNotAlreadyBeenCreated(); SettlementCreatedForDateEvent pendingSettlementCreatedForDateEvent = - new SettlementCreatedForDateEvent(aggregate.AggregateId, estateId, settlementDate.Date); + new SettlementCreatedForDateEvent(aggregate.AggregateId, estateId,merchantId, settlementDate.Date); aggregate.ApplyAndAppend(pendingSettlementCreatedForDateEvent); } @@ -211,6 +211,7 @@ public static void PlayEvent(this SettlementAggregate aggregate, MerchantFeeAdde public static void PlayEvent(this SettlementAggregate aggregate, SettlementCreatedForDateEvent domainEvent) { aggregate.EstateId = domainEvent.EstateId; + aggregate.MerchantId = domainEvent.MerchantId; aggregate.SettlementDate = domainEvent.SettlementDate; aggregate.IsCreated = true; } @@ -265,6 +266,8 @@ private SettlementAggregate(Guid aggregateId) public Guid EstateId { get; internal set; } + public Guid MerchantId { get; internal set; } + public Boolean IsCreated { get; internal set; } public DateTime SettlementDate { get; internal set; } diff --git a/TransactionProcessor.Testing/TestData.cs b/TransactionProcessor.Testing/TestData.cs index e80937e2..85121ddc 100644 --- a/TransactionProcessor.Testing/TestData.cs +++ b/TransactionProcessor.Testing/TestData.cs @@ -1078,14 +1078,14 @@ public static SettlementAggregate GetEmptySettlementAggregate() public static SettlementAggregate GetCreatedSettlementAggregate() { var aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); return aggregate; } public static SettlementAggregate GetSettlementAggregateWithPendingMerchantFees(Int32 numberOfFees) { var aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); for (int i = 0; i < numberOfFees; i++) { @@ -1098,7 +1098,7 @@ public static SettlementAggregate GetSettlementAggregateWithPendingMerchantFees( public static SettlementAggregate GetSettlementAggregateWithAllFeesSettled(Int32 numberOfFees) { var aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); for (int i = 0; i < numberOfFees; i++) { @@ -1114,7 +1114,7 @@ public static SettlementAggregate GetSettlementAggregateWithAllFeesSettled(Int32 public static SettlementAggregate GetSettlementAggregateWithNotAllFeesSettled(Int32 numberOfFees) { var aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId); - aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate); for (int i = 0; i <= numberOfFees; i++) { diff --git a/TransactionProcessor/Controllers/SettlementController.cs b/TransactionProcessor/Controllers/SettlementController.cs index 68adf9ed..d89ce80c 100644 --- a/TransactionProcessor/Controllers/SettlementController.cs +++ b/TransactionProcessor/Controllers/SettlementController.cs @@ -70,6 +70,7 @@ public async Task GetPendingSettlement([FromRoute] DateTime settl var settlementResponse = new SettlementResponse { EstateId = settlementAggregate.EstateId, + MerchantId = settlementAggregate.MerchantId, NumberOfFeesPendingSettlement = settlementAggregate.GetNumberOfFeesPendingSettlement(), NumberOfFeesSettled = settlementAggregate.GetNumberOfFeesSettled(), SettlementDate = settlementAggregate.SettlementDate, diff --git a/TransactionProcessor/Startup.cs b/TransactionProcessor/Startup.cs index e5e4d039..43b5d2e0 100644 --- a/TransactionProcessor/Startup.cs +++ b/TransactionProcessor/Startup.cs @@ -191,7 +191,7 @@ public void ConfigureContainer(ServiceRegistry services) { public static void LoadTypes() { SettlementCreatedForDateEvent s = - new SettlementCreatedForDateEvent(Guid.Parse("62CA5BF0-D138-4A19-9970-A4F7D52DE292"), Guid.Parse("3E42516B-6C6F-4F86-BF08-3EF0ACDDDD55"), DateTime.Now); + new SettlementCreatedForDateEvent(Guid.Parse("62CA5BF0-D138-4A19-9970-A4F7D52DE292"), Guid.Parse("3E42516B-6C6F-4F86-BF08-3EF0ACDDDD55"),Guid.Parse("9948C956-2769-40A1-9903-2D31B4D3EEEF"), DateTime.Now); TransactionHasStartedEvent t = new TransactionHasStartedEvent(Guid.Parse("2AA2D43B-5E24-4327-8029-1135B20F35CE"), Guid.NewGuid(), From 6ce7a92ec3e275abbc76e7d479e13235888318c8 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Sat, 15 Jul 2023 19:52:41 +0100 Subject: [PATCH 3/5] :| --- ...ansactionProcessor.ProjectionEngine.Database.csproj | 10 +++++----- TransactionProcessor/TransactionProcessor.csproj | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TransactionProcessor.ProjectionEngine.Database/TransactionProcessor.ProjectionEngine.Database.csproj b/TransactionProcessor.ProjectionEngine.Database/TransactionProcessor.ProjectionEngine.Database.csproj index a2eafda1..335cf4f6 100644 --- a/TransactionProcessor.ProjectionEngine.Database/TransactionProcessor.ProjectionEngine.Database.csproj +++ b/TransactionProcessor.ProjectionEngine.Database/TransactionProcessor.ProjectionEngine.Database.csproj @@ -7,14 +7,14 @@ None - - + + - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/TransactionProcessor/TransactionProcessor.csproj b/TransactionProcessor/TransactionProcessor.csproj index d7e0ad18..366f248c 100644 --- a/TransactionProcessor/TransactionProcessor.csproj +++ b/TransactionProcessor/TransactionProcessor.csproj @@ -24,7 +24,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 6d811456dfeeebb3c5507479cfc9a3738727e856 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Sat, 15 Jul 2023 20:04:15 +0100 Subject: [PATCH 4/5] .. --- .../TransactionProcessor.ProjectionEngine.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TransactionProcessor.ProjectionEngine.Tests/TransactionProcessor.ProjectionEngine.Tests.csproj b/TransactionProcessor.ProjectionEngine.Tests/TransactionProcessor.ProjectionEngine.Tests.csproj index f0cc047e..e66c41ba 100644 --- a/TransactionProcessor.ProjectionEngine.Tests/TransactionProcessor.ProjectionEngine.Tests.csproj +++ b/TransactionProcessor.ProjectionEngine.Tests/TransactionProcessor.ProjectionEngine.Tests.csproj @@ -10,7 +10,7 @@ - + From 923ef63f5a4bd8177aa90adbae8a40ba6e49fa0c Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Mon, 17 Jul 2023 09:59:58 +0100 Subject: [PATCH 5/5] :| --- .../Common/TestingContext.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/TransactionProcessor.IntegrationTests/Common/TestingContext.cs b/TransactionProcessor.IntegrationTests/Common/TestingContext.cs index 56ee37f6..d88cae0e 100644 --- a/TransactionProcessor.IntegrationTests/Common/TestingContext.cs +++ b/TransactionProcessor.IntegrationTests/Common/TestingContext.cs @@ -190,11 +190,15 @@ public async Task GetVoucherByTransactionNumber(String estat { TypeNameHandling = TypeNameHandling.All }); - GetVoucherResponse voucher = await this.DockerHelper.TransactionProcessorClient.GetVoucherByTransactionId(this.AccessToken, - estate.EstateId, - transactionResponse.TransactionId, - CancellationToken.None); - + + GetVoucherResponse voucher = null; + await Retry.For(async () => { + voucher = await this.DockerHelper.TransactionProcessorClient.GetVoucherByTransactionId(this.AccessToken, + estate.EstateId, + transactionResponse.TransactionId, + CancellationToken.None); + + }); return voucher; } }