This example shows how to parse a Swiss Payments Code into a QrInvoice object.

import ch.codeblock.qrinvoice.QrInvoiceCodeParser;
import ch.codeblock.qrinvoice.model.ParseException;
import ch.codeblock.qrinvoice.model.QrInvoice;
import ch.codeblock.qrinvoice.model.validation.ValidationException;
import ch.codeblock.qrinvoice.model.validation.ValidationResult;

import java.math.BigDecimal;

// ...

final String spc = "SPC\n" +
        "...";

try {
    final QrInvoice qrInvoice = QrInvoiceCodeParser.create().parse(spc);

    // access QR-Invoice structure
    final BigDecimal amount = qrInvoice.getPaymentAmountInformation().getAmount();

    // ...
} catch (ParseException e) {
    // parsing exception handling
}

Instead of only parsing the SPC it is possible to validate it just by calling the parseAndValidate method.

try {
    final QrInvoice qrInvoice = QrInvoiceCodeParser.create().parseAndValidate(spc);

    // access QR-Invoice structure
    final BigDecimal amount = qrInvoice.getPaymentAmountInformation().getAmount();

    // ...
} catch (ParseException e) {
    // parsing exception handling
} catch (ValidationException e) {
    final ValidationResult validationResult = e.getValidationResult();
    // ...
}

Please refer to How to Validate a QrInvoice Object for more information on the ValidationResult