protected PaymentTransactionEntryModel createPaymentTransactionEntry( final PaymentTransactionType type, final TransactionStatus status) { final PaymentTransactionEntryModel paymentTransactionEntry = new PaymentTransactionEntryModel(); paymentTransactionEntry.setType(type); paymentTransactionEntry.setTransactionStatus(status.toString()); return paymentTransactionEntry; }
@Test public void testExecuteActionNOK() throws RetryLaterException, Exception { final OrderProcessModel businessProcessModel = new OrderProcessModel(); final OrderModel order = new OrderModel(); final PaymentTransactionModel paymentTransaction = new PaymentTransactionModel(); final PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel(); entry.setType(PaymentTransactionType.AUTHORIZATION); entry.setTransactionStatus(TransactionStatus.REJECTED.name()); paymentTransaction.setEntries(Arrays.asList(entry)); businessProcessModel.setOrder(order); order.setPaymentTransactions(Arrays.asList(paymentTransaction)); Assertions.assertThat(checkAuthorizeOrderPayment.executeAction(businessProcessModel)) .isEqualTo(Transition.NOK); }
@Override public Transition executeAction(final OrderProcessModel process) { final OrderModel order = process.getOrder(); if (order != null) { if (order.getPaymentInfo() instanceof InvoicePaymentInfoModel) { return Transition.OK; } else { for (final PaymentTransactionModel transaction : order.getPaymentTransactions()) { for (final PaymentTransactionEntryModel entry : transaction.getEntries()) { if (entry.getType().equals(PaymentTransactionType.AUTHORIZATION) && TransactionStatus.ACCEPTED.name().equals(entry.getTransactionStatus())) { order.setStatus(OrderStatus.PAYMENT_AUTHORIZED); modelService.save(order); return Transition.OK; } } } } } return Transition.NOK; }