DirectAuthoriseResponseTransformer extends AbstractServiceResponseTransformer { @Override public ServiceResponse transform(final PaymentService paymentServiceReply) throws WorldpayModelTransformationException { final Object responseType = paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().get(0); if (responseType == null) { throw new WorldpayModelTransformationException("No reply message in Worldpay response"); } if (!(responseType instanceof Reply)) { throw new WorldpayModelTransformationException("Reply type from Worldpay not the expected type"); } final Reply intReply = (Reply) responseType; final DirectAuthoriseServiceResponse authResponse = new DirectAuthoriseServiceResponse(); if (getServiceResponseTransformerHelper().checkForError(authResponse, intReply)) { return authResponse; } final Object response = intReply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken().get(0); if (response instanceof OrderStatus) { final OrderStatus intOrderStatus = (OrderStatus) response; authResponse.setOrderCode(intOrderStatus.getOrderCode()); final List<Object> intOrderStatusElements = intOrderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); for (final Object orderStatusType : intOrderStatusElements) { transformOrderStatus(authResponse, intOrderStatus, orderStatusType); } } else { throw new WorldpayModelTransformationException("No order status returned in Worldpay reply message"); } return authResponse; }  @Override ServiceResponse transform(final PaymentService paymentServiceReply);  }
@Test public void testTransformShouldCreateServiceResponseFromPaymentServiceWithRequestInfoFor3DS1() throws WorldpayModelTransformationException { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final OrderStatus orderStatus = new OrderStatus(); orderStatus.setOrderCode(ORDER_CODE); responses.add(orderStatus); final List<Object> intOrderStatuses = orderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); final RequestInfo requestInfo = new RequestInfo(); final Request3DSecure request3DSecure = new Request3DSecure(); final IssuerURL issuerURL = new IssuerURL(); issuerURL.setvalue(ISSUER_URL); final PaRequest paRequest = new PaRequest(); paRequest.setvalue(PA_REQUEST); request3DSecure.getPaRequestOrIssuerURLOrMpiRequestOrMpiURL().addAll(Arrays.asList(issuerURL, paRequest)); requestInfo.setRequest3DSecure(request3DSecure); intOrderStatuses.add(requestInfo); final Token token = new Token(); intOrderStatuses.add(token); final EchoData echoData = new EchoData(); echoData.setvalue(ECHO_DATA); intOrderStatuses.add(echoData); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.buildTokenReply(token)).thenReturn(tokenReplyMock); final DirectAuthoriseServiceResponse result = (DirectAuthoriseServiceResponse) testObj.transform(paymentServiceReply); assertNotNull(result.getRequest3DInfo()); assertNull(result.getPaymentReply()); assertNull(result.getRedirectReference()); assertEquals(ORDER_CODE, result.getOrderCode()); assertEquals(ECHO_DATA, result.getEchoData()); assertEquals(tokenReplyMock, result.getToken()); assertThat(result.getRequest3DInfo().getIssuerUrl()).isEqualTo(ISSUER_URL); assertThat(result.getRequest3DInfo().getPaRequest()).isEqualTo(PA_REQUEST); assertThat(result.getRequest3DInfo().getMajor3DSVersion()).isNullOrEmpty(); assertThat(result.getRequest3DInfo().getTransactionId3DS()).isNullOrEmpty(); }
@Test(expected = WorldpayModelTransformationException.class) public void testTransformWhenNoOrderStatus() throws WorldpayModelTransformationException { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final Error error = new Error(); responses.add(error); final Token token = new Token(); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.buildTokenReply(token)).thenReturn(tokenReplyMock); testObj.transform(paymentServiceReply); }
@Test public void testTransformShouldCreateServiceResponseFromPaymentServiceWithRequestInfoFor3DS2() throws Exception { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final OrderStatus orderStatus = new OrderStatus(); orderStatus.setOrderCode(ORDER_CODE); responses.add(orderStatus); final List<Object> orderStatusType = orderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); final RequestInfo requestInfo = new RequestInfo(); final ChallengeRequired challengeRequired = new ChallengeRequired(); final ThreeDSChallengeDetails threeDSChallengeDetails = new ThreeDSChallengeDetails(); threeDSChallengeDetails.setAcsURL(ISSUER_URL); threeDSChallengeDetails.setPayload(ISSUER_PAYLOAD); ThreeDSVersion threeDSVersion = new ThreeDSVersion(); threeDSVersion.setvalue(MAJOR_3DS_VERSION); threeDSChallengeDetails.setThreeDSVersion(threeDSVersion); threeDSChallengeDetails.setTransactionId3DS(TRANSACTION_ID_3DS); challengeRequired.setThreeDSChallengeDetails(threeDSChallengeDetails); orderStatusType.add(challengeRequired); orderStatusType.add(requestInfo); final Token token = new Token(); token.setAuthenticatedShopperID(AUTHENTICATED_SHOPPER_ID); token.setTokenEventReference(REFERENCE_VALUE); orderStatusType.add(token); final EchoData intEchoData = new EchoData(); intEchoData.setvalue(ECHO_DATA); orderStatusType.add(intEchoData); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.buildTokenReply(token)).thenReturn(tokenReplyMock); final DirectAuthoriseServiceResponse result = (DirectAuthoriseServiceResponse) testObj.transform(paymentServiceReply); assertNotNull(result.getRequest3DInfo()); assertNull(result.getPaymentReply()); assertNull(result.getRedirectReference()); assertEquals(ORDER_CODE, result.getOrderCode()); assertEquals(ECHO_DATA, result.getEchoData()); assertEquals(tokenReplyMock, result.getToken()); assertThat(result.getRequest3DInfo().getPaRequest()).isNullOrEmpty(); assertThat(result.getRequest3DInfo().getIssuerUrl()).isEqualTo(ISSUER_URL); assertThat(result.getRequest3DInfo().getMajor3DSVersion()).isEqualTo(MAJOR_3DS_VERSION); assertThat(result.getRequest3DInfo().getTransactionId3DS()).isEqualTo(TRANSACTION_ID_3DS); assertThat(result.getRequest3DInfo().getIssuerPayload()).isEqualTo(ISSUER_PAYLOAD); }
@Test public void testTransformShouldCreateServiceResponseFromPaymentServiceWithRequestInfoAndIssuerURLAndPaRequestIsNull() throws WorldpayModelTransformationException { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final OrderStatus orderStatus = new OrderStatus(); orderStatus.setOrderCode(ORDER_CODE); responses.add(orderStatus); final List<Object> orderStatusType = orderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); final RequestInfo requestInfo = new RequestInfo(); final Request3DSecure request3DSecure = new Request3DSecure(); requestInfo.setRequest3DSecure(request3DSecure); orderStatusType.add(requestInfo); final Token token = new Token(); orderStatusType.add(token); final EchoData echoData = new EchoData(); echoData.setvalue(ECHO_DATA); orderStatusType.add(echoData); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.buildTokenReply(token)).thenReturn(tokenReplyMock); final DirectAuthoriseServiceResponse result = (DirectAuthoriseServiceResponse) testObj.transform(paymentServiceReply); assertNotNull(result.getRequest3DInfo()); assertNull(result.getPaymentReply()); assertNull(result.getRedirectReference()); assertEquals(ORDER_CODE, result.getOrderCode()); assertEquals(ECHO_DATA, result.getEchoData()); assertEquals(tokenReplyMock, result.getToken()); assertThat(result.getRequest3DInfo().getIssuerUrl()).isNullOrEmpty(); assertThat(result.getRequest3DInfo().getPaRequest()).isNullOrEmpty(); }
@Test public void testTransformShouldCreateServiceResponseFromPaymentServiceWithPaymentReply() throws WorldpayModelTransformationException { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final OrderStatus orderStatus = new OrderStatus(); orderStatus.setOrderCode(ORDER_CODE); responses.add(orderStatus); final List<Object> orderStatusType = orderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); final Payment payment = new Payment(); orderStatusType.add(payment); final Token token = new Token(); orderStatusType.add(token); final EchoData echoData = new EchoData(); echoData.setvalue(ECHO_DATA); orderStatusType.add(echoData); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.buildPaymentReply(payment)).thenReturn(paymentReplyMock); when(serviceResponseTransformerHelperMock.buildTokenReply(token)).thenReturn(tokenReplyMock); final DirectAuthoriseServiceResponse result = (DirectAuthoriseServiceResponse) testObj.transform(paymentServiceReply); assertNotNull(result.getPaymentReply()); assertNull(result.getRequest3DInfo()); assertNull(result.getRedirectReference()); assertEquals(ORDER_CODE, result.getOrderCode()); assertEquals(ECHO_DATA, result.getEchoData()); assertEquals(paymentReplyMock, result.getPaymentReply()); assertEquals(tokenReplyMock, result.getToken()); }
@Test public void testTransformShouldCreateServiceResponseFromPaymentServiceWithReference() throws WorldpayModelTransformationException { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final OrderStatus orderStatus = new OrderStatus(); orderStatus.setOrderCode(ORDER_CODE); responses.add(orderStatus); final List<Object> orderStatusType = orderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); final Reference reference = new Reference(); reference.setId(REFERENCE_ID); orderStatusType.add(reference); final Token token = new Token(); token.setAuthenticatedShopperID(AUTHENTICATED_SHOPPER_ID); orderStatusType.add(token); final EchoData echoData = new EchoData(); echoData.setvalue(ECHO_DATA); orderStatusType.add(echoData); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.buildTokenReply(token)).thenReturn(tokenReplyMock); final DirectAuthoriseServiceResponse result = (DirectAuthoriseServiceResponse) testObj.transform(paymentServiceReply); assertEquals(tokenReplyMock, result.getToken()); assertNotNull(result.getRedirectReference()); assertNull(result.getPaymentReply()); assertNull(result.getRequest3DInfo()); assertEquals(ORDER_CODE, result.getOrderCode()); assertEquals(ECHO_DATA, result.getEchoData()); assertEquals(REFERENCE_ID, result.getRedirectReference().getId()); }
@Test public void testTransformShouldCreateServiceResponseFromPaymentServiceWithPaymentAndReference() throws WorldpayModelTransformationException { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final OrderStatus orderStatus = new OrderStatus(); orderStatus.setOrderCode(ORDER_CODE); responses.add(orderStatus); final List<Object> orderStatusType = orderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); final Payment payment = new Payment(); orderStatusType.add(payment); final Reference reference = new Reference(); reference.setId(REFERENCE_ID); reference.setvalue(REFERENCE_VALUE); orderStatusType.add(reference); final Token token = new Token(); orderStatusType.add(token); final EchoData echoData = new EchoData(); echoData.setvalue(ECHO_DATA); orderStatusType.add(echoData); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.buildPaymentReply(payment)).thenReturn(paymentReplyMock); when(serviceResponseTransformerHelperMock.buildTokenReply(token)).thenReturn(tokenReplyMock); final DirectAuthoriseServiceResponse result = (DirectAuthoriseServiceResponse) testObj.transform(paymentServiceReply); assertEquals(paymentReplyMock, result.getPaymentReply()); assertEquals(tokenReplyMock, result.getToken()); assertNotNull(result.getPaymentReply()); assertNotNull(result.getRedirectReference()); assertNull(result.getRequest3DInfo()); assertEquals(ORDER_CODE, result.getOrderCode()); assertEquals(ECHO_DATA, result.getEchoData()); assertEquals(REFERENCE_ID, result.getRedirectReference().getId()); assertEquals(REFERENCE_VALUE, result.getRedirectReference().getValue()); }
@Test public void shouldThrowExceptionWhenOrderStatusTypeIsNull() throws WorldpayModelTransformationException { thrown.expect(WorldpayModelTransformationException.class); thrown.expectMessage("No order status type returned in Worldpay reply message"); final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); final List<Object> responses = reply.getOrderStatusOrBatchStatusOrErrorOrAddressCheckResponseOrRefundableAmountOrAccountBatchOrShopperOrOkOrFuturePayAgreementStatusOrShopperAuthenticationResultOrFuturePayPaymentResultOrPricePointOrCheckCardResponseOrPaymentOptionOrToken(); final OrderStatus orderStatus = new OrderStatus(); orderStatus.setOrderCode(ORDER_CODE); responses.add(orderStatus); final List<Object> orderStatusType = orderStatus.getReferenceOrBankAccountOrApmEnrichedDataOrErrorOrPaymentOrQrCodeOrCardBalanceOrPaymentAdditionalDetailsOrBillingAddressDetailsOrExemptionResponseOrOrderModificationOrJournalOrRequestInfoOrChallengeRequiredOrFxApprovalRequiredOrPbbaRTPOrContentOrJournalTypeDetailOrTokenOrDateOrEchoDataOrPayAsOrderUseNewOrderCodeOrAuthenticateResponse(); orderStatusType.add(null); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); testObj.transform(paymentServiceReply); }
@Test public void shouldThrowExceptionWhenResponseTypeIsNull() throws WorldpayModelTransformationException { thrown.expect(WorldpayModelTransformationException.class); thrown.expectMessage("No reply message in Worldpay response"); final PaymentService paymentServiceReply = new PaymentService(); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(null); testObj.transform(paymentServiceReply); }
@Test public void shouldThrowExceptionWhenResponseTypeNotReply() throws WorldpayModelTransformationException { thrown.expect(WorldpayModelTransformationException.class); thrown.expectMessage("Reply type from Worldpay not the expected type"); final PaymentService paymentServiceReply = new PaymentService(); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(new Notify()); testObj.transform(paymentServiceReply); }
@Test public void shouldReturnAuthResponseWithErrorDetailsWhenErrorOccurs() throws WorldpayModelTransformationException { final PaymentService paymentServiceReply = new PaymentService(); final Reply reply = new Reply(); paymentServiceReply.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(reply); when(serviceResponseTransformerHelperMock.checkForError(any(ServiceResponse.class), eq(reply))).thenReturn(true); final ServiceResponse result = testObj.transform(paymentServiceReply); verify(serviceResponseTransformerHelperMock).checkForError(serviceResponseArgumentCaptor.capture(), eq(reply)); assertEquals(result, serviceResponseArgumentCaptor.getValue()); }