DefaultRefusedOrderNotificationProcessorStrategy implements OrderNotificationProcessorStrategy { @Override public void processNotificationMessage(final PaymentTransactionModel paymentTransactionModel, final OrderNotificationMessage orderNotificationMessage) throws WorldpayConfigurationException { final AbstractOrderModel orderModel = paymentTransactionModel.getOrder(); if (isOrderRefusable(orderModel)) { worldpayPaymentInfoService.setPaymentInfoModel(paymentTransactionModel, orderModel, orderNotificationMessage); transactionTemplate.execute(transactionStatus -> { worldpayPaymentTransactionService.updateEntriesStatus(paymentTransactionModel.getEntries(), REJECTED.name()); worldpayPaymentTransactionService.updateEntriesAmount(paymentTransactionModel.getEntries(), orderNotificationMessage.getPaymentReply().getAmount()); modelService.save(paymentTransactionModel); return null; }); } else { LOG.warn(MessageFormat.format("The order [{0}] is a cart or not in PAYMENT_PENDING status.", orderModel.getCode())); } }  @Override void processNotificationMessage(final PaymentTransactionModel paymentTransactionModel, final OrderNotificationMessage orderNotificationMessage); @Required void setWorldpayPaymentInfoService(WorldpayPaymentInfoService worldpayPaymentInfoService); @Required void setTransactionTemplate(TransactionOperations transactionTemplate); @Required void setWorldpayPaymentTransactionService(WorldpayPaymentTransactionService worldpayPaymentTransactionService); @Required void setModelService(ModelService modelService);  }
@Test public void shouldProcessRefusedNotification() throws OrderCancelException, WorldpayConfigurationException { when(orderModelMock.getStatus()).thenReturn(OrderStatus.PAYMENT_PENDING); testObj.processNotificationMessage(paymentTransactionModelMock, orderNotificationMessageMock); verify(paymentTransactionModelMock).getOrder(); verify(modelServiceMock).save(paymentTransactionModelMock); verify(worldpayPaymentTransactionServiceMock).updateEntriesStatus(Collections.singletonList(paymentTransactionEntryModelMock), REJECTED.name()); verify(worldpayPaymentTransactionServiceMock).updateEntriesAmount(Collections.singletonList(paymentTransactionEntryModelMock), amountMock); verify(worldpayPaymentInfoServiceMock).setPaymentInfoModel(paymentTransactionModelMock, orderModelMock, orderNotificationMessageMock); }
@Test public void shouldProcessRefusedNotificationAndShouldNOTTriggerAnyEventIfOrderStatusIsNOTPaymentPending() throws OrderCancelException, WorldpayConfigurationException { when(orderModelMock.getStatus()).thenReturn(OrderStatus.CREATED); testObj.processNotificationMessage(paymentTransactionModelMock, orderNotificationMessageMock); verify(paymentTransactionModelMock).getOrder(); verify(worldpayPaymentInfoServiceMock, never()).setPaymentInfoModel(any(PaymentTransactionModel.class), any(AbstractOrderModel.class), any(OrderNotificationMessage.class)); verify(modelServiceMock, never()).save(paymentTransactionModelMock); verify(worldpayPaymentTransactionServiceMock, never()).updateEntriesStatus(anyListOf(PaymentTransactionEntryModel.class), anyString()); }