@Test public void testCaptureRejected() throws Exception { PaymentTransactionModel adyenTransaction = createAdyenTransaction(); List<PaymentTransactionEntryModel> transactionEntries = new ArrayList<>(); transactionEntries.add(createAuthorizedEntry()); transactionEntries.add(createCaptureReceivedEntry()); transactionEntries.add(createCaptureRejectedEntry()); adyenTransaction.setEntries(transactionEntries); List<PaymentTransactionModel> transactions = new ArrayList<>(); transactions.add(adyenTransaction); when(orderModelMock.getPaymentTransactions()).thenReturn(transactions); String result = adyenCheckCaptureAction.execute(orderProcessModelMock); assertEquals(AdyenCheckCaptureAction.Transition.NOK.toString(), result); verify(orderModelMock).setStatus(OrderStatus.PAYMENT_NOT_CAPTURED); verify(modelServiceMock).save(orderProcessModelMock.getOrder()); }
@Override public String execute(final OrderProcessModel process) { LOG.debug("Process: " + process.getCode() + " in step " + getClass().getSimpleName()); final OrderModel order = process.getOrder(); if (order.getPaymentInfo().getAdyenPaymentMethod() == null) { LOG.debug("Not Adyen Payment"); return Transition.OK.toString(); } order.setStatus(OrderStatus.PAYMENT_NOT_CAPTURED); modelService.save(order); BigDecimal remainingAmount = new BigDecimal(order.getTotalPrice()); for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) { boolean isRejected = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.REJECTED ) != null; boolean isErroneous = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ERROR ) != null; if (isErroneous || isRejected) { LOG.debug("Process: " + process.getCode() + " Order Not Captured"); return Transition.NOK.toString(); } PaymentTransactionEntryModel transactionEntry = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ACCEPTED, TransactionStatusDetails.SUCCESFULL); if (transactionEntry != null) { remainingAmount = remainingAmount.subtract(transactionEntry.getAmount()); LOG.debug("Remaining amount: " + remainingAmount); } } BigDecimal zero = BigDecimal.ZERO; zero = zero.setScale(3, BigDecimal.ROUND_FLOOR); remainingAmount = remainingAmount.setScale(3, BigDecimal.ROUND_FLOOR); if (remainingAmount.compareTo(zero) <= 0) { LOG.debug("Process: " + process.getCode() + " Order Captured"); order.setStatus(OrderStatus.PAYMENT_CAPTURED); modelService.save(order); return Transition.OK.toString(); } LOG.debug("Process: " + process.getCode() + " Order Waiting"); return Transition.WAIT.toString(); }
AdyenCheckCaptureAction extends AbstractWaitableAction<OrderProcessModel> { @Override public String execute(final OrderProcessModel process) { LOG.debug("Process: " + process.getCode() + " in step " + getClass().getSimpleName()); final OrderModel order = process.getOrder(); if (order.getPaymentInfo().getAdyenPaymentMethod() == null) { LOG.debug("Not Adyen Payment"); return Transition.OK.toString(); } order.setStatus(OrderStatus.PAYMENT_NOT_CAPTURED); modelService.save(order); BigDecimal remainingAmount = new BigDecimal(order.getTotalPrice()); for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) { boolean isRejected = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.REJECTED ) != null; boolean isErroneous = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ERROR ) != null; if (isErroneous || isRejected) { LOG.debug("Process: " + process.getCode() + " Order Not Captured"); return Transition.NOK.toString(); } PaymentTransactionEntryModel transactionEntry = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ACCEPTED, TransactionStatusDetails.SUCCESFULL); if (transactionEntry != null) { remainingAmount = remainingAmount.subtract(transactionEntry.getAmount()); LOG.debug("Remaining amount: " + remainingAmount); } } BigDecimal zero = BigDecimal.ZERO; zero = zero.setScale(3, BigDecimal.ROUND_FLOOR); remainingAmount = remainingAmount.setScale(3, BigDecimal.ROUND_FLOOR); if (remainingAmount.compareTo(zero) <= 0) { LOG.debug("Process: " + process.getCode() + " Order Captured"); order.setStatus(OrderStatus.PAYMENT_CAPTURED); modelService.save(order); return Transition.OK.toString(); } LOG.debug("Process: " + process.getCode() + " Order Waiting"); return Transition.WAIT.toString(); } }
AdyenCheckCaptureAction extends AbstractWaitableAction<OrderProcessModel> { @Override public String execute(final OrderProcessModel process) { LOG.debug("Process: " + process.getCode() + " in step " + getClass().getSimpleName()); final OrderModel order = process.getOrder(); if (order.getPaymentInfo().getAdyenPaymentMethod() == null) { LOG.debug("Not Adyen Payment"); return Transition.OK.toString(); } order.setStatus(OrderStatus.PAYMENT_NOT_CAPTURED); modelService.save(order); BigDecimal remainingAmount = new BigDecimal(order.getTotalPrice()); for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) { boolean isRejected = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.REJECTED ) != null; boolean isErroneous = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ERROR ) != null; if (isErroneous || isRejected) { LOG.debug("Process: " + process.getCode() + " Order Not Captured"); return Transition.NOK.toString(); } PaymentTransactionEntryModel transactionEntry = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ACCEPTED, TransactionStatusDetails.SUCCESFULL); if (transactionEntry != null) { remainingAmount = remainingAmount.subtract(transactionEntry.getAmount()); LOG.debug("Remaining amount: " + remainingAmount); } } BigDecimal zero = BigDecimal.ZERO; zero = zero.setScale(3, BigDecimal.ROUND_FLOOR); remainingAmount = remainingAmount.setScale(3, BigDecimal.ROUND_FLOOR); if (remainingAmount.compareTo(zero) <= 0) { LOG.debug("Process: " + process.getCode() + " Order Captured"); order.setStatus(OrderStatus.PAYMENT_CAPTURED); modelService.save(order); return Transition.OK.toString(); } LOG.debug("Process: " + process.getCode() + " Order Waiting"); return Transition.WAIT.toString(); }  }
AdyenCheckCaptureAction extends AbstractWaitableAction<OrderProcessModel> { @Override public String execute(final OrderProcessModel process) { LOG.debug("Process: " + process.getCode() + " in step " + getClass().getSimpleName()); final OrderModel order = process.getOrder(); if (order.getPaymentInfo().getAdyenPaymentMethod() == null) { LOG.debug("Not Adyen Payment"); return Transition.OK.toString(); } order.setStatus(OrderStatus.PAYMENT_NOT_CAPTURED); modelService.save(order); BigDecimal remainingAmount = new BigDecimal(order.getTotalPrice()); for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) { boolean isRejected = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.REJECTED ) != null; boolean isErroneous = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ERROR ) != null; if (isErroneous || isRejected) { LOG.debug("Process: " + process.getCode() + " Order Not Captured"); return Transition.NOK.toString(); } PaymentTransactionEntryModel transactionEntry = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ACCEPTED, TransactionStatusDetails.SUCCESFULL); if (transactionEntry != null) { remainingAmount = remainingAmount.subtract(transactionEntry.getAmount()); LOG.debug("Remaining amount: " + remainingAmount); } } BigDecimal zero = BigDecimal.ZERO; zero = zero.setScale(3, BigDecimal.ROUND_FLOOR); remainingAmount = remainingAmount.setScale(3, BigDecimal.ROUND_FLOOR); if (remainingAmount.compareTo(zero) <= 0) { LOG.debug("Process: " + process.getCode() + " Order Captured"); order.setStatus(OrderStatus.PAYMENT_CAPTURED); modelService.save(order); return Transition.OK.toString(); } LOG.debug("Process: " + process.getCode() + " Order Waiting"); return Transition.WAIT.toString(); }  @Override Set<String> getTransitions(); @Override String execute(final OrderProcessModel process); }
AdyenCheckCaptureAction extends AbstractWaitableAction<OrderProcessModel> { @Override public String execute(final OrderProcessModel process) { LOG.debug("Process: " + process.getCode() + " in step " + getClass().getSimpleName()); final OrderModel order = process.getOrder(); if (order.getPaymentInfo().getAdyenPaymentMethod() == null) { LOG.debug("Not Adyen Payment"); return Transition.OK.toString(); } order.setStatus(OrderStatus.PAYMENT_NOT_CAPTURED); modelService.save(order); BigDecimal remainingAmount = new BigDecimal(order.getTotalPrice()); for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) { boolean isRejected = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.REJECTED ) != null; boolean isErroneous = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ERROR ) != null; if (isErroneous || isRejected) { LOG.debug("Process: " + process.getCode() + " Order Not Captured"); return Transition.NOK.toString(); } PaymentTransactionEntryModel transactionEntry = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, PaymentTransactionType.CAPTURE, TransactionStatus.ACCEPTED, TransactionStatusDetails.SUCCESFULL); if (transactionEntry != null) { remainingAmount = remainingAmount.subtract(transactionEntry.getAmount()); LOG.debug("Remaining amount: " + remainingAmount); } } BigDecimal zero = BigDecimal.ZERO; zero = zero.setScale(3, BigDecimal.ROUND_FLOOR); remainingAmount = remainingAmount.setScale(3, BigDecimal.ROUND_FLOOR); if (remainingAmount.compareTo(zero) <= 0) { LOG.debug("Process: " + process.getCode() + " Order Captured"); order.setStatus(OrderStatus.PAYMENT_CAPTURED); modelService.save(order); return Transition.OK.toString(); } LOG.debug("Process: " + process.getCode() + " Order Waiting"); return Transition.WAIT.toString(); }  @Override Set<String> getTransitions(); @Override String execute(final OrderProcessModel process);  }