DefaultWorldpayRedirectOrderService extends AbstractWorldpayOrderService implements WorldpayRedirectOrderService { @Override public PaymentData redirectAuthorise(final MerchantInfo merchantInfo, final CartModel cartModel, final AdditionalAuthInfo additionalAuthInfo) throws WorldpayException { final RedirectAuthoriseServiceRequest request = worldpayRequestFactory.buildRedirectAuthoriseRequest(merchantInfo, cartModel, additionalAuthInfo); final RedirectAuthoriseServiceResponse redirectAuthorise = getWorldpayServiceGateway().redirectAuthorise(request); if (redirectAuthorise == null) { throw new WorldpayException("Response from Worldpay is empty"); } final RedirectReference redirectReference = redirectAuthorise.getRedirectReference(); if (redirectReference == null) { final String errorMessage = redirectAuthorise.getErrorDetail().getMessage(); LOG.error(MessageFormat.format("Error detail: {0}", errorMessage)); throw new WorldpayException(MessageFormat.format("Reference returned from Worldpay is empty - message was: {0}", errorMessage)); } sessionService.setAttribute(WORLDPAY_MERCHANT_CODE, merchantInfo.getMerchantCode()); return buildHOPPageData(redirectReference, request.getOrder().getBillingAddress().getCountryCode()); } DefaultWorldpayRedirectOrderService(final SessionService sessionService, final WorldpayURIService worldpayURIService, final WorldpayUrlService worldpayUrlService, final MacValidator macValidator, final WorldpayRequestFactory worldpayRequestFactory, final CommerceCheckoutService commerceCheckoutService, final WorldpayPaymentInfoService worldpayPaymentInfoService, final WorldpayPaymentTransactionService worldpayPaymentTransactionService, final WorldpayOrderService worldpayOrderService, final WorldpayServiceGateway worldpayServiceGateway, final AddressService addressService); @Override PaymentData redirectAuthorise(final MerchantInfo merchantInfo, final CartModel cartModel, final AdditionalAuthInfo additionalAuthInfo); @Override void completePendingRedirectAuthorise(final RedirectAuthoriseResult result, final String merchantCode, final CartModel cartModel); @Override void completeConfirmedRedirectAuthorise(final BigDecimal paymentAmount, final String merchantCode, final CartModel cartModel); @Override boolean validateRedirectResponse(final MerchantInfo merchantInfo, final Map<String, String> resultMap); MacValidator getMacValidator();  }
@Test public void redirectAuthorise_ShouldReturnPaymentDataCorrectlySet_WhenItIsCall() throws WorldpayException { final PaymentData result = testObj.redirectAuthorise(merchantInfoMock, cartModelMock, additionalAuthInfoMock); verify(sessionServiceMock).setAttribute(WORLDPAY_MERCHANT_CODE, MERCHANT_CODE); verify(worldpayURIServiceMock).extractUrlParamsToMap(eq(REDIRECT_URL), anyMapOf(String.class, String.class)); assertEquals(REDIRECT_URL, result.getPostUrl()); assertEquals(COUNTRY_CODE, result.getParameters().get(KEY_COUNTRY)); assertEquals(LANGUAGE_ISO_CODE, result.getParameters().get(LANGUAGE_SESSION_ATTRIBUTE_KEY)); assertEquals(FULL_SUCCESS_URL, result.getParameters().get(KEY_SUCCESS_URL)); assertEquals(FULL_PENDING_URL, result.getParameters().get(KEY_PENDING_URL)); assertEquals(FULL_FAILURE_URL, result.getParameters().get(KEY_FAILURE_URL)); assertEquals(FULL_CANCEL_URL, result.getParameters().get(KEY_CANCEL_URL)); }
@Test(expected = WorldpayException.class) public void redirectAuthorise_ShouldThrowAWPException_WhenWorldpayServiceGatewayRiseIt() throws WorldpayException { when(worldpayServiceGatewayMock.redirectAuthorise(redirectAuthoriseServiceRequestMock)).thenThrow(new WorldpayException(("Response Error"))); testObj.redirectAuthorise(merchantInfoMock, cartModelMock, additionalAuthInfoMock); }
@Test(expected = WorldpayException.class) public void redirectAuthorise_ShouldThrowAWPException_WhenWorldpayServiceGatewayResponseIsNull() throws WorldpayException { when(worldpayServiceGatewayMock.redirectAuthorise(redirectAuthoriseServiceRequestMock)).thenReturn(null); testObj.redirectAuthorise(merchantInfoMock, cartModelMock, additionalAuthInfoMock); }
@Test(expected = WorldpayException.class) public void redirectAuthorise_ShouldThrowAWPException_WhenRedirectReferenceFromRedirectResponseIsNull() throws WorldpayException { when(redirectAuthoriseServiceResponseMock.getRedirectReference()).thenReturn(null); when(redirectAuthoriseServiceResponseMock.getErrorDetail()).thenReturn(errorDetailMock); when(errorDetailMock.getMessage()).thenReturn(ERROR_MESSAGE); testObj.redirectAuthorise(merchantInfoMock, cartModelMock, additionalAuthInfoMock); }
@Test(expected = WorldpayException.class) public void redirectAuthorise_ShouldThrowAWPException_WhenRedirectReferenceValueIsNull() throws WorldpayException { when(redirectReferenceMock.getValue()).thenReturn(null); testObj.redirectAuthorise(merchantInfoMock, cartModelMock, additionalAuthInfoMock); }