DefaultWorldpayDirectOrderFacade implements WorldpayDirectOrderFacade { @Override public void tokenize(final CartModel cartModel, final CSEAdditionalAuthInfo cseAdditionalAuthInfo, final WorldpayAdditionalInfoData worldpayAdditionalInfoData) throws WorldpayException { Preconditions.checkState(Objects.nonNull(cartModel), "Cannot tokenize where there is no cart"); try { worldpayDirectOrderService.createToken(cartModel, cseAdditionalAuthInfo, worldpayAdditionalInfoData); } catch (final WorldpayConfigurationException e) { LOG.error(THERE_IS_NO_CONFIGURATION); throw e; } } DefaultWorldpayDirectOrderFacade(final WorldpayAuthenticatedShopperIdStrategy worldpayAuthenticatedShopperIdStrategy,
                                            final WorldpayDirectOrderService worldpayDirectOrderService,
                                            final CartService cartService,
                                            final AcceleratorCheckoutFacade acceleratorCheckoutFacade,
                                            final WorldpayPaymentInfoService worldpayPaymentInfoService,
                                            final WorldpayMerchantConfigDataFacade worldpayMerchantConfigDataFacade,
                                            final CartFacade cartFacade); @Override void tokenize(final CartModel cartModel, final CSEAdditionalAuthInfo cseAdditionalAuthInfo, final WorldpayAdditionalInfoData worldpayAdditionalInfoData); @Override void tokenize(final CSEAdditionalAuthInfo cseAdditionalAuthInfo, final WorldpayAdditionalInfoData worldpayAdditionalInfoData); @Override DirectResponseData authorise(final WorldpayAdditionalInfoData worldpayAdditionalInfoData); @Override DirectResponseData authoriseRecurringPayment(final WorldpayAdditionalInfoData worldpayAdditionalInfoData); @Override DirectResponseData authoriseRecurringPayment(final AbstractOrderModel abstractOrderModel,
                                                        final WorldpayAdditionalInfoData worldpayAdditionalInfoData,
                                                        final MerchantInfo merchantInfo); @Override String authoriseKlarnaRedirect(final WorldpayAdditionalInfoData worldpayAdditionalInfoData, final AdditionalAuthInfo additionalAuthInfo); @Override DirectResponseData authoriseApplePayDirect(final ApplePayAdditionalAuthInfo applePayAdditionalAuthInfo); @Override DirectResponseData authoriseGooglePayDirect(final GooglePayAdditionalAuthInfo googlePayAdditionalAuthInfo); @Override ApplePayOrderUpdate updatePaymentMethod(final ApplePayPaymentMethodUpdateRequest paymentMethodUpdateRequest); @Override String authoriseBankTransferRedirect(final BankTransferAdditionalAuthInfo bankTransferAdditionalAuthInfo,
                                                final WorldpayAdditionalInfoData worldpayAdditionalInfoData); @Override DirectResponseData authorise3DSecure(final String paResponse, final WorldpayAdditionalInfoData worldpayAdditionalInfoData); @Override DirectResponseData executeSecondPaymentAuthorisation3DSecure(); @Override DirectResponseData authoriseAndTokenize(final WorldpayAdditionalInfoData worldpayAdditionalInfoData, final CSEAdditionalAuthInfo cseAdditionalAuthInfo); CartService getCartService();  }
@Test(expected = IllegalStateException.class) public void tokenize_ShouldRiseAnException_WhenThereIsNotSessionCart() throws WorldpayException, IllegalStateException { when(cartServiceMock.hasSessionCart()).thenReturn(Boolean.FALSE); testObj.tokenize(cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); }
@Test(expected = WorldpayException.class) public void tokenize_ShouldRiseAnException_WhenTokeniseWithCartParameterRiseAWorldpayException() throws WorldpayException, IllegalStateException { doThrow(new WorldpayException("Token creation error")).when(worldpayDirectOrderServiceMock).createToken(cartModelMock, cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); testObj.tokenize(cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); }
@Test public void tokenize_ShouldCreateToken_WhenThereIsCartInSession() throws WorldpayException, IllegalStateException { testObj.tokenize(cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock).createToken(cartModelMock, cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); }
@Test(expected = IllegalStateException.class) public void tokenize_ShouldRiseAnException_WhenCartParameterIsNull() throws WorldpayException, IllegalStateException { cartModelMock = null; testObj.tokenize(cartModelMock, cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); }
@Test(expected = WorldpayException.class) public void tokenize_ShouldRiseAnException_WhenCreateTokenRiseAWorldpayException() throws WorldpayException, IllegalStateException { doThrow(new WorldpayException("Token creation error")).when(worldpayDirectOrderServiceMock).createToken(cartModelMock, cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); testObj.tokenize(cartModelMock, cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); }
@Test public void tokenize_ShouldCreateTokenHavingCartParameter_WhenThereIsCartInSession() throws WorldpayException, IllegalStateException { testObj.tokenize(cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock).createToken(cartModelMock, cseAdditionalAuthInfoMock, worldpayAdditionalInfoDataMock); }