WorldpayThreeDSecureEndpointController extends WorldpayChoosePaymentMethodCheckoutStepController { @RequestMapping (method = POST) @RequireHardLogIn public String doHandleThreeDSecureResponse(final HttpServletRequest request, final ThreeDSecureForm threeDSecureForm, final RedirectAttributes redirectAttributes) { final String worldpayOrderCode = threeDSecureForm.getMD(); TransactionStatus transactionStatus = ERROR; try { final DirectResponseData responseData = worldpayDirectOrderFacade.authorise3DSecure(threeDSecureForm.getPaRes(), getWorldpayAdditionalInfoFacade().createWorldpayAdditionalInfoData(request)); transactionStatus = responseData.getTransactionStatus(); if (AUTHORISED.equals(transactionStatus)) { final PlaceOrderData placeOrderData = new PlaceOrderData(); placeOrderData.setTermsCheck(true); OrderData orderData = getB2BCheckoutFacade().placeOrder(placeOrderData); return redirectToOrderConfirmationPage(orderData); } else { LOG.error(format("Failed to create payment authorisation for successful 3DSecure response. Received {0} as transactionStatus", transactionStatus)); worldpayCartService.setWorldpayDeclineCodeOnCart(worldpayOrderCode, responseData.getReturnCode()); } } catch (WorldpayException | InvalidCartException e) { LOG.error(format("There was an error processing the 3d secure payment for order with worldpayOrderCode [{0}]", worldpayOrderCode), e); } redirectAttributes.addFlashAttribute(PAYMENT_STATUS_PARAMETER_NAME, transactionStatus.toString()); return REDIRECT_URL_CHOOSE_PAYMENT_METHOD + "?" + PAYMENT_STATUS_PARAMETER_NAME + "=" + transactionStatus; }  @RequestMapping (method = POST) @RequireHardLogIn String doHandleThreeDSecureResponse(final HttpServletRequest request, final ThreeDSecureForm threeDSecureForm, final RedirectAttributes redirectAttributes);  }
@Test public void shouldRedirectToOrderConfirmationPageOnAuthorisedDirectResponse() throws InvalidCartException, WorldpayException { when(directResponseDataMock.getTransactionStatus()).thenReturn(TransactionStatus.AUTHORISED); when(checkoutFacade.placeOrder(any())).thenReturn(orderDataMock); final String result = testObj.doHandleThreeDSecureResponse(requestMock, threeDSecureFormMock, redirectAttributesMock); verify(worldpayDirectOrderFacadeMock).authorise3DSecure(PA_RESPONSE, worldpayAdditionalInfoDataMock); assertTrue(result.contains(CHECKOUT_ORDER_CONFIRMATION)); }
@Test public void shouldRedirectToChoosePaymentPageOnRefusedDirectResponse() throws InvalidCartException, WorldpayException { when(directResponseDataMock.getTransactionStatus()).thenReturn(REFUSED); when(directResponseDataMock.getReturnCode()).thenReturn(RETURN_CODE); final String result = testObj.doHandleThreeDSecureResponse(requestMock, threeDSecureFormMock, redirectAttributesMock); verify(worldpayCartServiceMock).setWorldpayDeclineCodeOnCart(WORLDPAY_ORDER_CODE, RETURN_CODE); verify(worldpayDirectOrderFacadeMock).authorise3DSecure(PA_RESPONSE, worldpayAdditionalInfoDataMock); assertTrue(result.contains(REDIRECT_URL_CHOOSE_PAYMENT_METHOD)); }
@Test public void shouldRedirectToErrorPageOnErrorDirectResponse() throws InvalidCartException, WorldpayException { when(directResponseDataMock.getTransactionStatus()).thenReturn(TransactionStatus.ERROR); final String result = testObj.doHandleThreeDSecureResponse(requestMock, threeDSecureFormMock, redirectAttributesMock); verify(worldpayDirectOrderFacadeMock).authorise3DSecure(PA_RESPONSE, worldpayAdditionalInfoDataMock); assertTrue(result.contains(REDIRECT_URL_CHOOSE_PAYMENT_METHOD)); }
@Test public void shouldRedirectToErrorPageWhenInvalidCartExceptionThrown() throws InvalidCartException, WorldpayException { when(directResponseDataMock.getTransactionStatus()).thenReturn(TransactionStatus.ERROR); when(worldpayDirectOrderFacadeMock.authorise3DSecure(PA_RESPONSE, worldpayAdditionalInfoDataMock)).thenThrow(new InvalidCartException(EXCEPTION_MESSAGE)); final String result = testObj.doHandleThreeDSecureResponse(requestMock, threeDSecureFormMock, redirectAttributesMock); verify(worldpayDirectOrderFacadeMock).authorise3DSecure(PA_RESPONSE, worldpayAdditionalInfoDataMock); assertTrue(result.contains(REDIRECT_URL_CHOOSE_PAYMENT_METHOD)); }
@Test public void shouldRedirectToErrorPageWhenWorldpayExceptionThrown() throws InvalidCartException, WorldpayException { when(directResponseDataMock.getTransactionStatus()).thenReturn(TransactionStatus.ERROR); when(worldpayDirectOrderFacadeMock.authorise3DSecure(PA_RESPONSE, worldpayAdditionalInfoDataMock)).thenThrow(new WorldpayException(EXCEPTION_MESSAGE)); final String result = testObj.doHandleThreeDSecureResponse(requestMock, threeDSecureFormMock, redirectAttributesMock); verify(worldpayDirectOrderFacadeMock).authorise3DSecure(PA_RESPONSE, worldpayAdditionalInfoDataMock); assertTrue(result.contains(REDIRECT_URL_CHOOSE_PAYMENT_METHOD)); }