cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

When Charging Credit Card Get PKIX error path Exception

Hello,

 

I've been using Authorize.net for a long time now, and with Java I have come to a problem with the SDK.  When I use the following below code I get an error.  Please help.  What must I do to resolve the issue?

 

The response object returned is returning always null.  Please tell me how I can help.

---

response = controller.getApiResponse();
// Parse the response to determine results
if (response!=null) {

...

===

// Set the request to operate in either the sandbox or production environment
ApiOperationBase.setEnvironment(Environment.SANDBOX);


// Create object with merchant authentication details
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
merchantAuthenticationType.setName("6r46jMVd4X");
merchantAuthenticationType.setTransactionKey("932pRSL6Wq86ZxjM");

// Populate the payment data
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber(order.getCardnum());
creditCard.setExpirationDate(order.getExpire());
paymentType.setCreditCard(creditCard);

// Set email address (optional)
CustomerDataType customer = new CustomerDataType();
customer.setEmail(order.getCustomerEmail());

// Create the payment transaction object
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setPayment(paymentType);
txnRequest.setCustomer(customer);
txnRequest.setAmount(new BigDecimal(order.getAmount()).setScale(2, RoundingMode.CEILING));

// Create the API request and set the parameters for this specific request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
apiRequest.setMerchantAuthentication(merchantAuthenticationType);
apiRequest.setTransactionRequest(txnRequest);

// Call the controller
CreateTransactionController controller = new CreateTransactionController(apiRequest);
controller.execute();

// Get the response
CreateTransactionResponse response = new CreateTransactionResponse();
response = controller.getApiResponse();
// Parse the response to determine results
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.getMessages() != null) {
model.addAttribute("auth_response", "Credit card order processed successfully!");
System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
System.out.println("Response Code: " + result.getResponseCode());
System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
System.out.println("Auth Code: " + result.getAuthCode());

String hostName = "localhost:3320";
String dbName = "mydb7";
String userName = "root";
String passWord = "";

Connection conn = null;

PreparedStatement st1 = null;

try {

try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://" + hostName + "/" + dbName;
conn = DriverManager.getConnection(url, userName, passWord);
} catch(Exception e) {
e.printStackTrace();
}

st1 = conn.prepareStatement(
"insert into orders (id, order_num, order_date, amount, customer_name, customer_email, customer_phone, "
+ "customer_address, cardnum, cardname, expire, code) values (?,?,now(),?,?,?,?,?,?,?,?,?)");

st1.setString(1, order.getId()+"");
st1.setString(2, order.getOrderNum()+"");
st1.setString(3, order.getAmount()+"");
st1.setString(4, order.getCustomerName()+"");
st1.setString(5, order.getCustomerEmail()+"");
st1.setString(6, order.getCustomerPhone()+"");
st1.setString(7, order.getCustomerAddress()+"");
st1.setString(8, order.getCardnum()+"");
st1.setString(9, order.getCardname()+"");
st1.setString(10, order.getExpire()+"");
st1.setString(11, order.getCode()+"");

st1.execute();
st1.close();
conn.close();

} catch(SQLException sqle) {
sqle.printStackTrace();
}

List<CartLineInfo> lines = cartInfo.getCartLines();

for (CartLineInfo line1 : lines) {
OrderDetail detail = new OrderDetail();
detail.setId(UUID.randomUUID().toString());
detail.setOrder(order);
detail.setAmount(line1.getAmount());
detail.setPrice(line1.getProductInfo().getPrice());
detail.setQuanity(line1.getQuantity());

String code = line1.getProductInfo().getCode();
Product product = productDAO.findProduct(code);
detail.setProduct(product);

session.persist(detail);
}

// Set OrderNum for report.
// Set OrderNum d? thông báo cho ngu?i dùng.
cartInfo.setOrderNum(orderNum);

} else {
model.addAttribute("auth_response", "Credit card order did not processed successfully!");
System.out.println("Failed Transaction.");
if (response.getTransactionResponse().getErrors() != null) {
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
}
}
} else {
System.out.println("Failed Transaction.");
model.addAttribute("auth_response", "Credit card order did not processed successfully!");
if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
} else {
System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
}
}
} else {
// Display the error code and message when response is null
ANetApiResponse errorResponse = controller.getErrorResponse();
model.addAttribute("auth_response", "Credit card order did not processed successfully!");
System.out.println("Failed to get response");
System.out.println("sdfasdfa");
if (!errorResponse.getMessages().getMessage().isEmpty()) {
System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
}
}

===

 

 

dhcho881
Member
Who Me Too'd this topic