- Enter seller information
- Base64 and 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_seller_name = "1"
- length_seller_name = "Shawrma House"?.toByteArray()?.size?.toString()
- value_seller_name = "Shawrma House"
By Creating a TLV Byte Array for field like this:
tlv1 = byteArrayOf(tag_seller_name.toByte(), length_seller_name.toByte()).plus(value_seller_name.toByteArray())
Then do same for the 5 tags and Convert to base64 code:
var tlvs = tlv1 + tlv2 + tlv3 + tlv4 + tlv5
var text = Base64.encodeToString(tlvs, Base64.DEFAULT)
return text.replace("\n", "")
Finally, Genearte the QR-cod from String using Zxing
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()) //..> date format recommended to be with this format "yyyy-MM-dd HH:mm:ss"
.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())
-
Download this app to validate is your QR code match Zatca requirements or not: الفاتورة الالكترونية
-
Sample of QR Reader
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
The MIT License (MIT). Please see License File for more information.