go_fakturoid

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: MIT Imports: 16 Imported by: 0

README

go-fakturoid

Connecting to API

package main

import (
	"fmt"
	go_fakturoid "github.com/MLJ-solutions/go-fakturoid"
)

func main() {
	client, _ := go_fakturoid.New(&go_fakturoid.Options{
		Creds: go_fakturoid.NewCredentials("EMAIL", "SLUG", "PRIVATE KEY"),
	})

	fmt.Println(client)
}

Full Example of creating invoice

package main

import (
	"fmt"
	. "github.com/MLJ-solutions/go-fakturoid"
	"github.com/MLJ-solutions/go-fakturoid/models"
	"log"
	"time"
)

func main() {
	client, _ := New(&Options{
		Creds: NewCredentials("EMAIL", "SLUG", "PRIVATE KEY"),
	})
	
	subject, err := client.CreateSubject(models.Subject{
		Name:           "Name",
		Street:         "Ulice adresa",
		City:           "City",
		Zip:            "12345",
		Country:        "CZ",
		RegistrationNo: "123456789",
		FullName:       "Full name",
		Email:          "developer@mlj.solutions",
	})
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(subject)

	createInvoice := models.Invoice{
		SubjectId:             subject.Id,
		Currency:              models.CurrencyCZK,
		PaymentMethod:         models.PaymentMethodCard,
		Due:                   14,
		IssuedOn:              models.FakturoidDate(time.Now()),
		TaxableFulfillmentDue: models.FakturoidDate(time.Now()),
		Lines:                 []models.InvoiceLine{{Name: "name", Quantity: 1, UnitName: "ks", UnitPrice: 100, VatRate: 15}},
	}

	invoice, err := client.CreateInvoice(createInvoice)
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(invoice)
}

package main

import (
	go_fakturoid "github.com/MLJ-solutions/go-fakturoid"
	"log"
)

func main() {
	client, _ := go_fakturoid.New(&go_fakturoid.Options{
		Creds: go_fakturoid.NewCredentials("EMAIL", "SLUG", "PRIVATE KEY"),
	})

	log.Println(client)

	account, err := client.Account()
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(account)
}

Full Example of getting account setting

package main

import (
	go_fakturoid "github.com/MLJ-solutions/go-fakturoid"
	"log"
)

func main() {
	client, _ := go_fakturoid.New(&go_fakturoid.Options{
		Creds: go_fakturoid.NewCredentials("EMAIL", "SLUG", "PRIVATE KEY"),
	})

	log.Println(client)

	account, err := client.Account()
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(account)
}

Documentation

Index

Constants

View Source
const (
	InvoiceQuerySince        = "since"
	InvoiceQueryUntil        = "until"
	InvoiceQueryUpdatedSince = "updated_since"
	InvoiceQueryUpdatedUntil = "updated_until"
	InvoiceQueryNumber       = "number"
	InvoiceQueryStatus       = "status"
	InvoiceQueryInvoiceId    = "invoice_id"
	InvoiceQueryCustomId     = "custom_id"
	InvoiceQuerySubjectId    = "subject_id"
)
View Source
const BasicUrl = "https://app.fakturoid.cz/api/v2/accounts/"

Variables

View Source
var DefaultTransport = func() (*http.Transport, error) {
	tr := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		MaxIdleConns:          256,
		MaxIdleConnsPerHost:   16,
		ResponseHeaderTimeout: time.Minute,
		IdleConnTimeout:       time.Minute,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 10 * time.Second,

		DisableCompression: true,
	}

	tr.TLSClientConfig = &tls.Config{

		MinVersion: tls.VersionTLS12,
	}

	return tr, nil
}

DefaultTransport - this default transport is similar to http.DefaultTransport but with additional param DisableCompression is set to true to avoid decompressing content with 'gzip' encoding.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(opts *Options) (*Client, error)

New - instantiate minio client with options

func (Client) Account

func (c Client) Account() (models.Account, error)

reqeuest on /account.json

func (Client) BankAccounts

func (c Client) BankAccounts() ([]models.BankAccount, error)

request on /bank_accounts.json

func (Client) CreateInvoice

func (c Client) CreateInvoice(Invoice models.Invoice) (models.Invoice, error)

create Invoice on /invoices.json

func (Client) CreateSubject

func (c Client) CreateSubject(subject models.Subject) (models.Subject, error)

create subject on /subjects.json

func (Client) DeleteInvoice added in v0.0.3

func (c Client) DeleteInvoice(Id int) (bool, error)

delete Invoice on /invoices/{ID}.json

func (*Client) EndpointURL

func (c *Client) EndpointURL() *url.URL

EndpointURL returns the URL of the fakturoid.

func (Client) InvoiceEvent added in v0.0.3

func (c Client) InvoiceEvent(Id int, Event *models.InvoiceEvent) (bool, error)

delete Invoice on /invoices/{ID}.json

func (Client) Invoices

func (c Client) Invoices(invoiceFilters InvoiceFilter) ([]models.Invoice, error)

request on /invoices.json TODO paging

func (Client) InvoicesSearch

func (c Client) InvoicesSearch(query string) ([]models.Invoice, error)

request on /Invoices/search.json?query=

func (Client) Subjects

func (c Client) Subjects() ([]models.Subject, error)

request on /subjects.json TODO paging

func (Client) SubjectsSearch

func (c Client) SubjectsSearch(query string) ([]models.Subject, error)

request on /subjects/search.json?query=

func (Client) UpdateInvoice added in v0.0.3

func (c Client) UpdateInvoice(Invoice models.Invoice, Id int) (models.Invoice, error)

update Invoice on /invoices/{ID}.json

type Credentials

type Credentials struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCredentials

func NewCredentials(email string, slug string, key string) *Credentials

type ErrorResponse

type ErrorResponse struct {
	Errors map[string][]string
}

TODO refine

func ToErrorResponse

func ToErrorResponse(err error) ErrorResponse

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

Error - Returns error string.

type InvoiceFilter

type InvoiceFilter struct {
	Since        *time.Time
	Until        *time.Time
	UpdatedSince *time.Time
	UpdatedUntil *time.Time
	Number       string
	Status       string
	InvoiceId    int
	SubjectId    int
	CustomId     string
}

structure to help filter invoices

func InvoiceFilterFromSubject

func InvoiceFilterFromSubject(subject models.Subject) InvoiceFilter

type Options

type Options struct {
	Transport http.RoundTripper
	Creds     *Credentials
}

type Value

type Value struct {
	Slug   string
	Email  string
	ApiKey string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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