manuelbl / SwissQRBill

Java library for Swiss QR bill payment slips (aka QR-Rechnung)
https://www.codecrete.net/qrbill
MIT License
157 stars 38 forks source link
invoice java qr-code swiss-qr-bill

Swiss QR Bill for Java

javadoc

Open-source Java library to generate and decode Swiss QR bills (jointly developed with the .NET version).

Try it yourself and create a QR bill. The code for this demonstration (React UI and RESTful service) can be found on GitHub as well.

This library implements version 2.2 and 2.3 of the Swiss Implementation Guidelines QR-bill from November 20, 2023, and Swico Syntax Definition (S1) from November 23, 2018.

Introduction

The Swiss QR bill is the QR code based payment format that started on 30 June, 2020. The payment slip is sent electronically or presented online in most cases. It can still be printed at the bottom of an invoice or added to the invoice on a separate sheet. The payer scans the QR code with his/her mobile banking app to initiate the payment and then just needs to confirm it.

If the invoicing party adds structured bill information (VAT rates, payment conditions etc.) to the QR bill, the payer can automate the booking in accounts payable. The invoicing party can also automate the accounts receivable processing as the payment includes all relevant data including a reference number. The Swiss QR bill is convenient for the payer and payee.

QR Bill

More examples can be found in the Wiki

Features

The Swiss QR bill library:

Getting started

The QR bill generator is available at Maven Central. To use it, just add it to your Maven or Gradle project.

If you are using Maven, add the below dependency to your pom.xml:

<dependency>
    <groupId>net.codecrete.qrbill</groupId>
    <artifactId>qrbill-generator</artifactId>
    <version>[3.3.1,3.999999]</version>
</dependency>

If you are using Gradle, add the below dependency to your build.gradle file:

compile group: 'net.codecrete.qrbill', name: 'qrbill-generator', version: '3.3.1+'

To generate a QR bill, you first fill in the Bill data structure and then call QRBill.generate:

package net.codecrete.qrbill.examples;

import net.codecrete.qrbill.generator.Address;
import net.codecrete.qrbill.generator.Bill;
import net.codecrete.qrbill.generator.QRBill;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class QRBillExample {

    public static void main(String[] args) {

        // Setup bill
        Bill bill = new Bill();
        bill.setAccount("CH4431999123000889012");
        bill.setAmountFromDouble(199.95);
        bill.setCurrency("CHF");

        // Set creditor
        Address creditor = new Address();
        creditor.setName("Robert Schneider AG");
        creditor.setStreet("Rue du Lac");
        creditor.setHouseNo("1268/2/22");
        creditor.setPostalCode("2501");
        creditor.setTown("Biel");
        creditor.setCountryCode("CH");
        bill.setCreditor(creditor);

        // more bill data
        bill.setReference("210000000003139471430009017");
        bill.setUnstructuredMessage("Abonnement für 2020");

        // Set debtor
        Address debtor = new Address();
        debtor.setName("Pia-Maria Rutschmann-Schnyder");
        debtor.setStreet("Grosse Marktgasse");
        debtor.setHouseNo("28");
        debtor.setPostalCode("9400");
        debtor.setTown("Rorschach");
        debtor.setCountryCode("CH");
        bill.setDebtor(debtor);

        // Set output format
        BillFormat format = new BillFormat();
        format.setGraphicsFormat(GraphicsFormat.SVG);
        format.setOutputSize(OutputSize.QR_BILL_ONLY);
        format.setLanguage(Language.DE);
        bill.setFormat(format);

        // Generate QR bill
        byte[] svg = QRBill.generate(bill);

        // Save QR bill
        Path path = Paths.get("qrbill.svg");
        try {
            Files.write(path, svg);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        System.out.println("QR bill saved at " + path.toAbsolutePath());
    }
}

More code examples can be found in the examples directory.

API Documention

Javadoc API documentation:

More information

More information can be found in the Wiki. It's the joint Wiki for the .NET and the Java version.

Changes effective November 21, 2025

On November 21, 2025, the QR bill specification 2.3 and further changes in the Swiss payment standards will become effective. The library is ready for these changes:

If the extended character set is used, it is no longer possible to use the PDF standard font Helvectica for the text as it is restricted to the smaller WinANSI character set. This library will automatically switch to the Liberation Sans font and embed the font subset actually used. SVG and PNG ouput can continue to use other fonts.

Font license

The library includes the Liberation Sans font (regular and bold face). It is made available free of charge by Goolge and Red Hat under the SIL Open Font License, Version 1.1. You will likely need to add their copyright and license information to your product. See the license for details.

QR Code

For the generation of the QR code itself, Nayuki's QR code generator is used.

Other programming languages

A .NET version of this library is also available. If you are looking for a library for yet another programming language or for a library with professional services, you might want to check out Services & Tools on MoneyToday.ch.