Skip to content

Commit

Permalink
Refactor and reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
arvvoid committed Sep 27, 2024
1 parent 42d0fdd commit 17ac7d2
Show file tree
Hide file tree
Showing 10 changed files with 697 additions and 564 deletions.
11 changes: 2 additions & 9 deletions README-HR.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ func main() {
"G", // payment method G - cash, K - credit card, T -
// transfer, O - other, C - check (deprecated)
"12345678901", // operator OIB
false, // late delivery, if previous attempt failed but the
// invoice was issued with just ZKI
"", // receipt book number, if the invoicing system was
// unusable and the invoice was issued manually, the
// number of the receipt book
"", // unused, reserved field for future or temporary
// unexpected use by the CIS, should be empty
)

if err != nil {
Expand All @@ -151,14 +144,14 @@ func main() {
// serial of the certificate used to generate it for future reference. You
// can get the cert serial with fiskalEntity.GetCertSERIAL().

// Display the invoice
// Display the invoice for test
fmt.Println(invoice)

// NOW we should have a saved invoice with a valid ZKI and we are ready to
// send the invoice to the CIS

// Send test invoice to CIS with InvoiceRequest
jir, zkiR, err := fiskalEntity.InvoiceRequest(invoice)
jir, zkiR, err := invoice.InvoiceRequest()

if err != nil {
log.Fatalf("Failed to send invoice: %v", err)
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ func main() {
"G", // payment method G - cash, K - credit card, T -
// transfer, O - other, C - check (deprecated)
"12345678901", // operator OIB
false, // late delivery, if previous attempt failed but the
// invoice was issued with just ZKI
"", // receipt book number, if the invoicing system was
// unusable and the invoice was issued manually, the
// number of the receipt book
"", // unused, reserved field for future or temporary
// unexpected use by the CIS, should be empty
)

if err != nil {
Expand All @@ -150,14 +143,14 @@ func main() {
// serial of the certificate used to generate it for future reference. You
// can get the cert serial with fiskalEntity.GetCertSERIAL().

// Display the invoice
// Display the invoice for test
fmt.Println(invoice)

// NOW we should have a saved invoice with a valid ZKI and we are ready to
// send the invoice to the CIS

// Send test invoice to CIS with InvoiceRequest
jir, zkiR, err := fiskalEntity.InvoiceRequest(invoice)
jir, zkiR, err := invoice.InvoiceRequest()

if err != nil {
log.Fatalf("Failed to send invoice: %v", err)
Expand Down
25 changes: 25 additions & 0 deletions basicvalidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ func IsValidCurrencyFormat(amount string) bool {
return validCurrency.MatchString(amount)
}

// IsValidTaxRate checks if the given string is a valid non-negative tax rate with exactly two decimal places.
// Allows positive values and 0.00, but not negative values.
func IsValidTaxRate(rate string) bool {
// Regex pattern to match a positive or zero decimal number with exactly two decimal places
// Matches values like "0.00", "25.00", "5.00", etc.
validTaxRate := regexp.MustCompile(`^([0-9]+)(\.[0-9]{2})$`)
return validTaxRate.MatchString(rate)
}

// ValidateOIB checks if an OIB is valid using the Mod 11, 10 algorithm
func ValidateOIB(oib string) bool {
if len(oib) != 11 {
Expand Down Expand Up @@ -86,3 +95,19 @@ func IsFileReadable(filePath string) bool {

return true
}

// ValidateJIR checks if the given JIR is a valid UUID format (e.g., "9d6f5bb6-da48-4fcd-a803-4586a025e0e4").
// Returns true if valid, otherwise false.
func ValidateJIR(jir string) bool {
// Regular expression to match UUID format (e.g., "9d6f5bb6-da48-4fcd-a803-4586a025e0e4")
var jirRegex = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
return jirRegex.MatchString(jir)
}

// ValidateZKI checks if the given ZKI is a valid MD5 hash in hexadecimal format (32 characters).
// Returns true if valid, otherwise false.
func ValidateZKI(zki string) bool {
// Regular expression to match a 32-character hexadecimal MD5 hash
var zkiRegex = regexp.MustCompile(`^[0-9a-f]{32}$`)
return zkiRegex.MatchString(zki)
}
6 changes: 0 additions & 6 deletions dsignandverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ import (
"crypto/x509"
"encoding/base64"
"fmt"
"time"

"github.com/beevik/etree"
)

// generateUniqueID generates a unique ID
func generateUniqueID() string {
return fmt.Sprintf("%x", time.Now().UnixNano())
}

// doc14n applies Exclusive Canonical XML (http://www.w3.org/2001/10/xml-exc-c14n#) to the input XML data
func doc14n(xmlData []byte) ([]byte, error) {
// Parse the input XML string into an etree.Document
Expand Down
Loading

0 comments on commit 17ac7d2

Please sign in to comment.