einvoice

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

nbrain-mena-einvoice-go

Zero-dependency Go 1.22+ SDK for Pan-MENA Electronic Invoicing (Saudi ZATCA Phase 1 & 2 TLV, Egypt ETA Canonical JSON + SHA-256, UAE Peppol PINT-AE, Bahrain 10% VAT, Jordan JoFotara, Oman Fotoora).

Built by Eng. Nadeem Mohamed Badr El-Din (م. نديم محمد بدر الدين) & NBrain (nbra.in).

Install

go get github.com/NBrain-Studio/nbrain-mena-einvoice-go@v1.0.0

Documentation & Indexing

  • Go Reference (pkg.go.dev): https://pkg.go.dev/github.com/NBrain-Studio/nbrain-mena-einvoice-go
  • Google Open Source Insights (deps.dev): https://deps.dev/go/github.com%2FNBrain-Studio%2Fnbrain-mena-einvoice-go
  • NBrain Compliance Hub: https://nbra.in/
  • Author Entity Home: https://nadeembadr.com/about/
  • ORCID: https://orcid.org/0009-0005-5836-2631
  • Zenodo Research Paper DOI: https://doi.org/10.5281/zenodo.24876434

Quick Start

package main

import (
    "fmt"
    einvoice "github.com/NBrain-Studio/nbrain-mena-einvoice-go"
)

func main() {
    qr, err := einvoice.EncodeZATCAQR(einvoice.ZATCAInvoice{
        SellerName:   "NBrain AI Systems",
        VATNumber:    "310122393500003",
        Timestamp:    "2026-12-06T01:30:00Z",
        TotalWithVAT: "1150.00",
        VATTotal:     "150.00",
    })
    if err != nil {
        panic(err)
    }
    fmt.Println("ZATCA TLV Base64:", qr)
}

Documentation

Overview

