WorldpaySummaryCheckoutStepController extends AbstractWorldpayDirectCheckoutStepController { @RequestMapping(value = "/placeOrder") @RequireHardLogIn public String placeOrder(@ModelAttribute("csePaymentForm") final CSEPaymentForm csePaymentForm, final Model model, final HttpServletRequest request, final RedirectAttributes redirectAttributes, final HttpServletResponse response) throws CMSItemNotFoundException { if (validateCart(redirectAttributes)) { return REDIRECT_PREFIX + CART_SUFFIX; } if (!isOrderFormValid(csePaymentForm, model)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return enterStep(model, redirectAttributes, response); } final CSEAdditionalAuthInfo cseAdditionalAuthInfo = createCSESubscriptionAdditionalAuthInfo(csePaymentForm); final WorldpayAdditionalInfoData worldpayAdditionalInfoData = getWorldpayAdditionalInfo(request, csePaymentForm.getSecurityCode(), cseAdditionalAuthInfo); return authorisePayment(model, worldpayAdditionalInfoData, response); }  @RequestMapping(value = "/view", method = RequestMethod.GET) @RequireHardLogIn @PreValidateCheckoutStep(checkoutStep = SUMMARY) String enterStep(final Model model, final RedirectAttributes redirectAttributes, final HttpServletResponse response); @RequestMapping(value = "/placeOrder") @RequireHardLogIn String placeOrder(@ModelAttribute("csePaymentForm") final CSEPaymentForm csePaymentForm, final Model model,
                             final HttpServletRequest request, final RedirectAttributes redirectAttributes, final HttpServletResponse response); @RequestMapping(value = "/express", method = RequestMethod.GET) @RequireHardLogIn String performExpressCheckout(final Model model, final RedirectAttributes redirectModel, final HttpServletResponse response); @GetMapping(value = "/DDCIframe") @RequireHardLogIn String getDDCIframeContent(final Model model); @GetMapping(value = "/challengeIframe") @RequireHardLogIn String getChallengeIframeContent(final Model model); @RequestMapping(value = "/back", method = RequestMethod.GET) @RequireHardLogIn @Override String back(final RedirectAttributes redirectAttributes); @RequestMapping(value = "/next", method = RequestMethod.GET) @RequireHardLogIn @Override String next(final RedirectAttributes redirectAttributes); @Override CheckoutFlowFacade getCheckoutFlowFacade();  }
@Test public void shouldRedirectToOrderConfirmationPage() throws CMSItemNotFoundException, WorldpayException, InvalidCartException { when(worldpayDirectOrderFacadeMock.authoriseRecurringPayment(worldpayAdditionalInfoDataMock)).thenReturn(directResponseDataMock); doReturn(REDIRECT_VIEW).when(testObj).handleDirectResponse(modelMock, directResponseDataMock, responseMock); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(REDIRECT_VIEW, result); verify(worldpayAdditionalInfoDataMock).setSecurityCode(SECURITY_CODE); }
@Test public void shouldRedirectsToSummaryPageOnInvalidCartException() throws InvalidCartException, CMSItemNotFoundException, WorldpayException { doThrow(new InvalidCartException(EXCEPTION_MESSAGE)).when(worldpayDirectOrderFacadeMock).authoriseRecurringPayment(worldpayAdditionalInfoDataMock); when(worldpayMerchantConfigDataMock.getThreeDSFlexJsonWebTokenSettings().getDdcUrl()).thenReturn(THREEDSECURE_FLEX_DDC_URL_VALUE); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldRedirectsToSummaryPageOnWorldpayException() throws InvalidCartException, CMSItemNotFoundException, WorldpayException { doThrow(new WorldpayException(EXCEPTION_MESSAGE)).when(worldpayDirectOrderFacadeMock).authoriseRecurringPayment(worldpayAdditionalInfoDataMock); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldRedirectToCartPageWhenCartIsInvalid() throws CMSItemNotFoundException, CommerceCartModificationException { when(cartFacadeMock.validateCartData()).thenReturn(singletonList(cartModificationDataMock)); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(REDIRECT_PREFIX + CART_SUFFIX, result); }
@Test public void shouldStayOnSummaryPageWhenSecurityCodeIsBlank() throws CMSItemNotFoundException { when(cartDataMock.getPaymentInfo().getSubscriptionId()).thenReturn(SUBSCRIPTION_ID); when(formMock.getSecurityCode()).thenReturn(StringUtils.EMPTY); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldStayOnSummaryPageWhenNoDeliveryAddress() throws CMSItemNotFoundException { when(checkoutFlowFacadeMock.hasNoDeliveryAddress()).thenReturn(true); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldStayOnSummaryPageWhenNoDeliveryMode() throws CMSItemNotFoundException { when(checkoutFlowFacadeMock.hasNoDeliveryMode()).thenReturn(true); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldStayOnSummaryPageWhenNoPaymentInfo() throws CMSItemNotFoundException { when(checkoutFlowFacadeMock.hasNoPaymentInfo()).thenReturn(true); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldStayOnSummaryPageWhenTermsAreNotChecked() throws CMSItemNotFoundException { when(formMock.isTermsCheck()).thenReturn(false); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldStayOnSummaryPageWhenCartDoesNotContainTaxValues() throws CMSItemNotFoundException { when(checkoutFacadeMock.containsTaxValues()).thenReturn(false); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }
@Test public void shouldStayOnSummaryPageWhenCartIsNotCalculated() throws CMSItemNotFoundException { when(cartDataMock.isCalculated()).thenReturn(false); final String result = testObj.placeOrder(formMock, modelMock, httpServletRequestMock, redirectAttributesMock, responseMock); assertEquals(CHECKOUT_SUMMARY_PAGE, result); }