@Test public void testNoAuthorizations() throws Exception { List<PaymentTransactionModel> transactions = new ArrayList<>(); when(orderModelMock.getPaymentTransactions()).thenReturn(transactions); assertEquals( AdyenCheckCaptureAction.Transition.WAIT.toString(), adyenCheckCaptureAction.execute(orderProcessModelMock) ); PaymentTransactionModel adyenTransaction = createAdyenTransaction(); adyenTransaction.getEntries().add(createAuthorizedEntry()); adyenTransaction.getEntries().add(createCaptureReceivedEntry()); transactions.add(adyenTransaction); assertEquals( AdyenCheckCaptureAction.Transition.WAIT.toString(), adyenCheckCaptureAction.execute(orderProcessModelMock) ); adyenTransaction.getEntries().add(createCaptureSuccessEntry()); assertEquals( AdyenCheckCaptureAction.Transition.OK.toString(), adyenCheckCaptureAction.execute(orderProcessModelMock) ); }
@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);  }