Skip to content

An unofficial package in Golang to help developers implement ZATCA (Fatoora) QR code easily.

License

Notifications You must be signed in to change notification settings

Haraj-backend/zatca-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zatca SDK GO

Build Test Go Report Card

An unofficial package in Golang to help developers to implement ZATCA (Fatoora) QR code easily which required for e-invoicing

✅ The hash result has been validated the same as the output from ZATCA's SDK as of 18th November 2021

Installation

go get github.com/Haraj-backend/zatca-sdk-go

Simple Usage

package main

import (
	"log"
	"time"

	"github.com/Haraj-backend/zatca-sdk-go/qrcode"
)

func main() {
	// encode data using TLV method to get code hash
	hash, err := qrcode.EncodeTLV(qrcode.Data{
		SellerName:      "Bobs Records",
		SellerTaxNumber: "310122393500003",
		Timestamp:       time.Date(2022, 04, 25, 15, 30, 00, 00, time.UTC),
		InvoiceTotal:    1000,
		TotalVAT:        150,
	})
	if err != nil {
		log.Fatalf("unable to encode TLV due: %v", err)
	}
	fmt.Println("hash data:", hash)

	// decode hash using TLV method to get data
	data, err := qrcode.DecodeTLV(hash)
	if err != nil {
		log.Fatalf("unable to decode TLV due: %v", err)
	}
	fmt.Printf("decoded hash: %s", data)
}

Generating QR Code

This package is only used for encoding QR Code data into base64 hash using TLV method. So it doesn't contain functionality to generate QR Code image.

If you want to generate the QR Code image, you could use another library such as skip2/go-qrcode. You could check examples/qrcode_generator for details.