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 ¶
- Variables
- func CalculateVATMinorUnits(netMinor int64, rateBps int64) (vatMinor int64, grossMinor int64, err error)
- func ComputeETAReceiptUUID(rawJSON []byte) (canonical string, uuidHex string, err error)
- func DecodeZATCAQR(b64 string) (ZATCAInvoice, []TLVField, error)
- func EncodeTLV(fields []TLVField) ([]byte, error)
- func EncodeZATCAQR(inv ZATCAInvoice) (string, error)
- func FormatMinorUnits(minor int64) string
- func SerializeCanonicalETA(doc any) (string, error)
- func ValidateAmount2DP(amount string) error
- func ValidateBahrainVAT(vat string) error
- func ValidateOmanVATIN(vatin string) error
- func ValidateSaudiVAT(vat string) error
- func ValidateUAETRN(trn string) error
- type CountryTaxProfile
- type TLVField
- type ZATCAInvoice
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 EncodeZATCAQR ¶
func EncodeZATCAQR(inv ZATCAInvoice) (string, error)
EncodeZATCAQR validates invoice fields and returns the Base64-encoded ZATCA TLV QR string.
func FormatMinorUnits ¶
FormatMinorUnits formats an integer minor-unit amount with 2 decimal places.
func SerializeCanonicalETA ¶
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 ¶
ValidateAmount2DP validates an exact 2-decimal non-negative monetary amount string (e.g. "1150.00").
func ValidateBahrainVAT ¶
ValidateBahrainVAT checks a 15-digit Bahrain NBR VAT registration number.
func ValidateOmanVATIN ¶
ValidateOmanVATIN checks an Oman Tax Authority VATIN (OM + 10 digits).
func ValidateSaudiVAT ¶
ValidateSaudiVAT validates a 15-digit Saudi ZATCA VAT registration number starting and ending with 3.
func ValidateUAETRN ¶
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 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.