ZATCA (Fatoora) QR-Code Implementation
QR-Code implementation for the e-invoicing (Fatoora)
- Enter seller information
- Base64 and QR Generated
How QR Generated
In this repo, we will demonstrate how to simply implement a QR code for the ZATCA (Fatoora). For this, the following steps will be explored:
Using TLV to start generating the QR code:
Example: seller name is “Shawrma House”
- tag = 1
- length = “Shawrma House”.length
- value = “Shawrma House”
By Creating a TLV Byte Array for each tag like this:
tlv1 = byteArrayOf(tag.toByte(), length.toByte()).plus(value.toByteArray())
Then do same for the 5 tags and Convert to base64 code:
var tlvs = tlv1 + tlv2 + tlv3 + tlv4 + tlv5
return Base64.encodeToString(tlvs, Base64.DEFAULT)
Finally, Genearte the QR-cod from String using Zxing
Usage
Step 1. Add ZatcaQRCodeGeneration class to your project
Step 2. use class Builder to add your merchant data like below:
builder.sellerName(sellerNameEditText?.text?.toString()) // Shawrma House
.taxNumber(taxNumberEditText?.text?.toString()) // 1234567890
.invoiceDate(dateTimeEditText?.text?.toString()) //..> 22/11/2021 03:00 am
.totalAmount(totalAmountWithVatEditText?.text?.toString()) // 100
.taxAmount(vatAmountEditText?.text?.toString()) // 15
Output Base64 =
AQ1TaGF3cm1hIEhvdXNlAgoxMjM0NTY3ODkwAxMyMi8xMS8yMDIxIDAzOjAwIGFtBAMxMDAFAjE1
Finally, you can convert Base64 string to Bitmap then render QR code image (you can pass Bitmap to your ImageView)
showBottomSheet(builder.getBase64())
Testing
-
Download this app to validate is your QR code is meet Zatca requirements or not:
E-Invoice QR Reader KSA قارئ الفاتورة الالكترونية -
Sample of QR Reader
Contributing
Contributions are what make the open-source community such an amazing place to learn, inspire, and create.
Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request.
You can also simply open an issue with the tag “enhancement”. Don’t forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Credits
License
The MIT License (MIT). Please see License File for more information.