WorldpayOrderModificationListener extends AbstractEventListener<OrderModificationEvent> { @Override protected void onEvent(final OrderModificationEvent orderModificationEvent) { final OrderNotificationMessage orderNotificationMessage = orderModificationEvent.getOrderNotificationMessage(); final AuthorisedStatus journalType = orderNotificationMessage.getJournalReply().getJournalType(); if (journalType.equals(REFUSED)) { setDeclineCodeInCart(orderNotificationMessage); } final PaymentTransactionType transactionType = paymentTransactionTypeMap.get(journalType); if (transactionType != null) { saveOrderModification(orderNotificationMessage, transactionType); } else { LOG.warn(MessageFormat.format("Transaction type {0} not supported. Ignoring event.", journalType)); } }  @Required void setPaymentTransactionTypeMap(final Map<AuthorisedStatus, PaymentTransactionType> paymentTransactionTypeMap); @Required void setModelService(final ModelService modelService); @Required void setOrderModificationSerialiser(final OrderModificationSerialiser orderModificationSerialiser); @Required void setWorldpayCartService(final WorldpayCartService worldpayCartService);  }
@Test public void onEventRefusedShouldUpdateCartModelWhenDeclineCodeExists() { when(journalReplyMock.getJournalType()).thenReturn(REFUSED); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock).setWorldpayDeclineCodeOnCart(WORLDPAY_ORDER_CODE, RETURN_CODE); verify(modelServiceMock).save(worldpayOrderModificationModelMock); }
@Test public void onEventRefusedShouldNotUpdateCartModelWhenDeclineCodeIsZero() { when(journalReplyMock.getJournalType()).thenReturn(REFUSED); when(orderNotificationMessageMock.getPaymentReply().getReturnCode()).thenReturn("0"); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock, never()).setWorldpayDeclineCodeOnCart(anyString(), anyString()); verify(modelServiceMock).save(worldpayOrderModificationModelMock); verify(worldpayOrderModificationModelMock).setType(PaymentTransactionType.REFUSED); verify(worldpayOrderModificationModelMock).setWorldpayOrderCode(WORLDPAY_ORDER_CODE); verify(worldpayOrderModificationModelMock).setOrderNotificationMessage(SERIALIZED); }
@Test public void onEventAUTHORISEDShouldSaveModificationModel() { when(journalReplyMock.getJournalType()).thenReturn(AUTHORISED); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock, never()).setWorldpayDeclineCodeOnCart(anyString(), anyString()); verify(modelServiceMock).save(worldpayOrderModificationModelMock); verify(worldpayOrderModificationModelMock).setType(AUTHORIZATION); verify(worldpayOrderModificationModelMock).setWorldpayOrderCode(WORLDPAY_ORDER_CODE); verify(worldpayOrderModificationModelMock).setOrderNotificationMessage(SERIALIZED); }
@Test public void onEventCAPTUREDShouldSaveModificationModel() { when(journalReplyMock.getJournalType()).thenReturn(CAPTURED); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock, never()).setWorldpayDeclineCodeOnCart(anyString(), anyString()); verify(modelServiceMock).save(worldpayOrderModificationModelMock); verify(worldpayOrderModificationModelMock).setType(CAPTURE); verify(worldpayOrderModificationModelMock).setWorldpayOrderCode(WORLDPAY_ORDER_CODE); verify(worldpayOrderModificationModelMock).setOrderNotificationMessage(SERIALIZED); }
@Test public void onEventREFUSEDShouldSaveModificationModelWhenTransactionBelongsToACart() { when(journalReplyMock.getJournalType()).thenReturn(REFUSED); when(orderNotificationMessageMock.getPaymentReply().getReturnCode()).thenReturn("0"); when(paymentTransactionModelMock.getOrder()).thenReturn(cartModelMock); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock, never()).setWorldpayDeclineCodeOnCart(anyString(), anyString()); verify(modelServiceMock).save(worldpayOrderModificationModelMock); verify(worldpayOrderModificationModelMock).setType(any(PaymentTransactionType.class)); verify(worldpayOrderModificationModelMock).setWorldpayOrderCode(anyString()); verify(worldpayOrderModificationModelMock).setOrderNotificationMessage(anyString()); }
@Test public void onEventREFUSEDShouldSaveModificationModelWhenTransactionBelongsToAnOrder() { when(journalReplyMock.getJournalType()).thenReturn(REFUSED); when(orderNotificationMessageMock.getPaymentReply().getReturnCode()).thenReturn("0"); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock, never()).setWorldpayDeclineCodeOnCart(anyString(), anyString()); verify(modelServiceMock).save(worldpayOrderModificationModelMock); verify(worldpayOrderModificationModelMock).setType(PaymentTransactionType.REFUSED); verify(worldpayOrderModificationModelMock).setWorldpayOrderCode(WORLDPAY_ORDER_CODE); verify(worldpayOrderModificationModelMock).setOrderNotificationMessage(SERIALIZED); }
@Test public void onEventCANCELLEDShouldSaveModificationModelWhenTransactionBelongsToACart() { when(journalReplyMock.getJournalType()).thenReturn(CANCELLED); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock, never()).setWorldpayDeclineCodeOnCart(anyString(), anyString()); verify(modelServiceMock).save(worldpayOrderModificationModelMock); verify(worldpayOrderModificationModelMock).setType(CANCEL); verify(worldpayOrderModificationModelMock).setWorldpayOrderCode(WORLDPAY_ORDER_CODE); verify(worldpayOrderModificationModelMock).setOrderNotificationMessage(SERIALIZED); }
@Test public void onEventCANCELLEDShouldSaveModificationModelWhenTransactionBelongsToAnOrder() { when(journalReplyMock.getJournalType()).thenReturn(CANCELLED); testObj.onEvent(orderModificationEventMock); verify(worldpayCartServiceMock, never()).setWorldpayDeclineCodeOnCart(anyString(), anyString()); verify(modelServiceMock).save(worldpayOrderModificationModelMock); verify(worldpayOrderModificationModelMock).setType(CANCEL); verify(worldpayOrderModificationModelMock).setWorldpayOrderCode(WORLDPAY_ORDER_CODE); verify(worldpayOrderModificationModelMock).setOrderNotificationMessage(SERIALIZED); }
@Test public void onEventShouldNotSaveModificationModelDueToIncorrectMapping() { when(journalReplyMock.getJournalType()).thenReturn(EXPIRED); testObj.onEvent(orderModificationEventMock); verify(modelServiceMock, never()).save(any()); }