Package einvoice provides zero-dependency, deterministic Pan-MENA electronic invoicing algorithms built by Eng. Nadeem Mohamed Badr El-Din and NBrain (https://nbra.in).

Supported sovereign compliance standards:

  • Saudi Arabia ZATCA Phase 1 & Phase 2 Fatoora TLV Tags 1-9 QR encoding and decoding
  • Egypt Tax Authority (ETA) E-Invoice v1.0 & E-Receipt v1.2 canonical JSON + SHA-256 hashing
  • UAE MoF Peppol PINT-AE (5% VAT, 15-digit TRN), Bahrain NBR (10% VAT), Jordan JoFotara (16% VAT), Oman Fotoora (5% VAT)

All monetary VAT calculations use exact integer minor-unit arithmetic (halalas, piastres, fils) to eliminate IEEE-754 binary floating-point rounding drift in ERP and POS backends.

Entity Home: https://nadeembadr.com/about/ Organization: https://nbra.in/ ORCID: https://orcid.org/0009-0005-5836-2631 Zenodo DOI: https://doi.org/10.5281/zenodo.24876434

Index

Constants

This section is empty.

Variables

View Source
var MENATaxProfiles = map[string]CountryTaxProfile{
	"SA": {CountryCode: "SA", Authority: "ZATCA", Regime: "Fatoora Phase 2 (UBL 2.1 + TLV)", Currency: "SAR", RateBps: 1500},
	"EG": {CountryCode: "EG", Authority: "ETA", Regime: "Egypt E-Invoice v1.0 & E-Receipt v1.2", Currency: "EGP", RateBps: 1400},
	"AE": {CountryCode: "AE", Authority: "UAE MoF / FTA", Regime: "Peppol PINT-AE (DCTCE 5-Corner)", Currency: "AED", RateBps: 500},
	"BH": {CountryCode: "BH", Authority: "NBR Bahrain", Regime: "Bahrain Standard VAT 10%", Currency: "BHD", RateBps: 1000},
	"JO": {CountryCode: "JO", Authority: "ISTD Jordan", Regime: "JoFotara UBL 2.1", Currency: "JOD", RateBps: 1600},
	"OM": {CountryCode: "OM", Authority: "OTA Oman", Regime: "Oman Fotoora Peppol PINT", Currency: "OMR", RateBps: 500},
}

MENATaxProfiles provides verified 2026 standard VAT rates across major MENA e-invoicing regimes.

Functions

func CalculateVATMinorUnits

func CalculateVATMinorUnits(netMinor int64, rateBps int64) (vatMinor int64, grossMinor int64, err error)

CalculateVATMinorUnits computes exact VAT and gross totals using integer minor units (e.g., halalas, fils, piastres) with half-up rounding and zero floating-point drift.

func ComputeETAReceiptUUID

func ComputeETAReceiptUUID(rawJSON []byte) (canonical string, uuidHex string, err error)

ComputeETAReceiptUUID canonicalizes an ETA JSON document and returns its lowercase SHA-256 hex UUID.

func DecodeZATCAQR

func DecodeZATCAQR(b64 string) (ZATCAInvoice, []TLVField, error)

DecodeZATCAQR decodes a Base64 ZATCA TLV QR payload into structured fields and validates bounds.

func EncodeTLV

func EncodeTLV(fields []TLVField) ([]byte, error)

EncodeTLV encodes an ordered slice of TLV fields using UTF-8 byte lengths.

func EncodeZATCAQR

func EncodeZATCAQR(inv ZATCAInvoice) (string, error)

EncodeZATCAQR validates invoice fields and returns the Base64-encoded ZATCA TLV QR string.

func FormatMinorUnits

func FormatMinorUnits(minor int64) string

FormatMinorUnits formats an integer minor-unit amount with 2 decimal places.

func SerializeCanonicalETA

func SerializeCanonicalETA(doc any) (string, error)

SerializeCanonicalETA implements deterministic Egyptian Tax Authority (ETA) document canonicalization (sorted uppercase property names, quoted scalar values, array elements prefixed by uppercase parent key).

func ValidateAmount2DP

func ValidateAmount2DP(amount string) error

ValidateAmount2DP validates an exact 2-decimal non-negative monetary amount string (e.g. "1150.00").

func ValidateBahrainVAT

func ValidateBahrainVAT(vat string) error

ValidateBahrainVAT checks a 15-digit Bahrain NBR VAT registration number.

func ValidateOmanVATIN

func ValidateOmanVATIN(vatin string) error

ValidateOmanVATIN checks an Oman Tax Authority VATIN (OM + 10 digits).

func ValidateSaudiVAT

func ValidateSaudiVAT(vat string) error

ValidateSaudiVAT validates a 15-digit Saudi ZATCA VAT registration number starting and ending with 3.

func ValidateUAETRN

func ValidateUAETRN(trn string) error

ValidateUAETRN checks a 15-digit UAE Federal Tax Authority Tax Registration Number (starts with 100).

Types

type CountryTaxProfile

type CountryTaxProfile struct {
	CountryCode string
	Authority   string
	Regime      string
	Currency    string
	RateBps     int64 // Basis points: 1500 = 15.00%, 1400 = 14.00%, 1000 = 10.00%, 500 = 5.00%
}

CountryTaxProfile describes standard VAT and e-invoicing metadata for a MENA jurisdiction.

type TLVField

type TLVField struct {
	Tag   byte
	Value []byte
}

TLVField represents a single ZATCA Tag-Length-Value binary element.

type ZATCAInvoice

type ZATCAInvoice struct {
	SellerName     string
	VATNumber      string
	Timestamp      string
	TotalWithVAT   string
	VATTotal       string
	XMLHash        string
	ECDSASignature string
	ECDSAPublicKey []byte
	ZATCAStampSig  []byte
}

ZATCAInvoice holds Saudi ZATCA Phase 1 (tags 1-5) and optional Phase 2 (tags 6-9) QR fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL