@Test public void validateUpdateTxnSuccess() { Transaction txnStatus = Transaction.builder().txnId("PT_001") .txnAmount("100") .billId("ORDER0012") .txnStatus(Transaction.TxnStatusEnum.PENDING) .productInfo("Property Tax Payment") .gateway("PAYTM") .build(); when(gatewayService.getTxnId(any(Map.class))).thenReturn(Optional.of("PB_PG_001")); when(transactionRepository.fetchTransactions(any(TransactionCriteria.class))).thenReturn(Collections.singletonList (txnStatus)); validator.validateUpdateTxn(Collections.singletonMap("transactionId", "PB_PG_001")); }
public Transaction validateUpdateTxn(Map<String, String> requestParams) { Optional<String> optional = gatewayService.getTxnId(requestParams); if (!optional.isPresent()) throw new CustomException("MISSING_UPDATE_TXN_ID", "Cannot process request, missing transaction id"); TransactionCriteria criteria = TransactionCriteria.builder() .txnId(optional.get()) .build(); List<Transaction> statuses = transactionRepository.fetchTransactions(criteria); if (statuses.isEmpty()) { throw new CustomException("TXN_UPDATE_NOT_FOUND", "Transaction not found"); } return statuses.get(0); }
TransactionValidator { public Transaction validateUpdateTxn(Map<String, String> requestParams) { Optional<String> optional = gatewayService.getTxnId(requestParams); if (!optional.isPresent()) throw new CustomException("MISSING_UPDATE_TXN_ID", "Cannot process request, missing transaction id"); TransactionCriteria criteria = TransactionCriteria.builder() .txnId(optional.get()) .build(); List<Transaction> statuses = transactionRepository.fetchTransactions(criteria); if (statuses.isEmpty()) { throw new CustomException("TXN_UPDATE_NOT_FOUND", "Transaction not found"); } return statuses.get(0); } }
TransactionValidator { public Transaction validateUpdateTxn(Map<String, String> requestParams) { Optional<String> optional = gatewayService.getTxnId(requestParams); if (!optional.isPresent()) throw new CustomException("MISSING_UPDATE_TXN_ID", "Cannot process request, missing transaction id"); TransactionCriteria criteria = TransactionCriteria.builder() .txnId(optional.get()) .build(); List<Transaction> statuses = transactionRepository.fetchTransactions(criteria); if (statuses.isEmpty()) { throw new CustomException("TXN_UPDATE_NOT_FOUND", "Transaction not found"); } return statuses.get(0); } @Autowired  TransactionValidator(GatewayService gatewayService, TransactionRepository transactionRepository, CollectionService collectionService); }
TransactionValidator { public Transaction validateUpdateTxn(Map<String, String> requestParams) { Optional<String> optional = gatewayService.getTxnId(requestParams); if (!optional.isPresent()) throw new CustomException("MISSING_UPDATE_TXN_ID", "Cannot process request, missing transaction id"); TransactionCriteria criteria = TransactionCriteria.builder() .txnId(optional.get()) .build(); List<Transaction> statuses = transactionRepository.fetchTransactions(criteria); if (statuses.isEmpty()) { throw new CustomException("TXN_UPDATE_NOT_FOUND", "Transaction not found"); } return statuses.get(0); } @Autowired  TransactionValidator(GatewayService gatewayService, TransactionRepository transactionRepository, CollectionService collectionService); void validateCreateTxn(TransactionRequest transactionRequest); Transaction validateUpdateTxn(Map<String, String> requestParams); boolean skipGateway(Transaction transaction); boolean shouldGenerateReceipt(Transaction prevStatus, Transaction newStatus); }
TransactionValidator { public Transaction validateUpdateTxn(Map<String, String> requestParams) { Optional<String> optional = gatewayService.getTxnId(requestParams); if (!optional.isPresent()) throw new CustomException("MISSING_UPDATE_TXN_ID", "Cannot process request, missing transaction id"); TransactionCriteria criteria = TransactionCriteria.builder() .txnId(optional.get()) .build(); List<Transaction> statuses = transactionRepository.fetchTransactions(criteria); if (statuses.isEmpty()) { throw new CustomException("TXN_UPDATE_NOT_FOUND", "Transaction not found"); } return statuses.get(0); } @Autowired  TransactionValidator(GatewayService gatewayService, TransactionRepository transactionRepository, CollectionService collectionService); void validateCreateTxn(TransactionRequest transactionRequest); Transaction validateUpdateTxn(Map<String, String> requestParams); boolean skipGateway(Transaction transaction); boolean shouldGenerateReceipt(Transaction prevStatus, Transaction newStatus);  }