@@ -142,21 +142,25 @@ private async Task<TokenResponse> GetToken(CancellationToken cancellationToken)
142142 return this . TokenResponse ;
143143 }
144144
145+ private Boolean RequireFeeCalculation ( TransactionAggregate transactionAggregate ) {
146+ return transactionAggregate switch {
147+ _ when transactionAggregate . IsAuthorised == false => false ,
148+ _ when transactionAggregate . IsCompleted == false => false ,
149+ _ when transactionAggregate . TransactionType == TransactionType . Logon => false ,
150+ _ when transactionAggregate . ContractId == Guid . Empty => false ,
151+ _ when transactionAggregate . ProductId == Guid . Empty => false ,
152+ _ when transactionAggregate . TransactionAmount == null => false ,
153+ _ => true
154+ } ;
155+ }
156+
145157 private async Task HandleSpecificDomainEvent ( TransactionHasBeenCompletedEvent domainEvent ,
146158 CancellationToken cancellationToken ) {
147159 TransactionAggregate transactionAggregate =
148160 await this . TransactionAggregateRepository . GetLatestVersion ( domainEvent . TransactionId , cancellationToken ) ;
149161
150- if ( transactionAggregate . IsAuthorised == false ) {
151- // Ignore not successful transactions
152- return ;
153- }
154-
155- if ( transactionAggregate . IsCompleted == false || transactionAggregate . TransactionType == TransactionType . Logon ||
156- ( transactionAggregate . ContractId == Guid . Empty || transactionAggregate . ProductId == Guid . Empty ) ) {
157- // These transactions cannot have fee values calculated so skip
162+ if ( RequireFeeCalculation ( transactionAggregate ) == false )
158163 return ;
159- }
160164
161165 this . TokenResponse = await this . GetToken ( cancellationToken ) ;
162166
0 commit comments