SecondThreeDSecurePaymentRequestTransformer implements ServiceRequestTransformer { @Override public PaymentService transform(final ServiceRequest request) throws WorldpayModelTransformationException { if (request == null || request.getMerchantInfo() == null || StringUtils.isBlank(request.getMerchantInfo().getMerchantCode()) || StringUtils.isBlank(request.getOrderCode())) { throw new WorldpayModelTransformationException("Request provided to do the refund is invalid."); } final SecondThreeDSecurePaymentRequest second3DSPaymentRequest = (SecondThreeDSecurePaymentRequest) request; final PaymentService paymentService = new PaymentService(); paymentService.setMerchantCode(request.getMerchantInfo().getMerchantCode()); paymentService.setVersion(configurationService.getConfiguration().getString(WORLDPAY_CONFIG_VERSION)); if (StringUtils.isBlank(second3DSPaymentRequest.getSessionId())) { throw new WorldpayModelTransformationException("No session id to transform on the second 3ds payment request"); } final List<Object> submitList = paymentService.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify(); final Submit submit = new Submit(); final List<Object> orderList = submit.getOrderOrOrderBatchOrShopperOrFuturePayAgreementOrMakeFuturePayPaymentOrIdentifyMeRequestOrPaymentTokenCreateOrChallenge(); Order order = new Order(); order.setOrderCode(request.getOrderCode()); orderList.add(order); final List<Object> orderElementList = order.getDescriptionOrAmountOrRiskOrOrderContentOrPaymentMethodMaskOrPaymentDetailsOrPayAsOrderOrShopperOrShippingAddressOrBillingAddressOrBranchSpecificExtensionOrRedirectPageAttributeOrPaymentMethodAttributeOrEchoDataOrStatementNarrativeOrHcgAdditionalDataOrThirdPartyDataOrResultURLOrShopperAdditionalDataOrApprovedAmountOrMandateOrAuthorisationAmountStatusOrDynamic3DSOrCreateTokenOrCreateTokenApprovalOrOrderLinesOrSubMerchantDataOrDynamicMCCOrDynamicInteractionTypeOrPrimeRoutingRequestOrRiskDataOrAdditional3DSDataOrExemptionOrShippingMethodOrProductSkuOrDeviceSessionOrInfo3DSecureOrSession(); Info3DSecure info3DSecure = new Info3DSecure(); final List<Object> completedAuthenticationList = info3DSecure.getPaResponseOrMpiProviderOrMpiResponseOrAttemptedAuthenticationOrCompletedAuthenticationOrThreeDSVersionOrMerchantNameOrXidOrDsTransactionIdOrCavvOrEci(); completedAuthenticationList.add(new CompletedAuthentication()); orderElementList.add(info3DSecure); Session session = new Session(); session.setId(second3DSPaymentRequest.getSessionId()); orderElementList.add(session); submitList.add(submit); return paymentService; }  @Override PaymentService transform(final ServiceRequest request); @Required void setConfigurationService(final ConfigurationService configurationService);  }
@Test(expected = WorldpayModelTransformationException.class) public void testTransformSecondThreeDSecurePaymentRequestToPaymentServiceNullMerchantInfo() throws WorldpayModelTransformationException { when(secondThreeDSecurePaymentRequestMock.getSessionId()).thenReturn(SESSION_ID); when(secondThreeDSecurePaymentRequestMock.getOrderCode()).thenReturn(ORDER_CODE); testObj.transform(secondThreeDSecurePaymentRequestMock); }
@Test(expected = WorldpayModelTransformationException.class) public void testTransformSecondThreeDSecurePaymentRequestToPaymentServiceNullMerchantInfoCode() throws WorldpayModelTransformationException { when(secondThreeDSecurePaymentRequestMock.getMerchantInfo()).thenReturn(merchantInfoMock); when(secondThreeDSecurePaymentRequestMock.getSessionId()).thenReturn(SESSION_ID); when(secondThreeDSecurePaymentRequestMock.getOrderCode()).thenReturn(ORDER_CODE); testObj.transform(secondThreeDSecurePaymentRequestMock); }
@Test(expected = WorldpayModelTransformationException.class) public void testTransformSecondThreeDSecurePaymentRequestToPaymentServiceNullOrderCode() throws WorldpayModelTransformationException { when(secondThreeDSecurePaymentRequestMock.getMerchantInfo()).thenReturn(merchantInfoMock); when(merchantInfoMock.getMerchantCode()).thenReturn(MERCHANT_INFO_CODE); when(secondThreeDSecurePaymentRequestMock.getSessionId()).thenReturn(SESSION_ID); testObj.transform(secondThreeDSecurePaymentRequestMock); }
@Test(expected = WorldpayModelTransformationException.class) public void testTransformSecondThreeDSecurePaymentRequestToPaymentServiceWithBlankSessionId() throws WorldpayModelTransformationException { when(secondThreeDSecurePaymentRequestMock.getMerchantInfo()).thenReturn(merchantInfoMock); when(merchantInfoMock.getMerchantCode()).thenReturn(MERCHANT_INFO_CODE); when(secondThreeDSecurePaymentRequestMock.getOrderCode()).thenReturn(ORDER_CODE); testObj.transform(secondThreeDSecurePaymentRequestMock); }
@Test public void testTransformSecondThreeDSecurePaymentRequestToPaymentService() throws WorldpayModelTransformationException { final MerchantInfo merchantInfo = new MerchantInfo("MERCHANT_CODE", "MERCHANT_PASSWORD"); when(secondThreeDSecurePaymentRequestMock.getMerchantInfo()).thenReturn(merchantInfo); when(merchantInfoMock.getMerchantCode()).thenReturn(MERCHANT_INFO_CODE); when(secondThreeDSecurePaymentRequestMock.getOrderCode()).thenReturn(ORDER_CODE); when(secondThreeDSecurePaymentRequestMock.getSessionId()).thenReturn(SESSION_ID); final PaymentService result = testObj.transform(secondThreeDSecurePaymentRequestMock); final List<Object> submitList = result.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify(); final Submit submit = (Submit) submitList.get(0); final List<Object> orderList = submit.getOrderOrOrderBatchOrShopperOrFuturePayAgreementOrMakeFuturePayPaymentOrIdentifyMeRequestOrPaymentTokenCreateOrChallenge(); final com.worldpay.internal.model.Order intOrder = (com.worldpay.internal.model.Order) orderList.get(0); final String orderCode = intOrder.getOrderCode(); assertEquals("Incorrect orderCode", ORDER_CODE, orderCode); assertEquals(merchantInfo.getMerchantCode(), result.getMerchantCode()); assertEquals(VERSION, result.getVersion()); final List<Object> orderElements = intOrder.getDescriptionOrAmountOrRiskOrOrderContentOrPaymentMethodMaskOrPaymentDetailsOrPayAsOrderOrShopperOrShippingAddressOrBillingAddressOrBranchSpecificExtensionOrRedirectPageAttributeOrPaymentMethodAttributeOrEchoDataOrStatementNarrativeOrHcgAdditionalDataOrThirdPartyDataOrResultURLOrShopperAdditionalDataOrApprovedAmountOrMandateOrAuthorisationAmountStatusOrDynamic3DSOrCreateTokenOrCreateTokenApprovalOrOrderLinesOrSubMerchantDataOrDynamicMCCOrDynamicInteractionTypeOrPrimeRoutingRequestOrRiskDataOrAdditional3DSDataOrExemptionOrShippingMethodOrProductSkuOrDeviceSessionOrInfo3DSecureOrSession(); final Session session = (Session) orderElements.get(1); assertEquals(SESSION_ID, session.getId()); }