/* Agregue este código a su POM
***** CONTENIDO DEL POM *****
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
// Clase donde se ejecuta el request
<mainClass>Program</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
// Agregar dependencia de UniRest para manejar los request
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.1.00</version>
</dependency>
// Agregar dependencia de GSON para serializar los objetos de Java a JSON
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
*/
// **** Clase donde se ejecuta el request ****
import com.google.gson.*;
import kong.unirest.*;
/*
* - Enviar una nota de ajuste en modo producción
* - Añada las dependencias de UniRest y GSON a su POM como se muestra en el código de la parte superior
*/
public class Program {
public static void main(String[] args) {
JsonObject isvNote = new JsonObject();
isvNote.addProperty("format", "Estandar");
isvNote.addProperty("concept", "1");
isvNote.addProperty("consecutive", 8);
isvNote.addProperty("externalNumber", "54554");
isvNote.addProperty("currencyCode", "COP");
isvNote.addProperty("currencyRate", 0);
isvNote.addProperty("date", "2020-1-20");
isvNote.addProperty("dateStart", "2020-1-20");
isvNote.addProperty("dateEnd", "2020-1-25");
isvNote.addProperty("supportDocumentPrefix", "asd");
isvNote.addProperty("supportDocumentConsecutive", 990004331);
isvNote.addProperty("supportDocumentCuds", "cufe");
isvNote.addProperty("supportDocumentDate", "2020-1-18");
JsonObject branchObj = new JsonObject();
branchObj.addProperty("name", "");
branchObj.addProperty("address", "");
branchObj.addProperty("phone", "");
branchObj.addProperty("countryCode", "");
branchObj.addProperty("countryName", "");
branchObj.addProperty("departmentCode", "");
branchObj.addProperty("departmentName", "");
branchObj.addProperty("cityCode", "");
branchObj.addProperty("cityName", "");
isvNote.add("branch", branchObj);
JsonObject supplierObj = new JsonObject();
supplierObj.addProperty("companyName", "Customer");
supplierObj.addProperty("personType", "1");
supplierObj.addProperty("firstName", "Customer");
supplierObj.addProperty("lastName", "Customer");
supplierObj.addProperty("identification", "000000001");
supplierObj.addProperty("digitCheck", "8");
supplierObj.addProperty("identificationTypeCode", "13");
supplierObj.addProperty("email", "");
supplierObj.addProperty("phone", "0000001");
supplierObj.addProperty("merchantRegistration", "");
supplierObj.addProperty("responsibleFor", "ZZ");
supplierObj.addProperty("responsibilities", "R-99-PN");
supplierObj.addProperty("economicActivities", "2817;3092");
supplierObj.addProperty("billingAddress", "KR con Calle");
supplierObj.addProperty("billingCountryName", "Colombia");
supplierObj.addProperty("billingCountryCode", "CO");
supplierObj.addProperty("billingRegionName", "Cundinamarca");
supplierObj.addProperty("billingRegionCode", "25");
supplierObj.addProperty("billingCityName", "Chipaque");
supplierObj.addProperty("billingCityCode", "25178");
supplierObj.addProperty("billingPostalCode", "");
supplierObj.addProperty("billingNeighborhood", "");
supplierObj.addProperty("billingPhone", "");
supplierObj.addProperty("billingContactName", "");
isvNote.add("customer", customerObj);
JsonArray noteDetailsArr = new JsonArray();
JsonObject noteDetailsObj = new JsonObject();
noteDetailsObj.addProperty("standardType", "");
noteDetailsObj.addProperty("standardCode", "");
noteDetailsObj.addProperty("itemCode", "0001");
noteDetailsObj.addProperty("itemName", "Item");
noteDetailsObj.addProperty("itemModel", "");
noteDetailsObj.addProperty("description", "Item prueba");
noteDetailsObj.addProperty("brandName", "");
noteDetailsObj.addProperty("itemCodeSupplier", "");
noteDetailsObj.addProperty("isPresent", false);
noteDetailsObj.addProperty("unitMeasurementCode", "");
noteDetailsObj.addProperty("unitMeasurementName", "");
noteDetailsObj.addProperty("price", 25);
noteDetailsObj.addProperty("quantity", 2);
noteDetailsArr.add(noteDetailsObj);
JsonArray discountsArr = new JsonArray();
JsonObject discountsObj = new JsonObject();
discountsObj.addProperty("name", "");
discountsObj.addProperty("type", "V");
discountsObj.addProperty("rate", 1);
discountsObj.addProperty("amount", 1);
discountsArr.add(discountsObj);
noteDetailsObj.add("discounts", discountsArr);
JsonArray chargesArr = new JsonArray();
JsonObject chargesObj = new JsonObject();
chargesObj.addProperty("name", "");
chargesObj.addProperty("type", "V");
chargesObj.addProperty("rate", 10);
chargesObj.addProperty("amount", 10);
chargesArr.add(chargesObj);
noteDetailsObj.add("charges", chargesArr);
JsonArray taxesArr = new JsonArray();
JsonObject taxesObj = new JsonObject();
taxesObj.addProperty("name", "Iva");
taxesObj.addProperty("code", "01");
taxesObj.addProperty("type", "P");
taxesObj.addProperty("rate", 19);
taxesObj.addProperty("amount", 6.46);
taxesArr.add(taxesObj);
noteDetailsObj.add("taxes", taxesArr);
JsonArray withholdingsArr = new JsonArray();
JsonObject withholdingsObj = new JsonObject();
withholdingsObj.addProperty("name", "ReteFuente");
withholdingsObj.addProperty("code", "06");
withholdingsObj.addProperty("type", "P");
withholdingsObj.addProperty("rate", 10);
withholdingsObj.addProperty("amount", 3.4);
withholdingsArr.add(withholdingsObj);
noteDetailsObj.add("withholdings", withholdingsArr);
JsonObject isvMandanteObj = new JsonObject();
isvMandanteObj.addProperty("name", "Mandante");
isvMandanteObj.addProperty("identification", "0014");
isvMandanteObj.addProperty("digitCheck", "8");
isvMandanteObj.addProperty("identificationTypeCode", "13");
noteDetailsObj.add("isvMandante", isvMandanteObj);
noteDetailsObj.add("noteDetails", noteDetailsArr);
JsonObject totals = new JsonObject();
totals.addProperty("amount", 68);
totals.addProperty("amount", 68);
totals.addProperty("prepaymentAmount", 0);
isvNote.add("totals", totals);
JsonArray isvNoteDiscountsArr = new JsonArray();
JsonObject isvNoteDiscountsObj = new JsonObject();
isvNoteDiscountsObj.addProperty("type", "");
isvNoteDiscountsObj.addProperty("rate", 0);
isvNoteDiscountsObj.addProperty("amount", 0);
isvNoteDiscountsArr .add(isvNoteDiscountsObj);
isvNote.add("discounts", isvNoteDiscountsArr );
JsonArray isvNoteChargesArr = new JsonArray();
JsonObject isvNoteChargesObj = new JsonObject();
isvNoteChargesObj.addProperty("type", "");
isvNoteChargesObj.addProperty("rate", 0);
isvNoteChargesObj.addProperty("amount", 0);
isvNoteChargesArr.add(isvNoteChargesObj );
isvNoteChargesObj.add("charges", isvNoteChargesArr);
// Realizar request por metodo POST
HttpRequestWithBody request = Unirest.post("https://isv.aliaddo.net/api/v1/public/documents/support");
// Adicionar cabeceras de autenticación con token Bearer generado en el panel izquierdo
request.header("x-api-key", "{{x-api-key}}");
// Tipo de requerimiento formato json
request.header("content-type", "application/json");
request.header("cache-control", "no-cache");
request.header("accept", "application/json");
// Añadir el objeto de nota de ajuste
request.body(isvNote).asJson()
// Manejar respuesta o error si hay alguno
.ifSuccess(response -> System.out.println("Response: " + "status -> " + response.getStatus() + " Body -> " + response.getBody()))
.ifFailure(response -> {
System.out.println("Oh No! Status " + response.getStatus());
response.getParsingError().ifPresent(e -> {
System.out.println("Parsing Exception: " + e);
System.out.println("Original body: " + e.getOriginalBody());
});
});
}
}