cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Environment not set. Set environment using setter or use overloaded method to pass appropriate envir

Hi Team,

Anyone having this issue?
I'm just running the Java example code the perform an authorization and getting a null response.
Debugging it I see that controller object has no properly set the environment. The exact message is:
"Environment not set. Set environment using setter or use overloaded method to pass appropriate environment". What i did is, added anet-java-sdk-1.8.6.jar into my project lib and copied the below code into my java test program.

//Common code to set for all requests

ApiOperationBase.setEnvironment(Environment.SANDBOX);

MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);

String customerprofileId = "36374423" ;

CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
creditCard.setExpirationDate("0616");

PaymentType paymentType = new PaymentType();
paymentType.setCreditCard(creditCard);

TransactionRequestType requestInternal = new TransactionRequestType();
requestInternal.setTransactionType("authOnlyTransaction");
requestInternal.setPayment(paymentType);
requestInternal.setAmount(new BigDecimal(System.currentTimeMillis() % 100));

CustomerDataType customer = new CustomerDataType();
customer.setEmail(System.currentTimeMillis()+"@b.bla");
requestInternal.setCustomer(customer);

CreateTransactionRequest request = new CreateTransactionRequest();
request.setTransactionRequest(requestInternal);

CreateTransactionController controller = new CreateTransactionController(request);
controller.execute();

CreateTransactionResponse response = controller.getApiResponse();

CreateCustomerProfileFromTransactionRequest transaction_request = new CreateCustomerProfileFromTransactionRequest();
transaction_request.setTransId(response.getTransactionResponse().getTransId());
CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(transaction_request);
createProfileController.execute();
CreateCustomerProfileResponse customer_response = createProfileController.getApiResponse();

if(customer_response != null) {
System.out.println(transaction_request.getTransId());
}
}

xiniouer_0-1660715752311.png

 

 

 

xiniouer
Member
0 REPLIES 0