WorldpayHopResponseController extends WorldpayChoosePaymentMethodCheckoutStepController { @RequireHardLogIn @RequestMapping(value = "/hop-response", method = RequestMethod.GET) public String doHandleHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes) { final Map<String, String> requestParameterMap = getRequestParameterMap(request); final RedirectAuthoriseResult response = extractAuthoriseResultFromRequest(request); if (!requestParameterMap.containsKey(PAYMENT_STATUS_PARAMETER_NAME)) { return handleHopResponseWithoutPaymentStatus(model, redirectAttributes, response); } if (getWorldpayHostedOrderFacade().validateRedirectResponse(requestParameterMap)) { return handleHopResponseWithPaymentStatus(model, redirectAttributes, response); } return doHostedOrderPageError(ERROR.name(), redirectAttributes); }  @RequireHardLogIn @RequestMapping(value = "/hop-response", method = RequestMethod.GET) String doHandleHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes); @RequireHardLogIn @RequestMapping(value = "/hop-pending", method = RequestMethod.GET) String doHandlePendingHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes); @RequireHardLogIn @RequestMapping(value = "bank-transfer/hop-response", method = RequestMethod.GET) String doHandleBankTransferHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes); @RequireHardLogIn @RequestMapping(value = "bank-transfer/hop-failure", method = RequestMethod.GET) String doHandleBankTransferHopFailure(final HttpServletRequest request, final RedirectAttributes redirectAttributes); @RequestMapping(value = "/hop-cancel", method = RequestMethod.GET) @RequireHardLogIn String doCancelPayment(); @RequestMapping(value = "/error", method = RequestMethod.GET) @RequireHardLogIn String doHostedOrderPageError(@RequestParam(value = "paymentStatus", required = false) final String paymentStatus, final RedirectAttributes redirectAttributes); @RequestMapping(value = "/billingaddressform", method = RequestMethod.GET) String getCountryAddressForm(@RequestParam("countryIsoCode") final String countryIsoCode,
                                        @RequestParam("useDeliveryAddress") final boolean useDeliveryAddress, final Model model);  }
