stackin

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Integrate once. Issue everywhere.

Go Go Reference License

API Reference · Go SDK guide


stackin

Go SDK for issuing, consulting and cancelling electronic invoices — a handful of business fields, nothing about certificates, XML, XSD, signing or SOAP. The API resolves all of that from the issuer's own configuration, identified by api_key.

One struct, Invoice — Issue()/Consult()/Cancel(), nothing else to instantiate. Each line item is a br.Product — Description/Amount apply to any document type, NCM/CFOP (plus everything else on Product: CEST, tax groups, presumed credits...) are Brazil-specific and required per item for NFE, ignored for NFSE.

Install

go get github.com/stackin-io/stackin-go-sdk

Usage

Get an api_key from the stackin dashboard — select the issuing company, then Settings → API key (context sdk). One key per issuing company, shown once at creation. The API resolves the issuer (CNPJ, state, address, certificate, environment) entirely from it; nothing about the issuer is ever passed on a call.

package main

import (
	"fmt"

	stackin "github.com/stackin-io/stackin-go-sdk"
	"github.com/stackin-io/stackin-go-sdk/br"
)

func main() {
	client := stackin.NewInvoice(stackin.WithAPIKey("COMPANY_API_KEY"))

	invoice, err := client.Issue(stackin.IssueRequest{
		DocumentType: stackin.NFSE,
		ClientName:   "John Doe",
		TaxID:        "00000000000",
		Items: []br.Product{
			{Description: "Software development", Amount: 5000.00},
		},
	})

	status, err := client.Consult("ACCESS_KEY...", stackin.NFSE)
	_, err = client.Cancel("ACCESS_KEY...", stackin.NFSE, "Typo")

	ncm, cfop := "84713012", "5102"
	invoice, err = client.Issue(stackin.IssueRequest{
		DocumentType: stackin.NFE,
		ClientName:   "Buyer Company Ltd",
		TaxID:        "11111111111111",
		Items: []br.Product{
			{Description: "Test product", Amount: 100.00, NCM: &ncm, CFOP: &cfop},
		},
		RecipientAddress: &stackin.Address{State: "RJ"},
	})
	_ = status
	fmt.Println(invoice, err)
}

RecipientAddress is an Address, but despite the name only .State is read — the rest of the fields aren't sent anywhere yet. It's the actual customer's state, used only to set idDest (interstate vs internal) on NFE — optional, omitting it always produces idDest=1 (internal).

Errors

  • *stackin.APIError — the API responded with a non-2xx status (StatusCode, Detail) — a 401 here means api_key is missing, wrong, or was rotated.
  • *stackin.ConnectionFailedError — the API didn't respond (network/DNS/timeout).
  • *stackin.InvoiceError — Issue()'s Items is empty, or missing NCM/CFOP on an item for NFE.

Building the full fiscal document (issuer data, service code, tax groups, schema-accurate XML) is the API's job — configured once per company, not passed on every call.

Examples

Runnable end-to-end programs in examples/ — simple_issue_nfe and simple_issue_nfse, each with a catalog of realistic line items covering every optional field.

Documentation

Overview

Package stackin is the official Go SDK for the stackin fiscal document API — issue, consult, and cancel Brazilian NF-e and NFS-e electronic invoices with a single API key, no certificates or XML handling required.

See https://docs.stackin.io for the REST API reference and https://docs.stackin.io/blog/go-sdk for the Go SDK guide.

Index

Constants

View Source
const DefaultBaseURL = "https://sdk.stackin.io"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Detail     string
}

func (*APIError) Error

func (e *APIError) Error() string

type Address

type Address struct {
	State        string `json:"state,omitempty"`
	CityCode     string `json:"city_code,omitempty"`
	Street       string `json:"street,omitempty"`
	Number       string `json:"number,omitempty"`
	Neighborhood string `json:"neighborhood,omitempty"`
	City         string `json:"city,omitempty"`
	ZipCode      string `json:"zip_code,omitempty"`
}

type ConnectionFailedError

type ConnectionFailedError struct {
	Message string
}

func (*ConnectionFailedError) Error

func (e *ConnectionFailedError) Error() string

type DocumentType

type DocumentType string
const (
	NFE  DocumentType = "nfe"
	NFSE DocumentType = "nfse"
)

type Environment

type Environment string
const (
	Local      Environment = "local"
	Test       Environment = "test"
	Production Environment = "production"
)

type Invoice

type Invoice struct {
	BaseURL string
	APIKey  string
	Timeout time.Duration
	// contains filtered or unexported fields
}

func NewInvoice

func NewInvoice(opts ...Option) *Invoice

func (*Invoice) Cancel

func (inv *Invoice) Cancel(accessKey string, documentType DocumentType, reason string) (map[string]any, error)

func (*Invoice) Consult

func (inv *Invoice) Consult(accessKey string, documentType DocumentType) (map[string]any, error)

func (*Invoice) Issue

func (inv *Invoice) Issue(req IssueRequest) (map[string]any, error)

type InvoiceError

type InvoiceError struct {
	Message string
}

func (*InvoiceError) Error

func (e *InvoiceError) Error() string

type IssueRequest

type IssueRequest struct {
	DocumentType     DocumentType
	ClientName       string
	TaxID            string
	Items            []br.Product
	RecipientAddress *Address
}

type Option

type Option func(*Invoice)

func WithAPIKey

func WithAPIKey(apiKey string) Option

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithEnvironment

func WithEnvironment(env Environment) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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