cancel
Showing results for 
Search instead for 
Did you mean: 

Getting exception as 'peer not authenticated' while creating recurring billing

I am getting exception while create a new recurring billing with below Java code. Same code was worked well one month ago

 

public static void subscriptionPayment(String apiLoginId, String transactionKey) 
{
	try{
			SimpleDateFormat sDF = new SimpleDateFormat("yyyy-MM-dd");
			Calendar d = Calendar.getInstance();			    
		    		
			SimpleDateFormat eDF = new SimpleDateFormat("MM/yyyy");
			Date expireDate = eDF.parse("12/2019");
			eDF.applyPattern("yyyy-MM");
			
			Merchant merchant ;
			
			merchant = Merchant.createMerchant(Environment.SANDBOX, apiLoginId, transactionKey);
			
			String planFOR = "";
			PaymentSchedule new_schedule = PaymentSchedule.createPaymentSchedule();			    
		    
			new_schedule.setIntervalLength(1);
	    	d.add(Calendar.MONTH, 1);
		    planFOR = "MONTHLY";
		    
		    new_schedule.setSubscriptionUnit(SubscriptionUnitType.MONTHS);
		    new_schedule.setStartDate(sDF.format(d.getTime()));
		    new_schedule.setTotalOccurrences(9999);
		    new_schedule.setTrialOccurrences(0);
		    			    
		    // Create a new credit card
		    CreditCard credit_card = CreditCard.createCreditCard();
		    credit_card.setCreditCardNumber("4111111111111111"); 
		    credit_card.setExpirationDate(eDF.format(expireDate));
		    credit_card.setCardCode("656");

		    // Create a billing info
		    Address billing_info = Address.createAddress();
		    
	    	billing_info.setLastName("Miller");
	    	billing_info.setFirstName("David");
		    
		    billing_info.setCompany("ABC");
		    billing_info.setAddress("Address");
		    billing_info.setCity("City");
		    billing_info.setCountry("Country");
		    billing_info.setFaxNumber("23654565");
		    billing_info.setPhoneNumber("0123456789");
		    billing_info.setState("State");
		    billing_info.setZipPostalCode("21254");
		    
		    // Create a customer and specify billing info
		    Customer customer = Customer.createCustomer();
		    customer.setBillTo(billing_info);
		    customer.setEmail("davidmiller@gmail.com");			    
		    
		    // Create a subscription and specify payment, schedule and customer
		    //
		    Subscription subscription = Subscription.createSubscription();
		    subscription.setPayment(Payment.createPayment(credit_card));
		    subscription.setSchedule(new_schedule);
		    subscription.setCustomer(customer);
	        subscription.setAmount(new BigDecimal(9));
		    subscription.setTrialAmount(Transaction.ZERO_AMOUNT);
		    subscription.setRefId("REF:" + System.currentTimeMillis());
		    subscription.setName("User Subscription");
		    Order order = Order.createOrder();
		    order.setDescription(subscription.getName());
		    subscription.setOrder(order);
		    
		    net.authorize.arb.Transaction transaction =
		        merchant.createARBTransaction(TransactionType.CREATE_SUBSCRIPTION,
		            subscription);
		    
		    Result<Transaction> result =(Result<Transaction>) merchant.postTransaction(transaction);
				    
		    for(int i = 0; i < result.getMessages().size(); i++){
		    	
		      Message message = (Message)result.getMessages().get(i);
		      if(message.getCode().equals("I00001")){
		      
		    }
	    }
	}
	catch(Exception ex){
	}
}



Below error getting in console while executing above code. Help me to solve the issue.

2017-06-02 18:07:45 HttpClient [INFO] Use Proxy: 'false'
2017-06-02 18:07:45 HttpCallTask [ERROR] Http request execute failed: 'peer not authenticated'
2017-06-02 18:07:45 HttpCallTask [WARN] Adding ErrorMessage: Code: 'javax.net.ssl.SSLPeerUnverifiedException', Text: 'peer not authenticated'
2017-06-02 18:07:45 ApiOperationBase [ERROR] Invalid response:'net.authorize.api.contract.v1.ANetApiResponse@a1e932e'
2017-06-02 18:07:46 HttpClient [WARN] Exception getting response: 'peer not authenticated': 'null', '[sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:421), org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128), org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:397), org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148), org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149), org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121), org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573), org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425), org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820), org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754), org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732), net.authorize.util.HttpClient.executeXML(HttpClient.java:245), net.authorize.Merchant.postTransaction(Merchant.java:290), PaymentTest.subscriptionPayment(PaymentTest.java:224), PaymentTest.main(PaymentTest.java:146)]'

davidarul
Member
7 REPLIES 7

You could

try {
SSLContext ctx = SSLContext.getInstance("TLSv1.2");
ctx.init(null, null, null);
SSLContext.setDefault(ctx);
} catch (Exception e) {
System.out.println(e.getMessage());
}

Or

final SSLContext ctx = SSLContext.getInstance("TLSv1.2");
ctx.init(null,null, new java.security.SecureRandom());
final SSLSocketFactory socketFactory = ctx.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
Powered by NexWebSites.com -
Certified Authorize.net developers
NexusSoftware
Trusted Contributor

Added this code in my method still getting same issue

Ensure your server has a valid non-expired SSL Certificate.

 

One way to diagnose, is to use Wireshark to capture the network traffic from your application.  Once the traffic is captured, click Analyze -> Decode As -> Transport, select the port and then select SSL, apply and save the settings. The captured traffic will be shown as SSL. Look for the response of the "client hello" message in the captured traffic, this is where the SSL/TLS handshake is done.

Powered by NexWebSites.com -
Certified Authorize.net developers

How can I use dummy ssl for localhost.

 

Could you give me some suggession?

davidarul
Member

A self-signed certificate would be the way to go for localhost. By the way, an easy to use tool for this purpose would be: Zero SSL, just enter your non-existent domain or IP into the top field.

Powered by NexWebSites.com -
Certified Authorize.net developers

Hi,

 

I upgraded to TSL1.2 and still getting the same issue.

 

I am used anet-java-sdk 1.9.3 and Java 1.7

 

Getting error in net.authorize.util.HttpClient file. Below line getting exception.

 

 

Hello, was there any resolution to this issue?