Documentation
¶
Overview ¶
Package fiskit is the official Go client for the FisKit API: Argentine electronic invoices with ARCA (formerly AFIP) in a single request. It has no dependencies besides the standard library.
client, err := fiskit.New("") // reads FISKIT_API_KEY
invoice, err := client.Invoices.Create(ctx, map[string]any{
"voucher_type": "invoice_c",
"amounts": map[string]any{"total": 1500},
}, "order-8812")
Index ¶
- Constants
- Variables
- type Address
- type AuthorityMessage
- type Client
- type Error
- type Event
- type Invoice
- type InvoicesService
- func (s *InvoicesService) Create(ctx context.Context, body any, idempotencyKey string) (*Invoice, error)
- func (s *InvoicesService) Email(ctx context.Context, id, email string) (string, error)
- func (s *InvoicesService) PDF(ctx context.Context, id string) ([]byte, error)
- func (s *InvoicesService) Retrieve(ctx context.Context, id string) (*Invoice, error)
- type Option
- type Taxpayer
- type TaxpayersService
Constants ¶
const DefaultWebhookTolerance = 5 * time.Minute
DefaultWebhookTolerance is how old a delivery may be before it is rejected.
const Version = "0.1.1"
Version of this library, sent in the User-Agent header.
Variables ¶
var ErrInvalidWebhook = errors.New("fiskit: invalid webhook")
ErrInvalidWebhook is returned (wrapped) when a delivery cannot be trusted.
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct {
Street string `json:"street"`
City string `json:"city"`
Province string `json:"province"`
PostalCode string `json:"postal_code"`
}
Address is a fiscal address from the ARCA registry.
type AuthorityMessage ¶
AuthorityMessage is an observation or error returned by ARCA.
type Client ¶
type Client struct {
Invoices *InvoicesService
Taxpayers *TaxpayersService
// contains filtered or unexported fields
}
Client talks to the FisKit API. It is safe for concurrent use.
type Error ¶
type Error struct {
Status int
Type string
Code string
Message string
Param string
RequestID string
Body []byte
}
Error is an error answered by the API, or a network failure (Status 0, Code "network"). Branch on Code, which is stable; Message is meant for people.
type Event ¶
type Event struct {
ID string `json:"id"`
Object string `json:"object"`
Type string `json:"type"` // invoice.authorized, invoice.rejected or invoice.failed
Created time.Time `json:"created"`
Livemode bool `json:"livemode"`
Data struct {
Object Invoice `json:"object"`
} `json:"data"`
}
Event is a webhook delivery. Data.Object is the invoice with the same fields as the API response.
func VerifyWebhook ¶
VerifyWebhook checks the Standard Webhooks signature of a delivery and returns the event. Pass the raw body exactly as received, before decoding it, and the secret (whsec_...) from the dashboard.
type Invoice ¶
type Invoice struct {
ID string `json:"id"`
Object string `json:"object"`
Status string `json:"status"` // pending, processing, authorized, rejected, reconciling or failed
VoucherType string `json:"voucher_type"`
PointOfSale int `json:"point_of_sale"`
Number *int64 `json:"number"` // nil until authorized
CAE string `json:"cae"`
CAEDueDate string `json:"cae_due_date"` // YYYY-MM-DD
AuthorityObservations []AuthorityMessage `json:"authority_observations"`
AuthorityErrors []AuthorityMessage `json:"authority_errors"`
Raw map[string]any `json:"-"`
}
Invoice is an invoice as the API returns it. Raw holds every field of the response.
func (*Invoice) Authorized ¶
Authorized reports whether ARCA authorized the invoice (it has a number and a CAE).
type InvoicesService ¶
type InvoicesService struct {
// contains filtered or unexported fields
}
InvoicesService issues and looks up invoices.
func (*InvoicesService) Create ¶
func (s *InvoicesService) Create(ctx context.Context, body any, idempotencyKey string) (*Invoice, error)
Create issues an invoice. body is any value that encodes to the request JSON (a map or a struct).
Pass your own idempotencyKey, for example your sale id: retrying with it never issues a second invoice. When empty, one is generated so the automatic retries are still safe.
A 202 is not an error: the returned invoice is Pending and FisKit finishes it in the background.
func (*InvoicesService) Email ¶
Email sends the PDF to the customer and returns the address it went to. With an empty email it goes to the receiver.email of the invoice.
type Option ¶
type Option func(*Client)
Option customizes a Client.
func WithBaseURL ¶
WithBaseURL points the client to another address, for example a mock in tests.
func WithHTTPClient ¶
WithHTTPClient replaces the HTTP client (timeouts, proxies, instrumentation).
func WithMaxRetries ¶
WithMaxRetries sets how many times a failed request is retried (2 by default). Only requests that are safe to repeat are retried: GETs and POSTs with an idempotency key.
type Taxpayer ¶
type Taxpayer struct {
CUIT int64 `json:"cuit"`
Name string `json:"name"`
Type string `json:"type"` // person or company
Active bool `json:"active"`
VATCondition string `json:"vat_condition"`
ReceiverVATConditionID int `json:"receiver_vat_condition_id"` // send it as receiver.vat_condition_id
MonotributoCategory *string `json:"monotributo_category"`
Address *Address `json:"address"`
Raw map[string]any `json:"-"`
}
Taxpayer is a CUIT as the ARCA registry describes it.
type TaxpayersService ¶
type TaxpayersService struct {
// contains filtered or unexported fields
}
TaxpayersService queries the ARCA registry.