CreateTokenRequestTransformer implements ServiceRequestTransformer { @Override public PaymentService transform(final ServiceRequest request) throws WorldpayModelTransformationException { if (request == null) { throw new WorldpayModelTransformationException("Request provided to create token is invalid."); } final CreateTokenServiceRequest tokenRequest = (CreateTokenServiceRequest) request; final PaymentService paymentService = new PaymentService(); paymentService.setMerchantCode(tokenRequest.getMerchantInfo().getMerchantCode()); paymentService.setVersion(configurationService.getConfiguration().getString(WORLDPAY_CONFIG_VERSION)); final PaymentTokenCreate paymentTokenCreate = (PaymentTokenCreate) tokenRequest.getCardTokenRequest().transformToInternalModel(); final Submit submit = new Submit(); submit.getOrderOrOrderBatchOrShopperOrFuturePayAgreementOrMakeFuturePayPaymentOrIdentifyMeRequestOrPaymentTokenCreateOrChallenge().add(paymentTokenCreate); paymentService.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(submit); return paymentService; }  @Override PaymentService transform(final ServiceRequest request); @Required void setConfigurationService(final ConfigurationService configurationService);  }
@Test public void transformShouldRaiseErrorWhenRequestIsNull() throws WorldpayModelTransformationException { expectedException.expect(WorldpayModelTransformationException.class); expectedException.expectMessage("Request provided to create token is invalid."); testObj.transform(null); }
@Test public void transformShouldCreatePaymentServiceRequestUsingShopperToken() throws WorldpayModelTransformationException { final ServiceRequest serviceRequest = createTokenRequestForShopperToken(MERCHANT_INFO, AUTH_SHOPPER_ID, PAYMENT, TOKEN_REQUEST_SHOPPER); final PaymentService result = testObj.transform(serviceRequest); final Submit submit = (Submit) result.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().get(0); final PaymentTokenCreate paymentTokenCreate = (PaymentTokenCreate) submit.getOrderOrOrderBatchOrShopperOrFuturePayAgreementOrMakeFuturePayPaymentOrIdentifyMeRequestOrPaymentTokenCreateOrChallenge().get(0); final CSEDATA cseData = (CSEDATA) paymentTokenCreate.getPaymentInstrumentOrCSEDATA().get(0); assertEquals(MERCHANT_INFO.getMerchantCode(), result.getMerchantCode()); assertEquals(AUTH_SHOPPER_ID, paymentTokenCreate.getAuthenticatedShopperID()); assertEquals(TOKEN_REFERENCE, paymentTokenCreate.getCreateToken().getTokenEventReference()); assertEquals(TOKEN_REASON, paymentTokenCreate.getCreateToken().getTokenReason().getvalue()); assertEquals(ENCRYPTED_DATA, cseData.getEncryptedData()); assertThat(BILLING_ADDRESS.transformToInternalModel(), samePropertyValuesAs(cseData.getCardAddress().getAddress())); assertEquals("shopper", paymentTokenCreate.getCreateToken().getTokenScope()); }
@Test public void transformShouldCreatePaymentServiceRequestUsingMerchantToken() throws WorldpayModelTransformationException { final ServiceRequest serviceRequest = createTokenRequestForMerchantToken(MERCHANT_INFO, PAYMENT, TOKEN_REQUEST_MERCHANT); final PaymentService result = testObj.transform(serviceRequest); final Submit submit = (Submit) result.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().get(0); final PaymentTokenCreate paymentTokenCreate = (PaymentTokenCreate) submit.getOrderOrOrderBatchOrShopperOrFuturePayAgreementOrMakeFuturePayPaymentOrIdentifyMeRequestOrPaymentTokenCreateOrChallenge().get(0); final CSEDATA cseData = (CSEDATA) paymentTokenCreate.getPaymentInstrumentOrCSEDATA().get(0); assertEquals(MERCHANT_INFO.getMerchantCode(), result.getMerchantCode()); assertNull(paymentTokenCreate.getAuthenticatedShopperID()); assertEquals(TOKEN_REFERENCE, paymentTokenCreate.getCreateToken().getTokenEventReference()); assertEquals(TOKEN_REASON, paymentTokenCreate.getCreateToken().getTokenReason().getvalue()); assertEquals(ENCRYPTED_DATA, cseData.getEncryptedData()); assertThat(BILLING_ADDRESS.transformToInternalModel(), samePropertyValuesAs(cseData.getCardAddress().getAddress())); assertEquals("merchant", paymentTokenCreate.getCreateToken().getTokenScope()); }