How to generate SEPA Credit Transfer (SCT) QR codes using PowerShell
Earlier this year I had to create some invoices for a non-work related project. To make paying the invoices as easy as possible I decided to include SEPA Credit Transfer (SCT) QR codes, which is a special type of QR code that allows to make a payment without inputting any data manually.
In this blog I’ll show you how to generate QR codes using PowerShell, explain what data a SCT QR code should contain and finally give you a sample script to generate your own SCT QR codes.
Finding a suitable library
Since PowerShell (or the .NET framework it is based on) does not include an out-of-the-box solution for generating QR codes, we need a library for this. QRCoder is a pure C# Open Source QR Code implementation that does not have any dependencies to external libraries. As an added bonus, it’s also very easy to use.
To use the QRCoder library with PowerShell, download the NuGet package and extract the DLL file from it:
- Download
qrcoder.1.6.0.nupkg
package file from https://www.nuget.org/api/v2/package/QRCoder/1.6.0 - Rename
qrcoder.1.6.0.nupkg
toqrcoder.1.6.0.zip
and extract it. A .nupkg file is just a zip archive that contains the packaged libraries. It can be renamed to .zip and extracted with any standard zip utilities. - Locate
QRCoder.dll
under the folderlib\net40
and copy it somewhere, e.g.C:\MyScripts
, for later use. We only need the DLL targeting .NET Framework 4.0
Using QRCoder with PowerShell
Now that we have our QRCoder.dll
file, the first thing we need to do is to load the assembly. Open up a PowerShell console and run the following:
1
2
3
4
# Load QRCoder.dll assembly
$QRCoderDLLPath = "C:\MyScripts\QRCoder.dll"
$DllBytes = [System.IO.File]::ReadAllBytes($QRCoderDLLPath)
[System.Reflection.Assembly]::Load($DLLBytes) | Out-Null
I prefer to always load assemblies from memory ($DllBytes
) as opposed to reading it directly from the file, because this way the assembly file will not get locked.
Next, we need to instantiate a QRCodeGenerator
object:
1
2
# Instantiate QRCodeGenerator
$QRCodeGenerator = [QRCoder.QRCodeGenerator]::new()
Then, using $QRCodeGenerator
we can create a QRCodeData
object, which is a data layer presentation of the QR code. Let’s say we want to encode the text https://www.google.fi
with an error correction level M (15%), which defines how much of the QR code can get corrupted before the code isn’t readable any longer:
1
2
# Create data layer presentation of the QR code
$QRCodeData = $QRCodeGenerator.CreateQrCode("https://www.google.fi", [QRCoder.QRCodeGenerator+ECCLevel]::M)
Details of all the parameters for
CreateQRCode
method can be found here. Note that all the examples in QRCoder’s documentation are in C# which means you have to first translate them to PowerShell.
Finally, we can use one the renderers included in QRCoder library to render the QR code in the format we prefer. Let’s say we wanted to render the QR code as a PNG graphic and save it to a .png file:
1
2
3
4
5
6
7
8
9
# Render the QR Code as a PNG graphic
$PngByteQRCode = [QRCoder.PngByteQRCode]::new($QRCodeData)
# Return the graphic as a byte array with 20 pixel module size
$PngByteArray = $PngByteQRCode.GetGraphic(20)
# Save the byte array to a .png file
$PngFilePath = "C:\MyScripts\QRCode.png"
[System.IO.File]::WriteAllBytes($PngFilePath, $PngByteArray)
And voilá! The file C:\MyScripts\QRCode.png
now contains a QR code with the text https://www.google.fi
encoded in it:
https://www.google.fi encoded in a QR code
Now that we have learned to generate an arbitrary QR code with PowerShell, let’s focus on SEPA Credit Transfer QR codes next.
What is a SEPA Credit Transfer (SCT) Quick Response code?
SEPA Credit Transfer Quick Response codes are QR codes that contain all the data required to make a payment. Using a QR code eliminates all manual data input - you just scan the code with your bank’s app, and all the payment details are picked up automatically. SCT QR codes are meant to replace the older bank bar codes in SEPA region in the future.
They are not yet supported in the whole of SEPA region but only in Austria, Belgium, Finland, Germany and The Netherlands. As I live in Finland the examples in this blog are tested using a Finnish banking app.
Data contents of the QR code
To generate a valid SCT QR code, we need to understand what data we need and how we need to structure it. Finance Finland has published a guideline for using QR codes in the credit transfer forms that includes a definition for the data contents of the QR code.
The data consists of 11 fields that are separated by line breaks (LF or CRLF). Some of the fields are mandatory and others optional.
# | Field description | Data length |
---|---|---|
1* | Service Tag, always ‘BCD’ | 3 characters |
2* | Version, always ‘001’ | 3 characters |
3* | Character set id number 1 = UTF-8 recommended | Number between 1-8 |
4* | Identification code, always ‘SCT’ | 3 characters |
5* | BIC of the Beneficiary Bank | 8/11 characters |
6* | Name of the Beneficiary | 1-70 characters |
7* | IBAN account number of the beneficiary | 1-34 characters |
8 | Amount of the credit transfer in Euros prefixed with ‘EUR’ | Must be between 0.01 and 999999999.99, use dot (.) as decimal separator |
9 | Purpose of the credit transfer | 1-4 characters |
10** | Creditor reference i.e. reference number | 1-35 characters |
11** | Remittance information i.e. message to creditor | 1-140 characters |
12 | Beneficiary to originator information (for example due date) | 1-70 characters Due date is entered as first information in the field in the following format ReqdExctnDt/2013-11-07 |
(* Field is mandatory, ** One of the fields is mandatory)
Example
To create a SCT QR code for an invoice with
- an amount of 397,49 euros
- a reference number 241018
- payable to Acme Corporation with bank account information (BIC / IBAN) OKOYFIHH / FI7944052020036082
- a due date of December 24th 2024
we use the following data:
1
2
3
4
5
6
7
8
9
10
11
12
BCD
001
1
SCT
OKOYFIHH
Acme Corporation
FI7944052020036082
EUR397.49
241018
ReqdExctnDt/2024-12-24
The empty lines in the example data represent optional fields that we do not need to specify.
When using this data to create a QR code we get a SCT QR code. When scanned using a banking app, all the details for the payment are picked up automatically without any need for manual inputting.
Example SCT QR code. You can safely test scanning the code with your banking app but please do not proceed with the payment! :)
The script
For your convenience I have created a ready-to-use PowerShell script that can be used to generate a SCT QR code which can be saved as .png file or copied to clipboard.
You can download the script here:
peramhe/New-SCTQRCode: A PowerShell script to generate a QR code for a SEPA Credit Transfer (SCT) transaction