- parse
Invoice
from Json file - make
Invoice
signature and save it as anEnvelop
- save
Invoice
to file - load and save JWK keys from/to file
Invoice
extract fromEnvelop
- signature verification when extract document from
Envelop
(only one signature is supported now)
- The only possible type of document that can be placed inside a signed Envelope is an Invoice. This decision is dictated by the simplification of implementation at this stage of the project.
- There is no tax calculation logic
- and much, much more — so help is more than welcome
public class Main {
public static void main(String[] args) {
Gobl gobl = new Gobl();
Invoice invoice = gobl.parseInvoice("src/test/resources/invoice.json");
System.out.println(invoice);
}
}
public class Main {
public static void main(String[] args) {
Gobl gobl = new Gobl();
KeySupport keySupport = new KeySupport();
val keys = keySupport.generate();
val envelope = gobl.signInvoice("src/test/resources/invoice.json", keys.privateKey(), UUID.randomUUID());
System.out.println(envelope);
}
}
public class Main {
public static void main(String[] args) {
Gobl gobl = new Gobl();
KeySupport keySupport = new KeySupport();
Key key = keySupport.loadKey(Path.of("src/test/resources/id_es256.jwk"));
val envelope = gobl.signInvoice("src/test/resources/invoice.json", (ECPrivateKey) key, UUID.randomUUID());
System.out.println(envelope);
}
}
try{
File file = new File("src/test/resources/invoice-signed.json");
KeySupport keySupport = new KeySupport();
Key publicKey = keySupport.loadKey(Path.of("src/test/resources/id_es256.pub.jwk"));
Invoice invoice = gobl.extractFromEnvelope(file, Invoice.class, publicKey);
// validation OK
System.out.println(invoice);
} catch (SignatureException ex) {
// validation failed
}
val invoice = new Invoice()
.withCode("standard")
.withIssueDate("2024-01-01")
.withCustomer(new Party()
.withName("Company INC")
.withAddresses(List.of(new Address()
.withCountry("Poland")
.withCode("05-092")
.withStreet("Warszawska")))
.withTaxId(new Identity()
.withCode("2222222222")
.withCountry("PL"))
).withCustomer(new Party()
.withName("Customer sp. z o.o.")
.withAddresses(List.of(new Address()
.withCountry("Poland")
.withCode("05-092")
.withStreet("Warszawska")))
.withTaxId(new Identity()
.withCode("1111111111")
.withCountry("PL"))
).withLines(List.of(new Line()
.withI(1)
.withItem(new Item()
.withName("Myszka")
.withCurrency("PLN")
.withPrice("100"))));
Gobl gobl = new Gobl();
gobl.saveInvoice(invoice, System.out);
<dependency>
<groupId>io.alapierre.gobl</groupId>
<artifactId>gobl-core</artifactId>
<version>0.0.2</version>
</dependency>
The project can be built on JDK17+.
Building the API client library requires:
- Java 17+
- Maven