From c8a01c28852c3ea15277540bb772d502e2713b08 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Wed, 7 Jun 2023 13:23:10 +0100 Subject: [PATCH] Dont calculate fees for Verify Account transactions --- .../TransactionDomainEventHandler.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs index d7b8945c..0da8fc91 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs @@ -142,21 +142,25 @@ private async Task GetToken(CancellationToken cancellationToken) return this.TokenResponse; } + private Boolean RequireFeeCalculation(TransactionAggregate transactionAggregate){ + return transactionAggregate switch{ + _ when transactionAggregate.IsAuthorised == false => false, + _ when transactionAggregate.IsCompleted == false => false, + _ when transactionAggregate.TransactionType == TransactionType.Logon => false, + _ when transactionAggregate.ContractId == Guid.Empty => false, + _ when transactionAggregate.ProductId == Guid.Empty => false, + _ when transactionAggregate.TransactionAmount == null => false, + _ => true + }; + } + private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent domainEvent, CancellationToken cancellationToken) { TransactionAggregate transactionAggregate = await this.TransactionAggregateRepository.GetLatestVersion(domainEvent.TransactionId, cancellationToken); - if (transactionAggregate.IsAuthorised == false) { - // Ignore not successful transactions - return; - } - - if (transactionAggregate.IsCompleted == false || transactionAggregate.TransactionType == TransactionType.Logon || - (transactionAggregate.ContractId == Guid.Empty || transactionAggregate.ProductId == Guid.Empty)) { - // These transactions cannot have fee values calculated so skip + if (RequireFeeCalculation(transactionAggregate) == false) return; - } this.TokenResponse = await this.GetToken(cancellationToken);