WorldpayRedirectCheckoutStepController extends WorldpayChoosePaymentMethodCheckoutStepController { @RequestMapping(value = "/add-payment-details", method = POST) @RequireHardLogIn public String addPaymentDetails(final Model model, @Valid final PaymentDetailsForm paymentDetailsForm, final BindingResult bindingResult, final RedirectAttributes redirectAttrs) throws CMSItemNotFoundException { getPaymentDetailsFormValidator().validate(paymentDetailsForm, bindingResult); if (addGlobalErrors(model, bindingResult)) { return handleFormErrors(model, paymentDetailsForm); } handleAndSaveAddresses(paymentDetailsForm); final String shopperBankCode = paymentDetailsForm.getShopperBankCode(); worldpayCartFacade.resetDeclineCodeAndShopperBankOnCart(shopperBankCode); final String paymentMethod = paymentDetailsForm.getPaymentMethod(); if (isAPM(paymentMethod)) { redirectAttrs.addFlashAttribute(SHOPPER_BANK_CODE, shopperBankCode); } redirectAttrs.addFlashAttribute(SAVE_PAYMENT_INFO, paymentDetailsForm.getSaveInAccount()); redirectAttrs.addFlashAttribute(PAYMENT_METHOD_PARAM, paymentDetailsForm.getPaymentMethod()); return getRedirectToPaymentMethod(); }  @RequestMapping(value = "/add-payment-details", method = POST) @RequireHardLogIn String addPaymentDetails(final Model model, @Valid final PaymentDetailsForm paymentDetailsForm, final BindingResult bindingResult, final RedirectAttributes redirectAttrs);  }
@Test public void addressShouldBeSavedIfCustomerIsAnonymousAndBillingAddressIsDifferentFromShippingAddress() throws CMSItemNotFoundException { when(paymentDetailsFormMock.getUseDeliveryAddress()).thenReturn(FALSE); when(userFacadeMock.isAnonymousUser()).thenReturn(TRUE); testObj.addPaymentDetails(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); verify(paymentDetailsFormValidatorMock).validate(paymentDetailsFormMock, bindingResultMock); verify(worldpayCartFacadeMock).resetDeclineCodeAndShopperBankOnCart(null); verify(testObj).handleAndSaveAddresses(paymentDetailsFormMock); verify(redirectAttrsMock).addFlashAttribute(SAVE_PAYMENT_INFO, true); verify(redirectAttrsMock).addFlashAttribute(PAYMENT_METHOD_PARAM, ONLINE.getMethodCode()); }
@Test public void addBankCodeForAPMPaymentMethod() throws CMSItemNotFoundException { when(paymentDetailsFormMock.getPaymentMethod()).thenReturn(PAYMENT_METHOD); when(apmConfigurationServiceMock.getAllApmPaymentTypeCodes()).thenReturn(singleton(PAYMENT_METHOD)); when(paymentDetailsFormMock.getShopperBankCode()).thenReturn(BANK_CODE); testObj.addPaymentDetails(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); final InOrder inOrder = inOrder(paymentDetailsFormValidatorMock, testObj, worldpayCartFacadeMock, redirectAttrsMock); inOrder.verify(paymentDetailsFormValidatorMock).validate(paymentDetailsFormMock, bindingResultMock); inOrder.verify(testObj).handleAndSaveAddresses(paymentDetailsFormMock); inOrder.verify(worldpayCartFacadeMock).resetDeclineCodeAndShopperBankOnCart(BANK_CODE); inOrder.verify(redirectAttrsMock).addFlashAttribute(SHOPPER_BANK_CODE, BANK_CODE); }
@Test public void shouldRedirectToErrorViewIfErrorsInForm() throws CMSItemNotFoundException { doReturn(true).when(testObj).addGlobalErrors(modelMock, bindingResultMock); doReturn(BILLING_ERROR_VIEW).when(testObj).handleFormErrors(modelMock, paymentDetailsFormMock); final String result = testObj.addPaymentDetails(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); assertEquals(BILLING_ERROR_VIEW, result); }