|
| 1 | +# facturapi-java |
| 2 | + |
| 3 | +SDK oficial de Java para [Facturapi](https://www.facturapi.io). |
| 4 | + |
| 5 | +English: [README.md](README.md) |
| 6 | + |
| 7 | +[](https://github.com/facturapi/facturapi-java/actions/workflows/ci.yml) |
| 8 | +[](https://central.sonatype.com/artifact/io.facturapi/facturapi-java) |
| 9 | +[](https://openjdk.org/) |
| 10 | + |
| 11 | +## Requisitos |
| 12 | + |
| 13 | +- Java 11+ |
| 14 | +- Kotlin/JVM |
| 15 | +- Android 8.0 (API level 26) o superior |
| 16 | +- Spring Boot, Jakarta EE, Quarkus, Micronaut y otras apps JVM de servidor |
| 17 | + |
| 18 | +## Instalación |
| 19 | + |
| 20 | +Maven: |
| 21 | + |
| 22 | +```xml |
| 23 | +<dependency> |
| 24 | + <groupId>io.facturapi</groupId> |
| 25 | + <artifactId>facturapi-java</artifactId> |
| 26 | + <version>0.1.0</version> |
| 27 | +</dependency> |
| 28 | +``` |
| 29 | + |
| 30 | +Gradle: |
| 31 | + |
| 32 | +```gradle |
| 33 | +implementation("io.facturapi:facturapi-java:0.1.0") |
| 34 | +``` |
| 35 | + |
| 36 | +## Inicio rápido |
| 37 | + |
| 38 | +```java |
| 39 | +import io.facturapi.Facturapi; |
| 40 | +import java.util.Map; |
| 41 | + |
| 42 | +Facturapi facturapi = new Facturapi("sk_test_..."); |
| 43 | + |
| 44 | +var customer = facturapi.customers().create(Map.of( |
| 45 | + "legal_name", "Mi Empresa SA de CV", |
| 46 | + "tax_id", "XAXX010101000", |
| 47 | + "tax_system", "601", |
| 48 | + "email", "cliente@example.com" |
| 49 | +), null); |
| 50 | + |
| 51 | +var invoice = facturapi.invoices().create(Map.of( |
| 52 | + "customer", customer.getId(), |
| 53 | + "items", java.util.List.of(Map.of("quantity", 1, "product", "prod_123")) |
| 54 | +), null); |
| 55 | + |
| 56 | +System.out.println(invoice.getId()); |
| 57 | +``` |
| 58 | + |
| 59 | +## Subidas |
| 60 | + |
| 61 | +```java |
| 62 | +import java.io.File; |
| 63 | + |
| 64 | +var organization = facturapi.organizations().uploadLogo( |
| 65 | + "org_123", |
| 66 | + new File("logo.png") |
| 67 | +); |
| 68 | + |
| 69 | +var updated = facturapi.organizations().uploadCertificate( |
| 70 | + "org_123", |
| 71 | + new File("certificate.cer"), |
| 72 | + new File("certificate.key"), |
| 73 | + "secret" |
| 74 | +); |
| 75 | +``` |
| 76 | + |
| 77 | +## Errores |
| 78 | + |
| 79 | +```java |
| 80 | +import io.facturapi.FacturapiException; |
| 81 | + |
| 82 | +try { |
| 83 | + facturapi.customers().retrieve("cus_123"); |
| 84 | +} catch (FacturapiException e) { |
| 85 | + System.out.println(e.getMessage()); |
| 86 | + System.out.println(e.getStatusCode()); |
| 87 | + System.out.println(e.getErrorCode()); |
| 88 | + System.out.println(e.getErrorPath()); |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +## Diseño |
| 93 | + |
| 94 | +- Las entradas usan diccionarios JSON flexibles (`Map<String, Object>`). |
| 95 | +- Las salidas son modelos Java tipados (`Invoice`, `Customer`, `SearchResult<T>`, etc.). |
| 96 | +- Los errores exponen directamente los campos útiles del error del API en `FacturapiException`. |
| 97 | +- La autenticación usa `Authorization: Bearer <apiKey>`. |
| 98 | + |
| 99 | +## Configuración |
| 100 | + |
| 101 | +```java |
| 102 | +Facturapi facturapi = Facturapi.builder("sk_test_...") |
| 103 | + .apiVersion("v2") |
| 104 | + .timeout(java.time.Duration.ofSeconds(20)) |
| 105 | + .build(); |
| 106 | +``` |
0 commit comments