We encourage to use the QrInvoiceBuilder for creating QrInvoice instances, as it guarantees proper object creation and implicitly performs validation. The builder supports two styles as you can see in the next two code examples. Choose whichever you like better.

Fully Fluent Style Using Lambdas

import ch.codeblock.qrinvoice.model.QrInvoice;
import ch.codeblock.qrinvoice.model.builder.QrInvoiceBuilder;
import ch.codeblock.qrinvoice.model.validation.ValidationException;
import ch.codeblock.qrinvoice.model.validation.ValidationResult;

import java.util.Arrays;

// ...
try {
    final QrInvoice qrInvoice = QrInvoiceBuilder
    .create()
    .creditorIBAN("CH44 3199 9123 0008 8901 2")
    .paymentAmountInformation(p -> p
        .chf(1949.75)
    )
    .creditor(c -> c
        .structuredAddress()
        .name("Robert Schneider AG")
        .streetName("Rue du Lac")
        .houseNumber("1268")
        .postalCode("2501")
        .city("Biel")
        .country("CH")
    )
    .ultimateDebtor(d -> d
        .structuredAddress()
        .name("Pia-Maria Rutschmann-Schnyder")
        .streetName("Grosse Marktgasse")
        .houseNumber("28")
        .postalCode("9400")
        .city("Rorschach")
        .country("CH")
    )
    .paymentReference(r -> r
        .qrReference("210000000003139471430009017")
    )
    .additionalInformation(a -> a
        .unstructuredMessage("Instruction of 03.04.2019")
        .billInformation("//S1/10/10201409/11/190512/20/1400.000-53/30/106017086/31/180508/32/7.7/40/2:10;0:30")
    )
    .alternativeSchemeParameters(Arrays.asList(
        "Name AV1: UV;UltraPay005;12345",
        "Name AV2: XY;XYService;54321"
    ))
    .build();
} catch (ValidationException validationException) {
    final ValidationResult validationResult = validationException.getValidationResult();
    // handle exception...
}

For more details on the ValidationResult see How to validate a QrInvoice object

Semi-Fluent Style

import ch.codeblock.qrinvoice.model.QrInvoice;
import ch.codeblock.qrinvoice.model.builder.QrInvoiceBuilder;
import ch.codeblock.qrinvoice.model.validation.ValidationException;
import ch.codeblock.qrinvoice.model.validation.ValidationResult;

import java.util.Arrays;

// ..
try {
    final QrInvoiceBuilder qrInvoiceBuilder = QrInvoiceBuilder.create()
        .creditorIBAN("CH4431999123000889012");

    qrInvoiceBuilder.paymentAmountInformation()
        .chf(1949.75);

    qrInvoiceBuilder.creditor()
        .structuredAddress()
        .name("Robert Schneider AG")
        .streetName("Rue du Lac")
        .houseNumber("1268")
        .postalCode("2501")
        .city("Biel")
        .country("CH");
    qrInvoiceBuilder.ultimateDebtor()
        .structuredAddress()
        .name("Pia-Maria Rutschmann-Schnyder")
        .streetName("Grosse Marktgasse")
        .houseNumber("28")
        .postalCode("9400")
        .city("Rorschach")
        .country("CH");

    qrInvoiceBuilder.paymentReference()
        .qrReference("210000000003139471430009017");

    qrInvoiceBuilder.additionalInformation()
        .unstructuredMessage("Instruction of 03.04.2019")
        .billInformation("//S1/10/10201409/11/190512/20/1400.000-53/30/106017086/31/180508/32/7.7/40/2:10;0:30");

    qrInvoiceBuilder.alternativeSchemeParameters(Arrays.asList(
         "Name AV1: UV;UltraPay005;12345",
         "Name AV2: XY;XYService;54321"
     ));

    final QrInvoice qrInvoice = qrInvoiceBuilder.build();
} catch (ValidationException validationException) {
    final ValidationResult validationResult = validationException.getValidationResult();
    // handle exception...
}