xinvoice

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

gobl.xinvoice

GOBL conversion into and from Factur-X (FR) and XRechnung/ZUGFeRD (DE) formats. This package provides a simple wrapper around the gobl.ubl and gobl.cii packages. If using this package inside an application, you should use those packages directly in order to reduce interdependencies.

codecov

Copyright Invopop Ltd. 2025. Released publicly under the Apache License Version 2.0. For commercial licenses please contact the dev team at invopop. In order to accept contributions to this library we will require transferring copyrights to Invopop Ltd.

Usage

Go Package

Usage of the XInvoice conversion library is quite straight forward. You must first have a GOBL Envelope including an invoice ready to convert. There are some samples here in the test/data directory. You must then choose the conversion direction and output format. Supported formats:

  • From GOBL:
    • To X-Rechnung (CII syntax)
    • To X-Rechnung (UBL syntax)
    • To ZUGFeRD (CII syntax)
    • To Factur-X (CII syntax)
  • To GOBL:
    • From any of the above formats

The library uses the gobl.cii and gobl.ubl libraries to perform the conversion.

Example of converting a GOBL invoice to XRechnung CII:

package main

import (
    "os"

    "github.com/invopop/gobl"
    xinvoice "github.com/invopop/gobl.xinvoice"
)

func main {
    data, err := os.ReadFile("./test/data/invoice-de-de.json")
    if err != nil {
        panic(err)
    }

    env := new(gobl.Envelope)
    if err := json.Unmarshal(data, env); err != nil {
        panic(err)
    }

    doc, err := xinvoice.ConvertToXRechnungCII(env)
    if err != nil {
        panic(err)
    }

    err = os.WriteFile("invoice-de-de-xrechnung.xml", doc, 0644)
    if err != nil {
        panic(err)
    }
}

Example of converting a X-Invoice file (any format) to GOBL:

package main

import (
    "os"

    "github.com/invopop/gobl"
    xinvoice "github.com/invopop/gobl.xinvoice"
)

func main {
    data, err := os.ReadFile("./test/data/invoice-xrechnung-cii.xml")
    if err != nil {
        panic(err)
    }

    env, err := xinvoice.ConvertToGOBL(data)
    if err != nil {
        panic(err)
    }

    output, err := json.MarshalIndent(env, "", "  ")
    if err != nil {
        panic(err)
    }
}
Command Line

The GOBL to XInvoice tool also includes a command line helper. You can it install manually in your Go environment with:

go install ./cmd/gobl.xinvoice

Usage is very straightforward, with the only flag being the preferred output format: xrechnung-cii, xrechnung-ubl, zugferd or facturx, to be used in case of conversion from GOBL. It is also possible to save the output to a file by adding a path as its second argument:

# XInvoice to GOBL
gobl.xinvoice convert ./test/data/invoice-de-de.xml

# XInvoice to GOBL (with output file)
gobl.xinvoice convert ./test/data/invoice-de-de.xml ./test/data/out/invoice-de-de-gobl.json

# GOBL to XRechnung CII
gobl.xinvoice convert ./test/data/invoice-de-de.json --format xrechnung-cii

# GOBL to Factur-X CII
gobl.xinvoice convert ./test/data/invoice-de-de.json --format facturx

Testing

testify

The library uses testify for testing. To run the tests you can use the command:

go test

Development

Limitations

For limitations during conversion, please see the gobl.ubl and gobl.cii packages directly.

XRechnung

Useful links:

Specifications:

Authentication:

ZUGFeRD

Useful links:

Specifications:

Factur-X

Useful links:

Specifications:

Documentation

Overview

Package xinvoice helps convert GOBL into XRechnung and Factur-X documents and vice versa.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToFacturX

func ConvertToFacturX(env *gobl.Envelope) ([]byte, error)

ConvertToFacturX converts a GOBL envelope into a Factur-X document

func ConvertToGOBL

func ConvertToGOBL(d []byte) (*gobl.Envelope, error)

ConvertToGOBL converts an XRechnung, Factur-X or UBL document into a GOBL envelope

func ConvertToXRechnungCII

func ConvertToXRechnungCII(env *gobl.Envelope) ([]byte, error)

ConvertToXRechnungCII converts a GOBL envelope into an XRechnung document

func ConvertToXRechnungUBL

func ConvertToXRechnungUBL(env *gobl.Envelope) ([]byte, error)

ConvertToXRechnungUBL converts a GOBL envelope into an XRechnung document

func ConvertToZUGFeRD

func ConvertToZUGFeRD(env *gobl.Envelope) ([]byte, error)

ConvertToZUGFeRD converts a GOBL envelope into a ZUGFeRD document

Types

This section is empty.

Directories

Path Synopsis
cmd
gobl.xinvoice command
Package main provides a CLI interface for the library
Package main provides a CLI interface for the library

Jump to

Keyboard shortcuts

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