Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ 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,
ContractReportingId = TestData.ContractReportingId,
EstateReportingId = TestData.EstateReportingId,
Description = TestData.OperatorIdentifier
});
await context.SaveChangesAsync(CancellationToken.None);
Expand Down Expand Up @@ -123,13 +124,14 @@ 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,
ContractReportingId = TestData.ContractReportingId,
EstateReportingId = TestData.EstateReportingId,
Description = TestData.OperatorIdentifier
});
await context.SaveChangesAsync(CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class DummySettlementDomainService : ISettlementDomainService
{
public async Task<ProcessSettlementResponse> ProcessSettlement(DateTime pendingSettlementDate,
Guid estateId,
Guid merchantId,
CancellationToken cancellationToken) {
return new ProcessSettlementResponse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Lamar" Version="12.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Shouldly" Version="4.2.1" />
Expand Down
3 changes: 2 additions & 1 deletion TransactionProcessor.BusinessLogic/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ 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);

if (aggregate.IsCreated == false) {
aggregate.Create(transactionAggregate.EstateId, settlementDate);
aggregate.Create(transactionAggregate.EstateId, transactionAggregate.MerchantId, settlementDate);
}

//Guid eventId = IdGenerationService.GenerateEventId(new {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private async Task<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public async Task<Voucher> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SettlementRequestHandler(ISettlementDomainService settlementDomainService
public async Task<ProcessSettlementResponse> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,37 @@
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<ProcessSettlementResponse>
{
public class ProcessSettlementRequest : IRequest<ProcessSettlementResponse>{
#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;
}

#endregion

#region Properties

/// <summary>
/// Gets the estate identifier.
/// </summary>
/// <value>
/// The estate identifier.
/// </value>
public Guid EstateId { get; }


public DateTime SettlementDate { get; }


public Guid EstateId{ get; }

public Guid MerchantId{ get; }

public DateTime SettlementDate{ get; }

#endregion

#region Methods

/// <summary>
/// Creates the specified estate identifier.
/// </summary>
/// <param name="transactionId">The transaction identifier.</param>
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="transactionType">Type of the transaction.</param>
/// <param name="transactionDateTime">The transaction date time.</param>
/// <param name="transactionNumber">The transaction number.</param>
/// <returns></returns>
public static ProcessSettlementRequest Create(DateTime settlementDate,
Guid estateId)
{
return new ProcessSettlementRequest(settlementDate, estateId);
Guid merchantId,
Guid estateId){
return new ProcessSettlementRequest(settlementDate, merchantId, estateId);
}

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface ISettlementDomainService
{
Task<ProcessSettlementResponse> ProcessSettlement(DateTime pendingSettlementDate,
Guid estateId,
Guid merchantId,
CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public class SettlementDomainService : ISettlementDomainService

public async Task<ProcessSettlementResponse> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<ItemGroup>
<PackageReference Include="EstateManagement.Client" Version="2023.6.1" />
<PackageReference Include="EstateManagement.Database" Version="2023.6.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.5" />
<PackageReference Include="EstateManagement.Database" Version="2023.7.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.7" />
<PackageReference Include="MessagingService.Client" Version="2023.6.1" />
<PackageReference Include="SecurityService.Client" Version="2023.6.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2023.6.1" />
Expand Down
9 changes: 2 additions & 7 deletions TransactionProcessor.Client/ITransactionProcessorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ Task<SerialisedMessage> PerformTransaction(String accessToken,
Task<SettlementResponse> 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,
Expand Down Expand Up @@ -51,13 +53,6 @@ Task<GetVoucherResponse> GetVoucherByTransactionId(String accessToken,
Guid transactionId,
CancellationToken cancellationToken);

/// <summary>
/// Redeems the voucher.
/// </summary>
/// <param name="accessToken">The access token.</param>
/// <param name="redeemVoucherRequest">The redeem voucher request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<RedeemVoucherResponse> RedeemVoucher(String accessToken,
RedeemVoucherRequest redeemVoucherRequest,
CancellationToken cancellationToken);
Expand Down
Loading