@Test public void doHandleHopResponseREFUSEDShouldRedirectToChoosePaymentMethod() throws InvalidCartException { when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(REFUSED); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock, never()).completeRedirectAuthorise(redirectAuthoriseResultMock); verify(checkoutFacadeMock, never()).placeOrder(); verify(redirectAttributesMock).addFlashAttribute(PAYMENT_STATUS_PARAMETER_NAME, REFUSED.name()); assertEquals(format(CHOOSE_PAYMENT_REDIRECT_URL, REFUSED.name()), result); }
@Test public void doHandleHopResponseAUTHORISEDShouldCompleteRedirectAndPlaceOrderWhenResponseIsValid() throws InvalidCartException { when(checkoutFacadeMock.placeOrder()).thenReturn(orderDataMock); when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(AuthorisedStatus.AUTHORISED); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock).completeRedirectAuthorise(redirectAuthoriseResultMock); verify(checkoutFacadeMock).placeOrder(); assertEquals(ORDER_CONFIRMATION_PAGE, result); }
@Test public void doHandleHopResponseShouldNOTCompleteRedirectAndNOTPlaceOrderWhenResponseIsNotValid() throws InvalidCartException { when(worldpayHostedOrderFacadeMock.validateRedirectResponse(anyMapOf(String.class, String.class))).thenReturn(false); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock, never()).completeRedirectAuthorise(redirectAuthoriseResultMock); verify(checkoutFacadeMock, never()).placeOrder(); verify(redirectAttributesMock).addFlashAttribute(PAYMENT_STATUS_PARAMETER_NAME, ERROR.name()); assertEquals(format(CHOOSE_PAYMENT_REDIRECT_URL, ERROR.name()), result); }
@Test public void doHandleHopResponseNotAUTHORISEDShouldNotCompleteRedirectAndNotPlaceOrderWhenResponseIsValid() throws InvalidCartException { when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(REFUSED); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock, never()).completeRedirectAuthorise(redirectAuthoriseResultMock); verify(checkoutFacadeMock, never()).placeOrder(); verify(redirectAttributesMock).addFlashAttribute(PAYMENT_STATUS_PARAMETER_NAME, REFUSED.name()); assertEquals(format(CHOOSE_PAYMENT_REDIRECT_URL, REFUSED.name()), result); }
@Test public void handleHopResponseShouldRedirectUserToOrderConfirmationPageWhenOrderHasAlreadyBeenPlaced() { when(checkoutFacadeMock.hasValidCart()).thenReturn(false); when(worldpayPaymentTransactionServiceMock.getPaymentTransactionFromCode(WORLDPAY_ORDER_CODE)).thenReturn(paymentTransactionModelMock); when(paymentTransactionModelMock.getOrder()).thenReturn(orderModelMock); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayPaymentTransactionServiceMock).getPaymentTransactionFromCode(WORLDPAY_ORDER_CODE); assertEquals(ORDER_CONFIRMATION_PAGE, result); }
@Test public void handleHopResponseShouldRedirectUserToEmptyCartPageWhenCartIsInvalidAndTransactionIsNotFound() { when(checkoutFacadeMock.hasValidCart()).thenReturn(false); when(worldpayPaymentTransactionServiceMock.getPaymentTransactionFromCode(WORLDPAY_ORDER_CODE)).thenReturn(paymentTransactionModelMock); when(paymentTransactionModelMock.getOrder()).thenReturn(cartModelMock); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayPaymentTransactionServiceMock).getPaymentTransactionFromCode(WORLDPAY_ORDER_CODE); assertEquals(AbstractController.REDIRECT_PREFIX + "/cart", result); }
@Test public void shouldInquiryWorldpayWhenPaymentStatusIsNotPresentInTheResultURLParametersAndPlaceOrderIfInquiredPaymentStatusIsAuthorised() throws Exception { mockHttpServletRequest.removeParameter(PAYMENT_STATUS_PARAMETER_NAME); when(checkoutFacadeMock.placeOrder()).thenReturn(orderDataMock); when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(null); when(worldpayHostedOrderFacadeMock.inquiryPaymentStatus()).thenReturn(redirectAuthoriseResultFromInquiryMock); when(redirectAuthoriseResultFromInquiryMock.getPaymentStatus()).thenReturn(AuthorisedStatus.AUTHORISED); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock).completeRedirectAuthorise(redirectAuthoriseResultFromInquiryMock); verify(checkoutFacadeMock).placeOrder(); assertEquals(ORDER_CONFIRMATION_PAGE, result); }
@Test public void shouldInquiryWorldpayWhenPaymentStatusIsNotPresentInTheResultURLParametersButNotPlaceOrderWhenPaymentStatusIsNotAuthorised() throws Exception { mockHttpServletRequest.removeParameter(PAYMENT_STATUS_PARAMETER_NAME); when(checkoutFacadeMock.placeOrder()).thenReturn(orderDataMock); when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(null); when(worldpayHostedOrderFacadeMock.inquiryPaymentStatus()).thenReturn(redirectAuthoriseResultFromInquiryMock); when(redirectAuthoriseResultFromInquiryMock.getPaymentStatus()).thenReturn(AuthorisedStatus.ERROR); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock, never()).completeRedirectAuthorise(redirectAuthoriseResultFromInquiryMock); verify(checkoutFacadeMock, never()).placeOrder(); assertEquals(format(CHOOSE_PAYMENT_REDIRECT_URL, ERROR.name()), result); }
@Test public void handleHopResponseShouldRedirectUserToOrderConfirmationPageWhenOrderHasAlreadyBeenPlacedAndPaymentStatusIsNotInTheResultURLParameters() { mockHttpServletRequest.removeParameter(PAYMENT_STATUS_PARAMETER_NAME); when(checkoutFacadeMock.hasValidCart()).thenReturn(false); when(worldpayPaymentTransactionServiceMock.getPaymentTransactionFromCode(WORLDPAY_ORDER_CODE)).thenReturn(paymentTransactionModelMock); when(paymentTransactionModelMock.getOrder()).thenReturn(orderModelMock); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayPaymentTransactionServiceMock).getPaymentTransactionFromCode(WORLDPAY_ORDER_CODE); assertEquals(ORDER_CONFIRMATION_PAGE, result); }
@Test public void shouldRedirectToErrorPageWhenInquiryCommunicationFails() throws Exception { mockHttpServletRequest.removeParameter(PAYMENT_STATUS_PARAMETER_NAME); when(checkoutFacadeMock.placeOrder()).thenReturn(orderDataMock); when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(null); when(worldpayHostedOrderFacadeMock.inquiryPaymentStatus()).thenThrow(new WorldpayException("There was an error")); final String result = testObj.doHandleHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock, never()).completeRedirectAuthorise(redirectAuthoriseResultMock); verify(checkoutFacadeMock, never()).placeOrder(); assertEquals(format(CHOOSE_PAYMENT_REDIRECT_URL, ERROR.name()), result); }