WorldpayPaymentMethodCheckoutStepController extends AbstractWorldpayPaymentMethodCheckoutStepController { @Override @RequestMapping(value = "/add", method = GET) @RequireHardLogIn @PreValidateCheckoutStep(checkoutStep = PAYMENT_METHOD_STEP_NAME) public String enterStep(final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { setupAddPaymentPage(model); setCheckoutStepLinksForModel(model, getCheckoutStep()); try { final String paymentMethod = (String) model.asMap().get(PAYMENT_METHOD_PARAM); if (isBankTransferAPM(paymentMethod)) { return REDIRECT_PREFIX + getRedirectURLForBankTransfer(model, paymentMethod); } else if (isKlarnaAPM(paymentMethod)) { return getViewContentForKlarna(model); } final PaymentData paymentData = redirectAuthorise(model, paymentMethod); populateModel(model, paymentData); return worldpayAddonEndpointService.getHostedOrderPostPage(); } catch (final WorldpayException e) { LOGGER.error("Failed to communicate successfully with worldpay", e); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.ERROR_MESSAGES_HOLDER, COMMUNICATION_ERROR); return REDIRECT_URL_CHOOSE_PAYMENT_METHOD; } }  @Override @RequestMapping(value = "/add", method = GET) @RequireHardLogIn @PreValidateCheckoutStep(checkoutStep = PAYMENT_METHOD_STEP_NAME) String enterStep(final Model model, final RedirectAttributes redirectAttributes); @Override String back(final RedirectAttributes redirectAttributes); @Override String next(final RedirectAttributes redirectAttributes);  }
@Test public void testEnterStepForCard() throws CMSItemNotFoundException { doReturn(true).when(testObj).paymentMethodIsOnline(PAYMENT_METHOD_VALUE); final String result = testObj.enterStep(modelMock, redirectAttributesMock); verify(siteConfigServiceMock).getBoolean("oms.enabled", false); verify(checkoutFlowFacadeMock).hasNoPaymentInfo(); verify(acceleratorCheckoutFacadeMock).getCountries(CountryType.SHIPPING); verify(acceleratorCheckoutFacadeMock).getCountries(CountryType.BILLING); verify(resourceBreadcrumbBuilderMock).getBreadcrumbs(CHECKOUT_MULTI_PAYMENT_METHOD_BREADCRUMB); verify(pageTitleResolver).resolveContentPageTitle(CMS_PAGE_TITLE); verify(modelMock).addAttribute(HOSTED_ORDER_PAGE_DATA, paymentDataMock); verify(modelMock).addAttribute(HOP_DEBUG_MODE_PARAM, false); verify(paymentDataParametersMock, never()).put(eq(PREFERRED_PAYMENT_METHOD_PARAM), any()); assertEquals(HOSTED_ORDER_PAGE, result); }
@Test public void testEnterStepRedirectToHopPageIfNotBankTransferPayment() throws CMSItemNotFoundException { doReturn(false).when(testObj).paymentMethodIsOnline(PAYMENT_METHOD_VALUE); when(modelMock.asMap().get(PAYMENT_METHOD_PARAM)).thenReturn(PAYMENT_METHOD_VALUE); final String result = testObj.enterStep(modelMock, redirectAttributesMock); verify(modelMock).addAttribute(HOSTED_ORDER_PAGE_DATA, paymentDataMock); verify(paymentDataParametersMock).put(PREFERRED_PAYMENT_METHOD_PARAM, PAYMENT_METHOD_VALUE); assertEquals(HOSTED_ORDER_PAGE, result); }
@Test public void shouldRedirectToInternalUrlWithKlarnaContentWhenPaymentTypeIsKlarna() throws Exception { when(worldpayAddonEndpointServiceMock.getKlarnaResponsePage()).thenReturn(KLARNA_RESPONSE_PAGE); when(modelMock.asMap().get(PAYMENT_METHOD_PARAM)).thenReturn(PAYMENT_METHOD_KLARNA); when(worldpayDirectOrderFacadeMock.authoriseKlarnaRedirect(worldpayAdditionalInfoDataMock, additionalAuthInfoMock)).thenReturn(KLARNA_RESPONSE); final String result = testObj.enterStep(modelMock, redirectAttributesMock); assertEquals(KLARNA_RESPONSE_PAGE, result); verify(modelMock).addAttribute(KLARNA_RESPONSE_PAGE_DATA_PARAM, KLARNA_RESPONSE); }