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 @@ -229,6 +229,10 @@ private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent do
await this.TransactionAggregateManager.AddFee(transactionAggregate.EstateId, transactionAggregate.AggregateId, calculatedFee, cancellationToken);
}
}
else if (merchant.SettlementSchedule == SettlementSchedule.NotSet)
{
throw new NotSupportedException($"Merchant {merchant.MerchantId} does not have a settlement schedule configured");
}
else
{
foreach (CalculatedFee calculatedFee in merchantFees)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public void PendingSettlementAggregate_AddFee_TwoFeesAdded_FeesAreAdded()
aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(2);
}

[Fact]
public void PendingSettlementAggregate_AddFee_TwoFeesAdded_SameFeeIdDifferentTransaction_FeesAreAdded()
{
PendingSettlementAggregate aggregate = PendingSettlementAggregate.Create(TestData.PendingSettlementAggregateId);
aggregate.Create(TestData.EstateId, TestData.SettlementDate);
aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee);
aggregate.AddFee(TestData.MerchantId, TestData.TransactionId2, TestData.CalculatedFeeMerchantFee);

aggregate.AggregateId.ShouldBe(TestData.PendingSettlementAggregateId);
aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(2);
}

[Fact]
public void PendingSettlementAggregate_AddFee_AggregateNotCreated_ErrorThrown()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void AddFee(Guid merchantId,
}

this.CheckHasBeenCreated();
this.CheckFeeHasNotAlreadyBeenAdded(calculatedFee);
this.CheckFeeHasNotAlreadyBeenAdded(transactionId, calculatedFee);

DomainEventRecord.DomainEvent @event = null;
if (calculatedFee.FeeType == FeeType.Merchant)
Expand Down Expand Up @@ -137,11 +137,11 @@ protected override Object GetMetadata()
return null;
}

private void CheckFeeHasNotAlreadyBeenAdded(CalculatedFee calculatedFee)
private void CheckFeeHasNotAlreadyBeenAdded(Guid transactionId, CalculatedFee calculatedFee)
{
if (this.CalculatedFeesPendingSettlement.Any(c => c.calculatedFee.FeeId == calculatedFee.FeeId))
if (this.CalculatedFeesPendingSettlement.Any(c => c.calculatedFee.FeeId == calculatedFee.FeeId && c.transactionId == transactionId))
{
throw new InvalidOperationException($"Fee with Id [{calculatedFee.FeeId}] has already been added to this days pending settlement");
throw new InvalidOperationException($"Fee with Id [{calculatedFee.FeeId}] for Transaction Id [{transactionId}] has already been added to this days pending settlement");
}
}

Expand Down
2 changes: 2 additions & 0 deletions TransactionProcessor.Testing/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class TestData

public static Guid TransactionId = Guid.Parse("AE89B2F6-307B-46F4-A8E7-CEF27097D766");

public static Guid TransactionId2 = Guid.Parse("760E702C-682E-41B1-A582-3D4ECA0F38C3");

public static Guid PendingSettlementAggregateId = Guid.Parse("BAEBA232-CD7F-46F5-AE2E-3204FE69A441");

public static String TransactionNumber = "0001";
Expand Down