Skip to content

ZATCA (Fatoora) QR code easily which required for e-invoicing for Android Apps on smart phones and POS devices.

Notifications You must be signed in to change notification settings

iabdelgawaad/ZATCA

Repository files navigation

(Kotlin & Java)- 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_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

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()) //..> 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())

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)