@@ -540,23 +540,18 @@ private static Result ValidateStartTransactionArguments(DateTime transactionDate
540540 String transactionReference ,
541541 TransactionStartContext transactionStartContext )
542542 {
543- if ( transactionStartContext == null )
544- return Result . Invalid ( "Transaction Start Context must not be null" ) ;
543+ var result = ValidateContext ( transactionStartContext ) ;
544+ if ( result . IsFailed ) return result ;
545545
546- if ( transactionDateTime == DateTime . MinValue )
547- return Result . Invalid ( $ "Transaction Date Time must not be [{ DateTime . MinValue } ]") ;
548- if ( String . IsNullOrEmpty ( transactionNumber ) )
549- return Result . Invalid ( "Transaction Number must not be null or empty" ) ;
550- if ( String . IsNullOrEmpty ( transactionReference ) )
551- return Result . Invalid ( "Transaction Reference must not be null or empty" ) ;
552-
553- if ( Int32 . TryParse ( transactionNumber , out Int32 _ ) == false ) {
554- return Result . Invalid ( "Transaction Number must be numeric" ) ;
555- }
546+ result = ValidateCoreFields ( transactionDateTime , transactionNumber , transactionReference , transactionType ) ;
547+ if ( result . IsFailed ) return result ;
556548
557- if ( Enum . IsDefined ( typeof ( TransactionType ) , transactionType ) == false )
558- return Result . Invalid ( "Transaction Type not valid" ) ;
549+ return Result . Success ( ) ;
550+ }
559551
552+ private static Result ValidateContext ( TransactionStartContext transactionStartContext ) {
553+ if ( transactionStartContext == null )
554+ return Result . Invalid ( "Transaction Start Context must not be null" ) ;
560555 if ( transactionStartContext . EstateId == Guid . Empty )
561556 return Result . Invalid ( $ "Estate Id must not be [{ Guid . Empty } ]") ;
562557 if ( transactionStartContext . MerchantId == Guid . Empty )
@@ -567,6 +562,27 @@ private static Result ValidateStartTransactionArguments(DateTime transactionDate
567562 return Result . Success ( ) ;
568563 }
569564
565+ private static Result ValidateCoreFields ( DateTime dateTime , string number , string reference , TransactionType transactionType )
566+ {
567+ if ( dateTime == DateTime . MinValue )
568+ return Result . Invalid ( $ "Transaction Date Time must not be [{ DateTime . MinValue } ]") ;
569+
570+ if ( string . IsNullOrEmpty ( number ) )
571+ return Result . Invalid ( "Transaction Number must not be null or empty" ) ;
572+
573+ if ( ! int . TryParse ( number , out _ ) )
574+ return Result . Invalid ( "Transaction Number must be numeric" ) ;
575+
576+ if ( string . IsNullOrEmpty ( reference ) )
577+ return Result . Invalid ( "Transaction Reference must not be null or empty" ) ;
578+
579+ if ( Enum . IsDefined ( typeof ( TransactionType ) , transactionType ) == false )
580+ return Result . Invalid ( "Transaction Type not valid" ) ;
581+
582+ return Result . Success ( ) ;
583+ }
584+
585+
570586 private static Result CheckCanStartTransaction ( TransactionAggregate aggregate )
571587 {
572588 Result result = aggregate . CheckTransactionNotAlreadyStarted ( ) ;
0 commit comments