swissqrinvoice

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 12 Imported by: 0

README

swiss-qr-invoice

GoDoc Go Report Card

Generate Swiss QR Invoices as described in this standard and the style guide. The library uses gopdf via the gopdf-wrapper.

Examples

Example 1

It's also possible to omit the payee and/or the amount, the fields will be replaced with a rectangle field.

Example 2

Use as a CLI app

Or use one of the pre-built binary application you can find on the release page. Download the binary for your system, make it executable and make sure that the binary is in the PATH. You can also compile and install the CLI application via go:

go install github.com/72nd/swiss-qr-invoice/invoice-cli

To create an invoice first initialize a new invoice-YAML:

invoice-cli new invoice.yaml

Then open the YAML file in your editor and adjust the values accordingly:

# Your IBAN
receiver_iban: CH44 3199 9123 0008 8901 2
# Learn more about this field below.
is_qr_iban: true
# Your Name
receiver_name: Robert Schneider AG
# Your Street
receiver_street: Rue du Lac
# Your Street Number
receiver_number: "12"
# Your ZIP Code
receiver_zip_code: "2501"
# Your Place
receiver_place: Biel
# Your Contry as a two letter code
receiver_country: CH
# Your recepients name, omit this if you want a empty payee field
payee_name: Pia-Maria Rutschmann-Schnyder
# Your recepients street, omit this if you want a empty payee field
payee_street: Grosse Marktgasse
# Your recepients street number, omit this if you want a empty payee field
payee_number: "28"
# Your recepients ZIP code, omit this if you want a empty payee field
payee_zip_code: "9400"
# Your recepients place, omit this if you want a empty payee field
payee_place: Rorschach
# Your recepients country, omit this if you want a empty payee field
payee_country: CH
# Invoice referecne, omit this if you haven't got one
reference: 21 00000 00003 13947 14300 09017
# Additional payment information, omit this if you don't need this
additional_info: Rechnung Nr. 3139 für Gartenarbeiten
# The invoice amount, omit this if you want a empty amount field
amount: 3 949.75
// The currenct, can be CHF or EUR
currency: CHF

Some words about the is_qr_iban field: There is a special QR-Invocie IBAN associated with your account (learn more) if you don't use such a special IBAN set this field to false.

After you've configured the file, generate the invoice:

invoice-cli generate -i invoice.yaml -o invoice.pdf

Use as a library

The invoice can be directly saved as PDF or further edited using via the gopdf-wrapper/gopdf element.

import inv "github.com/72nd/swiss-qr-invoice"

invoice := inv.Invoice{
	ReceiverIBAN:    "CH44 3199 9123 0008 8901 2",
	IsQrIBAN:        true,
	ReceiverName:    "Robert Schneider AG",
	ReceiverStreet:  "Rue du Lac",
	ReceiverNumber:  "12",
	ReceiverZIPCode: "2501",
	ReceiverPlace:   "Biel",
	ReceiverCountry: "CH",
	PayeeName:       "Pia-Maria Rutschmann-Schnyder",
	PayeeStreet:     "Grosse Marktgasse",
	PayeeNumber:     "28",
	PayeeZIPCode:    "9400",
	PayeePlace:      "Rorschach",
	PayeeCountry:    "CH",
	Reference:       "21 00000 00003 13947 14300 09017",
	AdditionalInfo:  "Rechnung Nr. 3139 für Gartenarbeiten",
	Amount:          "3 949.75",
	Currency:        "CHF",
}

// Directly save invoice as PDF.
invoice.SaveAsPDF("path/to/invoice.pdf")

// Use the gopdf-wrapper element to further customizing the invoice.
doc, err  := invoice.Doc()
if err != nil {
	log.Panic(err)
}
doc.AddSizedText(10, 10, "Your Invoice", 20)
doc.AddText(10, 20, "This is our invoice for our services")
if err := doc.WritePdf("path/to/invoice.pdf"); err != nil {
	log.Panic(err)
}

Documentation

Overview

Package swissqrinvoice Generate Swiss QR Invoices as described in [this standard](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-de.pdf) and [the style guide](https://www.paymentstandards.ch/dam/downloads/style-guide-de.pdf). The library uses gopdf(https://github.com/signintech/gopdf) via the [gopdf-wrapper](https://github.com/72nd/gopdf-wrapper).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Invoice

type Invoice struct {
	ReceiverIBAN    string `yaml:"receiver_iban" default:"CH44 3199 9123 0008 8901 2"`
	IsQrIBAN        bool   `yaml:"is_qr_iban" default:"true"`
	ReceiverName    string `yaml:"receiver_name" default:"Robert Schneider AG"`
	ReceiverStreet  string `yaml:"receiver_street" default:"Rue du Lac"`
	ReceiverNumber  string `yaml:"receiver_number" default:"12"`
	ReceiverZIPCode string `yaml:"receiver_zip_code" default:"2501"`
	ReceiverPlace   string `yaml:"receiver_place" default:"Biel"`
	ReceiverCountry string `yaml:"receiver_country" default:"CH"`
	PayeeName       string `yaml:"payee_name" default:"Pia-Maria Rutschmann-Schnyder"`
	PayeeStreet     string `yaml:"payee_street" default:"Grosse Marktgasse"`
	PayeeNumber     string `yaml:"payee_number" default:"28"`
	PayeeZIPCode    string `yaml:"payee_zip_code" default:"9400"`
	PayeePlace      string `yaml:"payee_place" default:"Rorschach"`
	PayeeCountry    string `yaml:"payee_country" default:"CH"`
	Reference       string `yaml:"reference" default:"21 00000 00003 13947 14300 09017"`
	AdditionalInfo  string `yaml:"additional_info" default:"Rechnung Nr. 3139 für Gartenarbeiten"`
	Amount          string `yaml:"amount" default:"3 949.75"`
	Currency        string `yaml:"currency" default:"CHF"`
}

Invoice contains all necessary information for the generation of an invoice.

func New added in v1.0.1

func New(useDefaults bool) (*Invoice, error)

New returns a new invoice optional with the default values.

func OpenInvoice added in v0.9.1

func OpenInvoice(path string) (*Invoice, error)

OpenInvoice opens a invoice config YAML file with the given path.

func (Invoice) Doc added in v0.9.1

func (i Invoice) Doc() (*wrapper.Doc, error)

Doc returns the invoice as a gopdf_wrapper.Doc element. This can be used to further customizing the invoice. in contrary to GoPdf() the wrapper doc has more convince functions than using gopdf directly.

func (Invoice) GoPdf added in v0.9.1

func (i Invoice) GoPdf() (*gopdf.GoPdf, error)

GoPdf returns the invoice as a gopdf.GoPdf element. This can be used to further customizing the invoice.

func (Invoice) Save added in v0.9.1

func (i Invoice) Save(path string) error

Save saves the invoice as a YAML file.

func (Invoice) SaveAsPDF

func (i Invoice) SaveAsPDF(path string) error

SaveAsPDF generates the invoice and save it as a PDF.

func (Invoice) SaveQrConent added in v1.0.2

func (i Invoice) SaveQrConent(path string) error

SaveQrConent saves the content of the QR code to a text file for debugging.

Directories

Path Synopsis
Code generated by rice embed-go; DO NOT EDIT.
Code generated by rice embed-go; DO NOT EDIT.

Jump to

Keyboard shortcuts

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