Understanding the QR Code used in Hong Kong Faster Payment System
If you have a Hong Kong Faster Payment System merchant account, people can transfer or pay you money by scanning your QRCode. This article explain the steps of generating a QR code for Hong Kong Faster Payment System (FPS).
Common QR Code (HKQR)
FPS in Hong Kong is using the standard of Common QRCode. Common QR Code is based on the EMVCo’s QR Code specification. Merchant can combine QR codes that are from different payment service providers (e.g. FPS, Octopus, TapNGo, etc) into a single QR code to receive payment.
Data Object
The Common QR Code content are made up of data objects. Each data object contains its own ID, Length and Value.They form a string in ID Length Value order
- ID must be 2 digit.
- Length refer to the 2-digit character length of Value.
- Value is the content
For example, according to the specification the Value of data object ID 0 is fixed to ‘01’ , and therefore Length should be ‘02’. i.e.
000201
Static or Dynamic
HKQR code can be Static or Dynamic by setting the Value (‘11’ or ‘12’) of data object ID ‘01’
Static
All the information in the static QR Code are fixed and consumer can type the payment account before confirm the payment. The full string of ID ‘01’ is
010211
Dynamic
The payment information can be generated on the fly when customer needs to checkout. Customer will see all the payment information after scanning and they are required to confirm to pay. The full string of ID ‘01’ is
010212
All the data objects should be added together to form a string. For example, we combine ID ‘00’ and ID ‘01’ data objects and form a string below.
000201010212
For data with other IDs, please refer to the Common QR Code specification and define different data that suit your own need. In the end you should have a very long strings that made up of different data objects.
CRC Checksum
For the data object ID ‘63’, its Value are calculated from Cyclic Redundancy Check (CRC16) and is fixed to be a 4-digit string. The calculation is using the polynomial ‘1021’ (hex) and initial value ‘FFFF;
For more bout the calculation of CRC16, please refer to the article from www.sunshine2k.de — Understanding and implementing CRC (Cyclic Redundancy Check) calculation (link)
6304XXXX
where XXXX are the checksum calculated. All the data objects before XXXX should be used for the checksum calculation, including the ID ‘63’ and Length ‘04’.
For example if the data objects defined are
00020101021226270012hk.com.hkicl0207000000152040000530334454075000.005802HK5902NA6002HK62680104000202081234567803040003040400040504ABCD060400050704000608040007
XXXX is calculated from the string by adding “63” and “04” to the end, i.e.
00020101021226270012hk.com.hkicl0207000000152040000530334454075000.005802HK5902NA6002HK62680104000202081234567803040003040400040504ABCD0604000507040006080400076304
The result should be 8D1D of the data objects are now
00020101021226270012hk.com.hkicl0207000000152040000530334454075000.005802HK5902NA6002HK62680104000202081234567803040003040400040504ABCD06040005070400060804000763048D1D
Testing your FPS QR Code
After calculated the checksum, the data objects can be used to generate the QR code. You may download HKQR app on both Android and iOS platform to test it. You can see all the values of the data objects by scanning QR Code. If it prompt up errors , you have to go back and check your QR string and each data object.
Links and References
All the materials in this article are based on the followings links. Please use them on your own discretion. By clicking the urls or websites, it means you accept their terms and conditions.
- EMVCo’s QR Code specification
https://www.emvco.com/emv-technologies/qrcodes/
- Common QR Code
https://fps.hkicl.com.hk/eng/fps/merchants/qr_code.php
- Common QR Code Specification by Hong Kong Monetary Authority (HKMA)
- www.sunshine2k.de — Understanding and implementing CRC (Cyclic Redundancy Check) calculation
http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html
- Hong Kong Common QR Code App (iOS)
- Hong Kong Common QR Code App (Android)
NodeJs Module
I made a module in NodeJS to generate QR code for Faster Payment System. Please take a look.