WorldpayCheckAuthorizeOrderPaymentAction extends WorldpayAbstractOrderAction<OrderProcessModel> { @Override public String execute(final OrderProcessModel process) { final OrderModel order = process.getOrder(); String returnTransition = null; if (order != null) { if (order.getPaymentInfo() instanceof InvoicePaymentInfoModel) { returnTransition = OK; } else { if (!worldpayPaymentTransactionService.areAllPaymentTransactionsAcceptedForType(order, AUTHORIZATION)) { setOrderStatus(order, PAYMENT_NOT_AUTHORIZED); return NOK; } if (!worldpayPaymentTransactionService.isAuthorisedAmountCorrect(order)) { setOrderStatus(order, CHECKED_INVALID); createOrderHistoryEntry("Order total did not match authorised amount", order); return NOK; } if (isAuthorizationPending(order)) { setOrderStatus(order, PAYMENT_PENDING); returnTransition = WAIT; } else { setOrderStatus(order, PAYMENT_AUTHORIZED); returnTransition = OK; } } } return returnTransition; }  @Override Set<String> getTransitions(); @Override String execute(final OrderProcessModel process); @Required void setPaymentTransactionService(final WorldpayPaymentTransactionService worldpayPaymentTransactionService);  }
@Test public void executeShouldReturnOKIfOrderPaymentInfoIsInvoice() { when(orderModelMock.getPaymentInfo()).thenReturn(invoicePaymentInfoMock); final String result = testObj.execute(processMock); assertEquals(OK, result); verify(orderModelMock, never()).setStatus(PAYMENT_PENDING); }
@Test public void executeShouldReturnNOKIfNotAllTransactionEntriesAuthorised() { when(orderModelMock.getPaymentInfo()).thenReturn(paymentInfoModelMock); when(worldpayPaymentTransactionServiceMock.areAllPaymentTransactionsAcceptedForType(orderModelMock, AUTHORIZATION)).thenReturn(false); final String result = testObj.execute(processMock); assertEquals(NOK, result); verify(orderModelMock).setStatus(PAYMENT_NOT_AUTHORIZED); }
@Test public void executeShouldReturnWAITIfAllTransactionEntriesAcceptedButPending() { when(orderModelMock.getPaymentInfo()).thenReturn(paymentInfoModelMock); when(worldpayPaymentTransactionServiceMock.areAllPaymentTransactionsAcceptedForType(orderModelMock, AUTHORIZATION)).thenReturn(true); when(worldpayPaymentTransactionServiceMock.isAuthorisedAmountCorrect(orderModelMock)).thenReturn(true); when(worldpayPaymentTransactionServiceMock.isPaymentTransactionPending(paymentTransactionMock, AUTHORIZATION)).thenReturn(true); final String result = testObj.execute(processMock); assertEquals(WAIT, result); verify(orderModelMock).setStatus(PAYMENT_PENDING); }
@Test public void executeShouldReturnOKIfAllTransactionEntriesAcceptedAndNotPending() { when(orderModelMock.getPaymentInfo()).thenReturn(paymentInfoModelMock); when(worldpayPaymentTransactionServiceMock.areAllPaymentTransactionsAcceptedForType(orderModelMock, AUTHORIZATION)).thenReturn(true); when(worldpayPaymentTransactionServiceMock.isAuthorisedAmountCorrect(orderModelMock)).thenReturn(true); when(worldpayPaymentTransactionServiceMock.isPaymentTransactionPending(paymentTransactionMock, AUTHORIZATION)).thenReturn(false); final String result = testObj.execute(processMock); assertEquals(OK, result); verify(modelServiceMock).save(orderModelMock); verify(orderModelMock).setStatus(PAYMENT_AUTHORIZED); }
@Test public void executeShouldReturnNOKWhenAuthorisedAmountNotCorrect() { when(worldpayPaymentTransactionServiceMock.areAllPaymentTransactionsAcceptedForType(orderModelMock, AUTHORIZATION)).thenReturn(true); when(worldpayPaymentTransactionServiceMock.isAuthorisedAmountCorrect(orderModelMock)).thenReturn(false); when(testObj.getTimeService()).thenReturn(timeServiceMock); when(modelServiceMock.create(OrderHistoryEntryModel.class)).thenReturn(orderHistoryEntryMock); when(timeServiceMock.getCurrentTime()).thenReturn(dateMock); final String result = testObj.execute(processMock); assertEquals(NOK, result); verify(orderModelMock).setStatus(CHECKED_INVALID); }
@Test public void executeShouldReturnOKWhenAuthorisedAmountIsCorrect() { when(worldpayPaymentTransactionServiceMock.areAllPaymentTransactionsAcceptedForType(orderModelMock, AUTHORIZATION)).thenReturn(true); when(worldpayPaymentTransactionServiceMock.isAuthorisedAmountCorrect(orderModelMock)).thenReturn(true); when(worldpayPaymentTransactionServiceMock.isPaymentTransactionPending(paymentTransactionMock, AUTHORIZATION)).thenReturn(false); final String result = testObj.execute(processMock); assertEquals(OK, result); verify(orderModelMock).setStatus(PAYMENT_AUTHORIZED); }