• Residence: Bosnia & Herzegovina
  • City: Bijeljina
  • Age: 26
DOWNLOAD CV
Back to Blog

Generating Swiss QR-Bills (ISO 20022) in Node.js

· Đorđije Lazarević · 3 min read

If you invoice customers in Switzerland, your invoices need a QR-bill: the payment part at the bottom of the page that Swiss banking apps scan. It replaced the old orange and red payment slips in 2022. Getting the format almost right is easy; getting it accepted by every bank requires a few rules that are not obvious.

What a QR-bill contains

The payment part is a 210 × 105 mm area at the bottom of an A4 page, with a receipt on the left and the payment section with the Swiss QR Code on the right. The QR code carries structured data: creditor account and address, amount and currency (CHF or EUR), the debtor, and a reference.

The three reference types

AccountReferenceUse it when
QR-IBANQR reference (27 digits, check digit)You want automatic matching of payments to invoices
Regular IBANCreditor Reference (ISO 11649, starts with RF)Your bank does not offer a QR-IBAN, or you need an international reference
Regular IBANNoneSimple cases; matching is manual

The most common error is mixing them: a QR-IBAN always requires a QR reference, and a QR reference only works with a QR-IBAN. You can recognise a QR-IBAN by its institution ID (digits 5 to 9) in the range 30000 to 31999.

Structured addresses only

Since November 2025, Swiss banks accept only structured addresses in QR-bills: street and building number in their own fields, postal code and town in theirs. If your customer data has a single address line, split it before you generate bills, and validate it when customers enter it.

Generating the PDF

The open source swissqrbill library handles the layout, fonts and QR code, and works with PDFKit. This example produces a valid bill with the official sample data:

import PDFDocument from 'pdfkit';
import { createWriteStream } from 'node:fs';
import { SwissQRBill } from 'swissqrbill/pdf';

const data = {
  currency: 'CHF' as const,
  amount: 1250.5,
  creditor: {
    account: 'CH44 3199 9123 0008 8901 2', // QR-IBAN
    name: 'Example AG',
    address: 'Bahnhofstrasse',
    buildingNumber: 7,
    zip: 8001,
    city: 'Zürich',
    country: 'CH',
  },
  reference: '21 00000 00003 13947 14300 09017', // QR reference
  debtor: {
    name: 'Max Muster',
    address: 'Musterstrasse',
    buildingNumber: 1,
    zip: 3000,
    city: 'Bern',
    country: 'CH',
  },
  message: 'Invoice 2026-0142',
};

const pdf = new PDFDocument({ size: 'A4' });
pdf.pipe(createWriteStream('invoice.pdf'));
pdf.fontSize(20).text('Invoice 2026-0142', 50, 50);
// ...the rest of the invoice...
new SwissQRBill(data).attachTo(pdf);
pdf.end();

The library validates the data and throws on invalid input, so wrap generation in your invoice service and surface the error to whoever entered the data. It can also produce an SVG (swissqrbill/svg) if you render invoices in the browser.

Creating QR references from invoice numbers

A QR reference is 26 digits plus a check digit calculated with the recursive modulo 10 algorithm. I build the 26 digits from a customer or invoice number, padded with zeros:

const TABLE = [0, 9, 4, 6, 8, 2, 7, 1, 3, 5];

export function qrReferenceCheckDigit(digits: string): number {
  let carry = 0;
  for (const digit of digits) carry = TABLE[(carry + Number(digit)) % 10];
  return (10 - carry) % 10;
}

export function qrReference(invoiceNumber: number): string {
  const base = String(invoiceNumber).padStart(26, '0');
  return base + qrReferenceCheckDigit(base);
}

qrReferenceCheckDigit('21000000000313947143000901'); // 7

The last line checks the function against the official example reference used above. When the payment arrives, the bank returns the same reference in the camt.054 file, and your system matches it to the invoice without anyone reading a bank statement.

Before you go live

  • Print a bill and scan it with two or three Swiss banking apps. This catches layout and data issues that schema validation does not.
  • Run a few bills through a QR-bill validation tool (your bank or SIX offers one).
  • If bills are printed, keep the perforation or the scissors symbol; if they are sent as PDF, the library handles the separation lines.
  • Store the reference with the invoice, so incoming payments can be reconciled automatically.

I implemented QR-bill invoicing on an enterprise B2B/B2C e-commerce platform built with NestJS, where QR-bill invoicing is part of the order flow for Swiss customers.

Planning a React Native app?

I take on freelance projects for clients across DACH and the EU: React and Next.js web apps, React Native mobile apps and NestJS backends, from architecture to production. Remote, CET time zone.