WorldpayApmOrderCancelDenialStrategy extends AbstractCancelDenialStrategy implements OrderCancelDenialStrategy { @Override public OrderCancelDenialReason getCancelDenialReason(final OrderCancelConfigModel orderCancelConfigModel, final OrderModel orderModel, final PrincipalModel principalModel, boolean partialCancel, boolean partialEntryCancel) { final List<PaymentTransactionModel> paymentTransactions = orderModel.getPaymentTransactions(); if (paymentTransactions != null) { for (final PaymentTransactionModel paymentTransaction : paymentTransactions) { final PaymentInfoModel paymentInfo = paymentTransaction.getInfo(); if (shouldReturnCancelReason(paymentInfo)) { LOG.warn(format("The order [{0}] cannot be cancelled as the payment was made through an APM or is still unknown", orderModel.getCode())); return getReason(); } } } return null; }  @Override OrderCancelDenialReason getCancelDenialReason(final OrderCancelConfigModel orderCancelConfigModel, final OrderModel orderModel,
                                                         final PrincipalModel principalModel, boolean partialCancel, boolean partialEntryCancel);  }
@Test public void shouldReturnNullWhenThereIsNoReasonToDenyCancellation() { when(orderModelMock.getPaymentTransactions()).thenReturn(ImmutableList.of(paymentTransactionModelMock)); when(paymentTransactionModelMock.getInfo()).thenReturn(paymentInfoModelMock); when(paymentInfoModelMock.getIsApm()).thenReturn(false); when(paymentInfoModelMock.getPaymentType()).thenReturn("VISA-SSL"); final OrderCancelDenialReason result = testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); assertThat(result).isNull(); }
@Test public void shouldReturnDenialReasonWhenPaymentInfoIsNull() { when(orderModelMock.getPaymentTransactions()).thenReturn(ImmutableList.of(paymentTransactionModelMock)); when(paymentTransactionModelMock.getInfo()).thenReturn(null); final DefaultOrderCancelDenialReason result = (DefaultOrderCancelDenialReason) testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); assertThat(result.getCode()).isEqualTo(5); assertThat(result.getDescription()).isEqualTo(CANCEL_DENIAL_REASON_DESCRIPTION); }
@Test public void shouldReturnDenialReasonWhenPaymentInfoIsAPM() { when(orderModelMock.getPaymentTransactions()).thenReturn(ImmutableList.of(paymentTransactionModelMock)); when(paymentTransactionModelMock.getInfo()).thenReturn(paymentInfoModelMock); when(paymentInfoModelMock.getIsApm()).thenReturn(true); final DefaultOrderCancelDenialReason result = (DefaultOrderCancelDenialReason) testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); assertThat(result.getCode()).isEqualTo(5); assertThat(result.getDescription()).isEqualTo(CANCEL_DENIAL_REASON_DESCRIPTION); }
@Test public void shouldReturnDenialReasonWhenPaymentInfoIsUnknown() { when(orderModelMock.getPaymentTransactions()).thenReturn(ImmutableList.of(paymentTransactionModelMock)); when(paymentTransactionModelMock.getInfo()).thenReturn(paymentInfoModelMock); when(paymentInfoModelMock.getIsApm()).thenReturn(false); when(paymentInfoModelMock.getPaymentType()).thenReturn(""); final DefaultOrderCancelDenialReason result = (DefaultOrderCancelDenialReason) testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); assertThat(result.getCode()).isEqualTo(5); assertThat(result.getDescription()).isEqualTo(CANCEL_DENIAL_REASON_DESCRIPTION); }