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.9.0.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("my apiloginid");
merchantAuthenticationType.setTransactionKey(" my transaction key");
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
// Populate the payment data
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("5424000000000015");
creditCard.setExpirationDate("1220");
paymentType.setCreditCard(creditCard);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setPayment(paymentType);
txnRequest.setAmount(new BigDecimal(10.00));
// Make the API Request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
apiRequest.setTransactionRequest(txnRequest);
CreateTransactionController controller = new CreateTransactionController(apiRequest);
controller.getErrorResponse();
CreateTransactionResponse response = controller.getApiResponse();
logger.info("response from authorized.net"+ response);
if (response!=null) {
// If API Response is ok, go ahead and check the transaction response
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
TransactionResponse result = response.getTransactionResponse();
if (result.getResponseCode().equals("1")) {
logger.info(result.getResponseCode());
logger.info("Successful Credit Card Transaction");
logger.info(result.getAuthCode());
logger.info(result.getTransId());
}
else
{
logger.info("Failed Transaction"+result.getResponseCode());
}
}
else
{
logger.info("Failed Transaction: "+response.getMessages().getResultCode());
}
}
Note:
I'm setting the environment as the example, didn't change anything:
ApiOperationBase.setEnvironment(Environment.SANDBOX);
10-04-2016 06:02 AM