Skip to content

Commit

Permalink
Merge pull request #2 from Haraj-backend/refactor/refactor-example
Browse files Browse the repository at this point in the history
[Update Example]
  • Loading branch information
riandyrn authored Dec 3, 2021
2 parents 4c1189a + 654a82c commit 3a49978
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ import (

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,
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("AR3Yp9mE2KzZiNin2YfYsdmKINin2YTYudix2KjZigIPMzEwMTIyMzkzNTAwMDAzAxQyMDIyLTA0LTI1VDE1OjMwOjAwWgQHMTAwMC4wMAUGMTUwLjAw")
data, err := qrcode.DecodeTLV(hash)
if err != nil {
log.Fatalf("unable to decode TLV due: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions examples/qrcode_generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
qr.png
2 changes: 1 addition & 1 deletion examples/qrcode_generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module qrcode_generator
go 1.16

require (
github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211202074435-18341e584c9c // indirect
github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211203170357-4c1189a98eb1 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
)
2 changes: 2 additions & 0 deletions examples/qrcode_generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211202071118-b3ec4cfc3c60 h1:bXw3
github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211202071118-b3ec4cfc3c60/go.mod h1:Pwl7G1DblSnj27OT7dMMuV20HegghOqdznkq8PoQLms=
github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211202074435-18341e584c9c h1:VxrAZ7sHbprf2tNa5uZqAXSuCXZfQLBCKK19OH5z8nk=
github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211202074435-18341e584c9c/go.mod h1:Pwl7G1DblSnj27OT7dMMuV20HegghOqdznkq8PoQLms=
github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211203170357-4c1189a98eb1 h1:MqeFlLI5spRRm+3aYMb7JOOP8O0kywCvl7ni+6rB2L4=
github.com/Haraj-backend/zatca-sdk-go v0.0.0-20211203170357-4c1189a98eb1/go.mod h1:Pwl7G1DblSnj27OT7dMMuV20HegghOqdznkq8PoQLms=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
22 changes: 7 additions & 15 deletions examples/qrcode_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@ import (
)

func main() {
input := qrcode.QRCodeData{
SellerName: "Bobs Records",
SellerTRN: "310122393500003",
Timestamp: time.Date(2022, 04, 25, 15, 30, 00, 00, time.UTC),
InvoiceTotal: 1000,
TotalVAT: 150,
}

qrCode, err := qrcode.NewQRCode(input)
if err != nil {
log.Fatalf("unable to initialize new qrcode due: %v", err)
}

hash, err := qrCode.EncodeTLV()
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)
}

err = goqrcode.WriteFile(hash, goqrcode.Medium, 256, "qr.png")
if err != nil {
log.Fatalf("unable to encode TLV due: %v", err)
Expand Down

0 comments on commit 3a49978

Please # to comment.