DefaultWorldpayRedirectOrderService extends AbstractWorldpayOrderService implements WorldpayRedirectOrderService { @Override public void completePendingRedirectAuthorise(final RedirectAuthoriseResult result, final String merchantCode, final CartModel cartModel) { validateParameterNotNull(result, "RedirectAuthoriseResult cannot be null"); final PaymentInfoModel paymentInfoModel = getWorldpayPaymentInfoService().createPaymentInfo(cartModel); cloneAndSetBillingAddressFromCart(cartModel, paymentInfoModel); final CommerceCheckoutParameter commerceCheckoutParameter = createCommerceCheckoutParameter(cartModel, paymentInfoModel, result.getPaymentAmount()); getCommerceCheckoutService().setPaymentInfo(commerceCheckoutParameter); final PaymentTransactionModel paymentTransaction = getWorldpayPaymentTransactionService().createPaymentTransaction(result.getPending(), merchantCode, commerceCheckoutParameter); getWorldpayPaymentTransactionService().createPendingAuthorisePaymentTransactionEntry(paymentTransaction, merchantCode, cartModel, result.getPaymentAmount()); } 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 testCompleteRedirectAuthoriseAndSetSavedPaymentInfoToTrue() { when(redirectAuthoriseResultMock.getSaveCard()).thenReturn(true); setUpRedirectAuthoriseResultMock(AUTHORISED, true); when(worldpayPaymentTransactionServiceMock.createPaymentTransaction(true, MERCHANT_CODE, commerceCheckoutParameterMock)).thenReturn(paymentTransactionModelMock); testObj.completePendingRedirectAuthorise(redirectAuthoriseResultMock, MERCHANT_CODE, cartModelMock); verify(testObj).cloneAndSetBillingAddressFromCart(cartModelMock, paymentInfoModelMock); verify(testObj).createCommerceCheckoutParameter(cartModelMock, paymentInfoModelMock, bigDecimalMock); verify(commerceCheckoutServiceMock).setPaymentInfo(commerceCheckoutParameterMock); verify(worldpayPaymentTransactionServiceMock).createPendingAuthorisePaymentTransactionEntry(paymentTransactionModelMock, MERCHANT_CODE, cartModelMock, bigDecimalMock); }
@Test public void testCompleteRedirectAuthoriseAndSetSavedPaymentInfoToFalse() { setUpRedirectAuthoriseResultMock(AUTHORISED, true); when(worldpayPaymentTransactionServiceMock.createPaymentTransaction(true, MERCHANT_CODE, commerceCheckoutParameterMock)).thenReturn(paymentTransactionModelMock); testObj.completePendingRedirectAuthorise(redirectAuthoriseResultMock, MERCHANT_CODE, cartModelMock); verify(testObj).cloneAndSetBillingAddressFromCart(cartModelMock, paymentInfoModelMock); verify(testObj).createCommerceCheckoutParameter(cartModelMock, paymentInfoModelMock, bigDecimalMock); verify(worldpayPaymentTransactionServiceMock).createPaymentTransaction(true, MERCHANT_CODE, commerceCheckoutParameterMock); verify(worldpayPaymentTransactionServiceMock).createPendingAuthorisePaymentTransactionEntry(paymentTransactionModelMock, MERCHANT_CODE, cartModelMock, bigDecimalMock); }