ZATCA (Fatoora) QR-Code Implementation

QR-Code implementation for the e-invoicing (Fatoora)

Zatca-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

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Credits

License

The MIT License (MIT). Please see License File for more information.

(back to top)

GitHub

View Github