WorldpayHopResponseController extends WorldpayChoosePaymentMethodCheckoutStepController { @RequireHardLogIn @RequestMapping(value = "/hop-pending", method = RequestMethod.GET) public String doHandlePendingHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes) { final Map<String, String> requestParameterMap = getRequestParameterMap(request); AuthorisedStatus paymentStatus = AuthorisedStatus.ERROR; if (getWorldpayHostedOrderFacade().validateRedirectResponse(requestParameterMap)) { final RedirectAuthoriseResult authoriseResult = extractAuthoriseResultFromRequest(request); authoriseResult.setPending(true); paymentStatus = authoriseResult.getPaymentStatus(); if (!apmErrorResponseStatuses.contains(paymentStatus)) { getWorldpayHostedOrderFacade().completeRedirectAuthorise(authoriseResult); return placeOrderAndRedirect(model, redirectAttributes); } else { LOG.error(format("Failed to create payment authorisation for successful hop-response (/hop-pending). Received {0}", paymentStatus.name())); } } return doHostedOrderPageError(paymentStatus.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 doHandlePendingHopResponseOPENShouldCompleteRedirectForAPMAndPlaceOrderWhenResponseIsValid() throws InvalidCartException { when(checkoutFacadeMock.placeOrder()).thenReturn(orderDataMock); when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(AuthorisedStatus.OPEN); final String result = testObj.doHandlePendingHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock).completeRedirectAuthorise(redirectAuthoriseResultMock); verify(checkoutFacadeMock).placeOrder(); verify(redirectAuthoriseResultMock).setPending(true); assertEquals(ORDER_CONFIRMATION_PAGE, result); }
@Test public void doHandlePendingHopResponseNotOPENShouldNotCompleteRedirectForAPMAndNotPlaceOrderWhenResponseIsValid() throws InvalidCartException { when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(AuthorisedStatus.ERROR); final String result = testObj.doHandlePendingHopResponse(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 doHandlePendingHopResponseNotERRORShouldNOTCompleteRedirectForAPMAndNotPlaceOrderWhenResponseIsNotValid() throws InvalidCartException { when(redirectAuthoriseResultMock.getPaymentStatus()).thenReturn(ERROR); final String result = testObj.doHandlePendingHopResponse(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 doHandlePendingHopResponseRaisesExceptionWhenPlacingOrderAndPaymentStatusSet() throws InvalidCartException { when(checkoutFacadeMock.placeOrder()).thenThrow(new InvalidCartException(EXCEPTION_MESSAGE)); final String result = testObj.doHandlePendingHopResponse(mockHttpServletRequest, modelMock, redirectAttributesMock); verify(worldpayHostedOrderFacadeMock).completeRedirectAuthorise(redirectAuthoriseResultMock); verify(redirectAttributesMock).addFlashAttribute(PAYMENT_STATUS_PARAMETER_NAME, ERROR.name()); assertEquals(format(CHOOSE_PAYMENT_REDIRECT_URL, ERROR.name()), result); }