DefaultWorldpayRedirectOrderService extends AbstractWorldpayOrderService implements WorldpayRedirectOrderService { @Override public boolean validateRedirectResponse(final MerchantInfo merchantInfo, final Map<String, String> resultMap) { final String orderKey = resultMap.get(ORDER_KEY); if (StringUtils.isBlank(orderKey)) { return false; } final String paymentStatus = resultMap.get(PAYMENT_STATUS); if (shouldValidateMac(merchantInfo, paymentStatus)) { final String mac2 = resultMap.getOrDefault(KEY_MAC2, ""); final String mac = resultMap.getOrDefault(KEY_MAC, mac2); final String paymentAmount = resultMap.get(KEY_PAYMENT_AMOUNT); final String paymentCurrency = resultMap.get(KEY_PAYMENT_CURRENCY); return validateResponse(merchantInfo, orderKey, mac, paymentAmount, paymentCurrency, AuthorisedStatus.valueOf(paymentStatus)); } return true; } 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 testCheckResponseIsValidWhenNotUsingMacValidation() { when(merchantInfoMock.isUsingMacValidation()).thenReturn(false); final boolean result = testObj.validateRedirectResponse(merchantInfoMock, createWorldpayResponseWithOrderKeyOnly()); assertTrue(result); }
@Test public void testCheckResponseIsValidWhenRedirectResponseStatusIsOPEN() { when(merchantInfoMock.isUsingMacValidation()).thenReturn(true); final boolean result = testObj.validateRedirectResponse(merchantInfoMock, createWorldpayResponseWithOrderKeyOnly()); assertTrue(result); }
@Test public void testCheckResponseIsNotValidWhenNoOrderKeyPresent() { final boolean result = testObj.validateRedirectResponse(merchantInfoMock, createWorldpayResponseWithNoOrderKey()); assertFalse(result); }