AbstractWorldpayDirectCheckoutStepController extends WorldpayChoosePaymentMethodCheckoutStepController { public String handleDirectResponse(final Model model, final DirectResponseData directResponseData, final HttpServletResponse response) throws CMSItemNotFoundException, WorldpayConfigurationException { if (worldpayDirectResponseFacade.isAuthorised(directResponseData)) { return redirectToOrderConfirmationPage(directResponseData.getOrderData()); } if (worldpayDirectResponseFacade.is3DSecureLegacyFlow(directResponseData)) { final Map<String, String> attributes = worldpayDirectResponseFacade.retrieveAttributesForLegacy3dSecure(directResponseData); model.addAllAttributes(attributes); response.addHeader(THREED_SECURE_FLOW, Boolean.TRUE.toString()); response.addHeader(THREED_SECURE_FLEX_FLOW, Boolean.FALSE.toString()); return worldpayAddonEndpointService.getAutoSubmit3DSecure(); } if (worldpayDirectResponseFacade.is3DSecureFlexFlow(directResponseData)) { final Map<String, String> attributes = worldpayDirectResponseFacade.retrieveAttributesForFlex3dSecure(directResponseData); model.addAllAttributes(attributes); response.addHeader(THREED_SECURE_FLOW, Boolean.TRUE.toString()); response.addHeader(THREED_SECURE_FLEX_FLOW, Boolean.TRUE.toString()); return worldpayAddonEndpointService.getAutoSubmit3DSecureFlex(); } if (worldpayDirectResponseFacade.isCancelled(directResponseData)) { GlobalMessages.addErrorMessage(model, CHECKOUT_MULTI_WORLD_PAY_DECLINED_MESSAGE_DEFAULT); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return getErrorView(model); } GlobalMessages.addErrorMessage(model, getLocalisedDeclineMessage(directResponseData.getReturnCode())); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return getErrorView(model); }  String handleDirectResponse(final Model model, final DirectResponseData directResponseData, final HttpServletResponse response); void setDDCIframeData(final Model model);  }
@Test public void shouldRedirectTo3DSecureIfAuthenticationRequiredForLegacyFlow() throws CMSItemNotFoundException, WorldpayConfigurationException { when(worldpayDirectResponseFacadeMock.is3DSecureLegacyFlow(directResponseDataMock)).thenReturn(true); final String result = testObj.handleDirectResponse(modelMock, directResponseDataMock, responseMock); assertEquals(AUTOSUBMIT_3DSECURE, result); }
@Test public void shouldRedirectTo3DSecureIfAuthenticationRequiredFor3DSecureFlexFlow() throws CMSItemNotFoundException, WorldpayConfigurationException { when(worldpayDirectResponseFacadeMock.is3DSecureFlexFlow(directResponseDataMock)).thenReturn(true); final String result = testObj.handleDirectResponse(modelMock, directResponseDataMock, responseMock); assertEquals(AUTOSUBMIT_3DSECURE_FLEX, result); }
@Test public void shouldRetrieveAllAttributesForModelIfPaymentRequires3dSecureLegacyFlowAuthentication() throws CMSItemNotFoundException, WorldpayConfigurationException { when(worldpayDirectResponseFacadeMock.is3DSecureLegacyFlow(directResponseDataMock)).thenReturn(true); testObj.handleDirectResponse(modelMock, directResponseDataMock, responseMock); verify(worldpayDirectResponseFacadeMock).retrieveAttributesForLegacy3dSecure(directResponseDataMock); }
@Test public void shouldRetrieveAllAttributesForModelIfPaymentRequires3dSecureFlexFlowAuthentication() throws CMSItemNotFoundException, WorldpayConfigurationException { when(worldpayDirectResponseFacadeMock.is3DSecureFlexFlow(directResponseDataMock)).thenReturn(true); testObj.handleDirectResponse(modelMock, directResponseDataMock, responseMock); verify(worldpayDirectResponseFacadeMock).retrieveAttributesForFlex3dSecure(directResponseDataMock); }
@Test public void shouldReturnErrorPageWhenCancelled() throws CMSItemNotFoundException, WorldpayConfigurationException { when(worldpayDirectResponseFacadeMock.isCancelled(directResponseDataMock)).thenReturn(true); final String result = testObj.handleDirectResponse(modelMock, directResponseDataMock, responseMock); assertEquals(ERROR_VIEW, result); }
@Test public void shouldRedirectToErrorIfResponseIsNotAuthorisedOrAuthRequired() throws CMSItemNotFoundException, WorldpayConfigurationException { final String result = testObj.handleDirectResponse(modelMock, directResponseDataMock, responseMock); assertEquals(ERROR_VIEW, result); }