DefaultWorldpayDirectOrderFacade implements WorldpayDirectOrderFacade { @Override public DirectResponseData authorise(final WorldpayAdditionalInfoData worldpayAdditionalInfoData) throws WorldpayException, InvalidCartException { Preconditions.checkState(cartService.hasSessionCart(), CANNOT_AUTHORIZE_PAYMENT_WHERE_THERE_IS_NO_CART_MESSAGE); final CartModel cart = cartService.getSessionCart(); return internalAuthorise(cart, worldpayAdditionalInfoData); } 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 public void shouldReturnOrderDataWhenAuthorisedAndOrderPlaced() throws Exception { when(cseAdditionalAuthInfoMock.getSaveCard()).thenReturn(Boolean.FALSE); when(worldpayAdditionalInfoDataMock.getSecurityCode()).thenReturn(CVC); final DirectResponseData result = testObj.authorise(worldpayAdditionalInfoDataMock); final InOrder inOrder = inOrder(acceleratorCheckoutFacadeMock, worldpayDirectOrderServiceMock); inOrder.verify(worldpayDirectOrderServiceMock).completeAuthorise(directAuthoriseServiceResponseMock, cartModelMock); inOrder.verify(acceleratorCheckoutFacadeMock).placeOrder(); assertEquals(acceleratorCheckoutFacadeMock.placeOrder(), result.getOrderData()); assertEquals(AUTHORISED, result.getTransactionStatus()); }
@Test public void authoriseShouldReturnResponseDataWithStatusRefusedAndOrderDataNull() throws Exception { when(paymentReplyMock.getAuthStatus()).thenReturn(REFUSED); when(paymentReplyMock.getReturnCode()).thenReturn(RETURN_CODE); final DirectResponseData result = testObj.authorise(worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock).authorise(cartModelMock, worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock, never()).completeAuthorise(any(DirectAuthoriseServiceResponse.class), any(CartModel.class)); assertNull(result.getOrderData()); assertEquals(RETURN_CODE, result.getReturnCode()); assertEquals(TransactionStatus.REFUSED, result.getTransactionStatus()); }
@Test public void authoriseShouldNotCompleteOrderWhenPaymentReplyIsCancelled() throws Exception { when(paymentReplyMock.getAuthStatus()).thenReturn(CANCELLED); final DirectResponseData authorise = testObj.authorise(worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock).authorise(cartModelMock, worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock, never()).completeAuthorise(any(DirectAuthoriseServiceResponse.class), any(CartModel.class)); assertEquals(TransactionStatus.CANCELLED, authorise.getTransactionStatus()); }
@Test public void authoriseShouldRaiseIllegalStateExceptionWhenTryingToAuthoriseWithoutCart() throws WorldpayException, InvalidCartException { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Cannot authorize payment where there is no cart"); when(cartServiceMock.hasSessionCart()).thenReturn(Boolean.FALSE); testObj.authorise(worldpayAdditionalInfoDataMock); }
@Test(expected = WorldpayException.class) public void authoriseShouldRaiseExceptionWhenPaymentReplayIsNullAndErrorDetailIsNotNull() throws Exception { when(directAuthoriseServiceResponseMock.getErrorDetail()).thenReturn(errorDetailMock); when(errorDetailMock.getMessage()).thenReturn(ERROR_MESSAGE); when(directAuthoriseServiceResponseMock.getPaymentReply()).thenReturn(null); testObj.authorise(worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock).authorise(cartModelMock, worldpayAdditionalInfoDataMock); verify(worldpayDirectOrderServiceMock, never()).completeAuthorise(any(DirectAuthoriseServiceResponse.class), any(CartModel.class)); }
@Test public void shouldReturnDirectResponseDataWith3DSecureInformationWhenDirectAuthoriseServiceResponseContainsRequest3DSLegacyFlowInfo() throws WorldpayException, InvalidCartException { when(directAuthoriseServiceResponseMock.getPaymentReply()).thenReturn(null); when(directAuthoriseServiceResponseMock.getRequest3DInfo()).thenReturn(request3DInfoMock); when(request3DInfoMock.getIssuerUrl()).thenReturn(ISSUER_URL); when(request3DInfoMock.getPaRequest()).thenReturn(PA_REQUEST); final DirectResponseData result = testObj.authorise(worldpayAdditionalInfoDataMock); assertThat(result.getIssuerURL()).isEqualTo(ISSUER_URL); assertThat(result.getPaRequest()).isEqualTo(PA_REQUEST); assertThat(result.getMajor3DSVersion()).isNullOrEmpty(); assertThat(result.getTransactionId3DS()).isNullOrEmpty(); assertThat(result.getIssuerPayload()).isNullOrEmpty(); assertThat(result.getTransactionStatus()).isEqualTo(AUTHENTICATION_REQUIRED); }
@Test public void shouldReturnDirectResponseDataWith3DSecureInformationWhenDirectAuthoriseServiceResponseContainsRequest3DSV2Info() throws WorldpayException, InvalidCartException { when(directAuthoriseServiceResponseMock.getPaymentReply()).thenReturn(null); when(directAuthoriseServiceResponseMock.getRequest3DInfo()).thenReturn(request3DInfoMock); when(request3DInfoMock.getMajor3DSVersion()).thenReturn(THREEDS_V2); when(request3DInfoMock.getIssuerUrl()).thenReturn(ISSUER_URL); when(request3DInfoMock.getIssuerPayload()).thenReturn(ISSUER_PAYLOAD); when(request3DInfoMock.getTransactionId3DS()).thenReturn(TRANSACTION_ID_3DS); when(request3DInfoMock.getPaRequest()).thenReturn(PA_REQUEST); final DirectResponseData result = testObj.authorise(worldpayAdditionalInfoDataMock); assertEquals(ISSUER_URL, result.getIssuerURL()); assertEquals(PA_REQUEST, result.getPaRequest()); assertEquals(THREEDS_V2, result.getMajor3DSVersion()); assertEquals(TRANSACTION_ID_3DS, result.getTransactionId3DS()); assertEquals(AUTHENTICATION_REQUIRED, result.getTransactionStatus()); }
@Test public void shouldReturnDirectResponseDataWith3DSecureInformationWhenDirectAuthoriseServiceResponseContainsRequest3DSV1Info() throws WorldpayException, InvalidCartException { when(directAuthoriseServiceResponseMock.getPaymentReply()).thenReturn(null); when(directAuthoriseServiceResponseMock.getRequest3DInfo()).thenReturn(request3DInfoMock); when(request3DInfoMock.getMajor3DSVersion()).thenReturn(THREEDS_V1); when(request3DInfoMock.getIssuerUrl()).thenReturn(ISSUER_URL); when(request3DInfoMock.getIssuerPayload()).thenReturn(ISSUER_PAYLOAD); when(request3DInfoMock.getTransactionId3DS()).thenReturn(TRANSACTION_ID_3DS); when(request3DInfoMock.getPaRequest()).thenReturn(PA_REQUEST); final DirectResponseData result = testObj.authorise(worldpayAdditionalInfoDataMock); assertEquals(ISSUER_URL, result.getIssuerURL()); assertEquals(PA_REQUEST, result.getPaRequest()); assertEquals(THREEDS_V1, result.getMajor3DSVersion()); assertEquals(TRANSACTION_ID_3DS, result.getTransactionId3DS()); assertEquals(AUTHENTICATION_REQUIRED, result.getTransactionStatus()); }
@Test public void authoriseShouldGenerateAuthenticatedShopperId() throws InvalidCartException, WorldpayException { testObj.authorise(worldpayAdditionalInfoDataMock); verify(worldpayAdditionalInfoDataMock).setAuthenticatedShopperId(AUTHENTICATED_SHOPPER_ID); }