Swiss QR Invoice

Hello everyone,

Who has already generated a Swiss QR- invoice with Lucee? Which components/libraries or services have you used?

I am of course looking for something that is free of charge. It is for a non-profit organization.

I would be very happy to receive tips and advice.

Thanks a lot,
Allan

see this post it shows how to make QR code with Lucee 6.2

Of course it can be rewritten to work with older Lucee versions, but will need a bit of work.

1 Like

@Schumatech, I was not familiar with the Swiss QR Code, but was curious so I just learned about it and found that it has a specific data content structure for payment info, plus the Swiss cross in the middle for user recognition, but structurally not different than any other QR code.

As for data structure, I found multiple versions here.

Then using @micstriit’s Java example as a reference, I herded ChatGPT into giving me cfscript that looks like it could actually work (I haven’t tested it):

// Load necessary ZXing Java classes
qrWriterClass = CreateObject("java", "com.google.zxing.qrcode.QRCodeWriter");
bitMatrixClass = CreateObject("java", "com.google.zxing.common.BitMatrix");
encodeHintType = CreateObject("java", "com.google.zxing.EncodeHintType");
barcodeFormat = CreateObject("java", "com.google.zxing.BarcodeFormat");

// Swiss QR Code payment data (adjust based on Swiss QR Code standard)
qrData = "SPC\n0200\n1\nCH4431999123000889012\nS\nRobert Schneider AG\nRue du Lac 1268\n2501\nBiel\nCH\nS\nPia-Maria Rutschmann-Schnyder\nGrosse Marktgasse 28\n9400\nRorschach\nCH\n3949.75\nCHF\n\n\nNON\n\nMOTIVATED SALARY";

// Set QR encoding hints
hints = CreateObject("java", "java.util.HashMap");
hints.put(encodeHintType.CHARACTER_SET, "UTF-8");

// Create the QR code BitMatrix
qrCode = qrWriterClass.init().encode(qrData, barcodeFormat.QR_CODE, 400, 400, hints);

// Load BufferedImage for handling the QR code image
bufferedImageClass = CreateObject("java", "java.awt.image.BufferedImage");
bufferedImage = qrCode.toBufferedImage();

// Swiss Cross Image (see download below)
crossImagePath = "/path/to/swiss_cross.png";
imageioClass = CreateObject("java", "javax.imageio.ImageIO");
crossImage = imageioClass.read(CreateObject("java", "java.io.File").init(crossImagePath));

// Combine Swiss Cross into QR Code Image
graphicsClass = bufferedImage.getGraphics();
crossWidth = 50; // Set size for the Swiss cross
crossHeight = 50;
crossX = (bufferedImage.getWidth() / 2) - (crossWidth / 2); // Center position
crossY = (bufferedImage.getHeight() / 2) - (crossHeight / 2);

// Draw the Swiss cross in the middle of the QR code
graphicsClass.drawImage(crossImage, crossX, crossY, crossWidth, crossHeight, null);
graphicsClass.dispose();

// Save the QR code image to a file
outputPath = "/path/to/output/swiss_qr_code.png";
outputFile = CreateObject("java", "java.io.File").init(outputPath);
imageioClass.write(bufferedImage, "png", outputFile);

// Output success message
writeOutput("Swiss QR Code with Swiss cross generated successfully.");

I also found a PNG for the cross here via Formpipe.

Good luck and I’m looking forward to your QA tested code!

2 Likes

I think there is not such a thing as a swiss QR-Code. QR-Codes is a free to use patent (thx to Denso and Toyota). What you are describing is a standard of structered information that is the content of the QR-Code. You just need to bring the raw data into the needed standard and translate/generate that to a QR-Code like any other standardized data (such as e.g. vcf, url etc)

QR-bill – Swiss Payment Standards | SIX.

This could be a helpful link. Do you have any more information on how it can be used

I’ve read something about it. The QR-Bill is not just a QR-Code, but a standard for printing standarized digital bills (e.g. as PDF) in a structured manner, that has t the QR-Code data in it (as XML). You can choose to make it fully by your own, or try using a linary for it, e.g. SwissQRBill Java library GitHub - manuelbl/SwissQRBill: Java library for Swiss QR bill payment slips (aka QR-Rechnung)

1 Like

QRCode can store 4 kind of that, binary,string,number or kanji (japanese characters).

Nearly all QRCode today do store string and use different formats QRReader understand, i have for example a component that can create for me all kind of format like this

        /**
         * Creates a formatted WiFi configuration string to encode into a QR code.
         * 
         * @param ssid          The WiFi SSID (network name).
         * @param password      The WiFi password.
         * @param encryption    The encryption type (e.g., WPA, WEP). Optional.
         * @return              A formatted WiFi string for the QR code.
         */
        public static String function wifi(required string ssid, required string password, string encryption="") {
            var enc="";
            if(len(arguments.encryption)) enc="T:#arguments.encryption#;";
            return "WIFI:S:#trim(arguments.ssid)#:;#enc#P:#arguments.password#;;";
        }

for “Swiss QRCode” this is simply a format like this, sorry i simply assumed that part is clear.