@@ -13,13 +13,50 @@ namespace TransactionProcessor.Aggregates
1313 using Shared . EventStore . Aggregate ;
1414 using Shared . General ;
1515
16+ public enum TransactionResponseCode
17+ {
18+ Success = 0 ,
19+ SuccessNeedToAddDevice = 1 ,
20+
21+ InvalidDeviceIdentifier = 1000 ,
22+ InvalidEstateId = 1001 ,
23+ InvalidMerchantId = 1002 ,
24+ NoValidDevices = 1003 ,
25+ NoEstateOperators = 1004 ,
26+ OperatorNotValidForEstate = 1005 ,
27+ NoMerchantOperators = 1006 ,
28+ OperatorNotValidForMerchant = 1007 ,
29+ TransactionDeclinedByOperator = 1008 ,
30+ MerchantDoesNotHaveEnoughCredit = 1009 ,
31+ OperatorCommsError = 1010 ,
32+ InvalidSaleTransactionAmount = 1011 ,
33+ InvalidContractIdValue = 1012 ,
34+ InvalidProductIdValue = 1013 ,
35+ MerchantHasNoContractsConfigured = 1014 ,
36+ ContractNotValidForMerchant = 1015 ,
37+ ProductNotValidForMerchant = 1016 ,
38+ OperatorNotEnabledForEstate = 1017 ,
39+ OperatorNotEnabledForMerchant = 1018 ,
40+
41+ // A Catch All generic Error where reason has not been identified
42+ UnknownFailure = 9999
43+ }
44+
45+ public static class TransactionResponseCodeExtensions
46+ {
47+ public static string ToCodeString ( this TransactionResponseCode code )
48+ {
49+ return ( ( int ) code ) . ToString ( "D4" ) ;
50+ }
51+ }
52+
1653 public static class TransactionAggregateExtensions {
1754
1855 public static Result DeclineTransaction ( this TransactionAggregate aggregate ,
1956 Guid operatorId ,
2057 String operatorResponseCode ,
2158 String operatorResponseMessage ,
22- String responseCode ,
59+ TransactionResponseCode responseCode ,
2360 String responseMessage )
2461 {
2562 Result result = aggregate . CheckTransactionHasBeenStarted ( ) ;
@@ -32,23 +69,25 @@ public static Result DeclineTransaction(this TransactionAggregate aggregate,
3269 if ( result . IsFailed )
3370 return result ;
3471
72+
73+
3574 TransactionDomainEvents . TransactionDeclinedByOperatorEvent transactionDeclinedByOperatorEvent =
3675 new ( aggregate . AggregateId ,
3776 aggregate . EstateId ,
3877 aggregate . MerchantId ,
3978 operatorId ,
4079 operatorResponseCode ,
4180 operatorResponseMessage ,
42- responseCode ,
81+ responseCode . ToCodeString ( ) ,
4382 responseMessage ,
4483 aggregate . TransactionDateTime ) ;
4584 aggregate . ApplyAndAppend ( transactionDeclinedByOperatorEvent ) ;
4685
4786 return Result . Success ( ) ;
4887 }
4988
50- public static Result DeclineTransactionLocally ( this TransactionAggregate aggregate ,
51- String responseCode ,
89+ public static Result DeclineTransactionLocally ( this TransactionAggregate aggregate ,
90+ TransactionResponseCode responseCode ,
5291 String responseMessage )
5392 {
5493 Result result = aggregate . CheckTransactionHasBeenStarted ( ) ;
@@ -61,7 +100,7 @@ public static Result DeclineTransactionLocally(this TransactionAggregate aggrega
61100 if ( result . IsFailed )
62101 return result ;
63102 TransactionDomainEvents . TransactionHasBeenLocallyDeclinedEvent transactionHasBeenLocallyDeclinedEvent =
64- new ( aggregate . AggregateId , aggregate . EstateId , aggregate . MerchantId , responseCode , responseMessage ,
103+ new ( aggregate . AggregateId , aggregate . EstateId , aggregate . MerchantId , responseCode . ToCodeString ( ) , responseMessage ,
65104 aggregate . TransactionDateTime ) ;
66105
67106 aggregate . ApplyAndAppend ( transactionHasBeenLocallyDeclinedEvent ) ;
@@ -276,7 +315,7 @@ public static Result AuthoriseTransaction(this TransactionAggregate aggregate,
276315 String operatorResponseCode ,
277316 String operatorResponseMessage ,
278317 String operatorTransactionId ,
279- String responseCode ,
318+ TransactionResponseCode responseCode ,
280319 String responseMessage )
281320 {
282321 Result result = aggregate . CheckTransactionHasBeenStarted ( ) ;
@@ -294,7 +333,7 @@ public static Result AuthoriseTransaction(this TransactionAggregate aggregate,
294333 operatorResponseCode ,
295334 operatorResponseMessage ,
296335 operatorTransactionId ,
297- responseCode ,
336+ responseCode . ToCodeString ( ) ,
298337 responseMessage ,
299338 aggregate . TransactionDateTime ) ;
300339 aggregate . ApplyAndAppend ( transactionAuthorisedByOperatorEvent ) ;
@@ -304,7 +343,7 @@ public static Result AuthoriseTransaction(this TransactionAggregate aggregate,
304343
305344 public static Result AuthoriseTransactionLocally ( this TransactionAggregate aggregate ,
306345 String authorisationCode ,
307- String responseCode ,
346+ TransactionResponseCode responseCode ,
308347 String responseMessage )
309348 {
310349 var result = aggregate . CheckTransactionHasBeenStarted ( ) ;
@@ -317,7 +356,7 @@ public static Result AuthoriseTransactionLocally(this TransactionAggregate aggre
317356 if ( result . IsFailed )
318357 return result ;
319358 TransactionDomainEvents . TransactionHasBeenLocallyAuthorisedEvent transactionHasBeenLocallyAuthorisedEvent =
320- new ( aggregate . AggregateId , aggregate . EstateId , aggregate . MerchantId , authorisationCode , responseCode , responseMessage ,
359+ new ( aggregate . AggregateId , aggregate . EstateId , aggregate . MerchantId , authorisationCode , responseCode . ToCodeString ( ) , responseMessage ,
321360 aggregate . TransactionDateTime ) ;
322361
323362 aggregate . ApplyAndAppend ( transactionHasBeenLocallyAuthorisedEvent ) ;
0 commit comments