1
I am deploying your java checkout solution on my local machine for testing purposes. The code I am using is available in the developer at Cielo.
Follows the code:
public String envia() {
String responseLine = "";
try {
String json = "{"
+ " \"OrderNumber\": \"12344\","
+ " \"SoftDescriptor\": \"Nome que aparecerá na fatura\","
+ " \"Cart\": {"
+ " \"Discount\": {"
+ " \"Type\": \"Percent\","
+ " \"Value\": 10"
+ " },"
+ " \"Items\": ["
+ " {"
+ " \"Name\": \"Nome do produto\","
+ " \"Description\": \"Descrição do produto\","
+ " \"UnitPrice\": 100,"
+ " \"Quantity\": 2,"
+ " \"Type\": \"Asset\","
+ " \"Sku\": \"Sku do item no carrinho\","
+ " \"Weight\": 200"
+ " }"
+ " ]"
+ " },"
+ " \"Shipping\": {"
+ " \"Type\": \"Correios\","
+ " \"SourceZipCode\": \"14400000\","
+ " \"TargetZipCode\": \"11000000\","
+ " \"Address\": {"
+ " \"Street\": \"Endereço de entrega\","
+ " \"Number\": \"123\","
+ " \"Complement\": \"\","
+ " \"District\": \"Bairro da entrega\","
+ " \"City\": \"Cidade de entrega\","
+ " \"State\": \"SP\""
+ " },"
+ " \"Services\": ["
+ " {"
+ " \"Name\": \"Serviço de frete\","
+ " \"Price\": 123,"
+ " \"Deadline\": 15"
+ " }"
+ " ]"
+ " },"
+ " \"Payment\": {"
+ " \"BoletoDiscount\": 0,"
+ " \"DebitDiscount\": 0,"
+ " \"RecurrentPayment\": {"
+ " \"Interval\": \"Monthly\","
+ " \"EndDate\": \"2015-12-31\""
+ " }"
+ " },"
+ " \"Customer\": {"
+ " \"Identity\": 11111111111,"
+ " \"FullName\": \"Fulano Comprador da Silva\","
+ " \"Email\": \"[email protected]\","
+ " \"Phone\": \"11999999999\""
+ " },"
+ " \"Options\": {"
+ " \"AntifraudEnabled\": false"
+ " }"
+ "}";
BufferedReader bufferedReader;
URL url = new URL("https://cieloecommerce.cielo.com.br/api/public/v1/orders");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.addRequestProperty("MerchantId", "xxxx-xxxx-xxxx-xxxx-xxxx");
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setDoOutput(true);
DataOutputStream jsonRequest = new DataOutputStream(
connection.getOutputStream());
jsonRequest.writeBytes(json);
jsonRequest.flush();
jsonRequest.close();
bufferedReader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
StringBuffer jsonResponse = new StringBuffer();
while ((responseLine = bufferedReader.readLine()) != null) {
jsonResponse.append(responseLine);
}
bufferedReader.close();
connection.disconnect();
} catch (Exception ex) {
return ex.getMessage();
}
return responseLine;
}
When executing the code the following error is returned:
sun.security.Validator.Validatorexception: PKIX path building failed: sun.security.Provider.certpath.Suncertpathbuilderexception: Unable to find Valid Certification path to requested target
I make it clear that I have imported the certificate ecommerce.cielo.com.br
to the browser as indicated. Also, I imported the other certificates, Raiz.crt
and Intermediaria.crt
, besides the ecommerce.cielo.com.br.crt
to my Truststore with the following commands:
keytool -keystore cacerts -import -alias ecommerce -file ecommerce.cielo.com.br.crt -trustcacerts
keytool -keystore cacerts -import -alias intermediaria -file Intermediaria.crt -trustcacerts
keytool -keystore cacerts -import -alias raiz -file Raiz.crt -trustcacerts
What can I do to remedy the error already described?