einvoice

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

README

go-einvoice

CI Go Reference Go Report Card

A Go library for generating German E-Invoices (E-Rechnung) compliant with EN 16931.

This library is designed to help developers upgrade their invoicing systems for the upcoming German B2B mandates starting January 1st, 2025. It supports the creation of XRechnung 3.0 (XML) and ZUGFeRD / Factur-X (PDF/A-3 with embedded XML).

Features

✅ Full support for EN 16931 (UN/CEFACT CII). ✅ Compliant with XRechnung 3.0 (German Standard). ✅ Generates ZUGFeRD / Factur-X files by embedding XML into existing PDFs.

Installation

go get github.com/dotwavehq/go-einvoice

Library Usage

To use go-einvoice in your backend service, you build an einvoice.Invoice and hand it to a serializer. The library takes care of the complex XML namespaces and business rules.

Create an Invoice

import (
    einvoice "github.com/dotwavehq/go-einvoice"
    "github.com/dotwavehq/go-einvoice/cii"
    "github.com/dotwavehq/go-einvoice/zugferd"
    "github.com/shopspring/decimal"
)

func main() {
    // Helper to create decimals from string to avoid float precision errors
    toDec := func(s string) decimal.Decimal {
        d, _ := decimal.NewFromString(s)
        return d
    }

    invoice := einvoice.Invoice{
        Number:         "RE-2025-1001",
        IssueDate:      time.Now(),
        DueDate:        time.Now().AddDate(0, 0, 14),
        BuyerReference: "ORDER-12345",
        Currency:       "EUR",
        Note:           "Thank you for your business.",

        Seller: einvoice.Party{
            Name:        "My Software Company GmbH",
            Street:      "Tech Lane 1",
            City:        "Berlin",
            PostalCode:  "10115",
            CountryCode: "DE", 
            VATID:       "DE123456789",
            Contact: &einvoice.Contact{
                Name:  "Jane Doe",
                Phone: "+49 30 123456",
                Email: "billing@mycompany.com",
            },
        },

        Buyer: einvoice.Party{
            Name:        "Client Corp AG",
            Street:      "Business Rd 5",
            City:        "Munich",
            PostalCode:  "80331",
            CountryCode: "DE",
            VATID:       "DE987654321",
        },

        Payment: einvoice.Payment{
            IBAN:             "DE99123456789012345678",
            PaymentMeansCode: "30",
        },

        LineItems: []einvoice.LineItem{
            {
                Description: "Consulting Services",
                Quantity:    toDec("10.0"),
                UnitCode:    "HUR",
                UnitPrice:   toDec("100.00"),
                TaxRate:     toDec("19.0"),
            },
            {
                Description: "Hosting Fee",
                Quantity:    toDec("1.0"),
                UnitCode:    "C62",
                UnitPrice:   toDec("50.00"),
                TaxRate:     toDec("19.0"),
            },
        },
        
        TaxTotal:   toDec("199.50"),
        GrandTotal: toDec("1249.50"),
    }

    // Serialize to XML (CII / XRechnung format)
    serializer := cii.NewSerializer()
    xmlBytes, err := serializer.Serialize(&invoice)
    if err != nil {
        log.Fatalf("Failed to generate XML: %v", err)
    }

    // Save as pure XRechnung XML
    os.WriteFile("xrechnung.xml", xmlBytes, 0644)

    // Create ZUGFeRD (Hybrid PDF)
    err = zugferd.EmbedXML("invoice.pdf", xmlBytes, "zugferd.pdf")
    if err != nil {
        log.Fatalf("Failed to embed XML into PDF: %v", err)
    }
    
    log.Println("Successfully generated E-Invoices!")
}

CLI Usage

Generate XML
./einvoice -in invoice.json -out invoice
# Creates invoice.xml
Generate ZUGFeRD PDF
./einvoice -in invoice.json -pdf invoice.pdf -out invoice
# Creates invoice.pdf

License

GNU AFFERO GENERAL PUBLIC LICENSE

Documentation

Overview

Package einvoice provides the domain model for German E-Invoices (E-Rechnung) compliant with EN 16931.

The Invoice type is the entry point. Serialize it to XRechnung 3.0 / CII XML with the cii package, and embed that XML into a PDF/A-3 (ZUGFeRD / Factur-X) with the zugferd package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contact

type Contact struct {
	Name  string
	Phone string
	Email string
}

type Invoice

type Invoice struct {
	Number         string
	IssueDate      time.Time
	DueDate        time.Time
	Currency       string
	Note           string
	BuyerReference string

	Seller    Party
	Buyer     Party
	Payment   Payment
	LineItems []LineItem

	TaxTotal   decimal.Decimal
	GrandTotal decimal.Decimal
}
Example
package main

import (
	"fmt"

	einvoice "github.com/dotwavehq/go-einvoice"
	"github.com/dotwavehq/go-einvoice/cii"
	"github.com/shopspring/decimal"
)

func main() {
	inv := &einvoice.Invoice{
		Number:   "RE-2025-1001",
		Currency: "EUR",
		Seller:   einvoice.Party{Name: "Seller GmbH", CountryCode: "DE", VATID: "DE123456789"},
		Buyer:    einvoice.Party{Name: "Buyer AG", CountryCode: "DE"},
		LineItems: []einvoice.LineItem{{
			Description: "Consulting",
			Quantity:    decimal.NewFromInt(10),
			UnitCode:    "HUR",
			UnitPrice:   decimal.RequireFromString("100.00"),
			TaxRate:     decimal.NewFromInt(19),
		}},
		TaxTotal:   decimal.RequireFromString("190.00"),
		GrandTotal: decimal.RequireFromString("1190.00"),
	}

	xmlBytes, err := cii.NewSerializer().Serialize(inv)
	if err != nil {
		panic(err)
	}
	fmt.Println(len(xmlBytes) > 0)
}
Output:
true

type InvoiceSerializer

type InvoiceSerializer interface {
	Serialize(invoice *Invoice) ([]byte, error)
}

InvoiceSerializer defines the contract for converting the domain model into a spec format.

type LineItem

type LineItem struct {
	Description string
	Quantity    decimal.Decimal
	UnitCode    string
	UnitPrice   decimal.Decimal
	TaxRate     decimal.Decimal
}

type Party

type Party struct {
	Name        string
	Street      string
	City        string
	PostalCode  string
	CountryCode string
	VATID       string
	Contact     *Contact
}

type Payment

type Payment struct {
	IBAN             string
	BIC              string
	AccountHolder    string
	PaymentMeansCode string
}

Directories

Path Synopsis
cmd
einvoice command

Jump to

Keyboard shortcuts

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