regonapi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 9 Imported by: 0

README

Go REGON API GoDoc

This project is Go interface to Polish National Official Business Register (REGON) database. More information here. Library is a thin wrapper for official SOAP webservice API. Check technical documentation here.

Features

  • search for business entities by NIP (tax id), REGON (statistical numbers) or KRS (National Court Register)
  • get system status
  • get basic reports
  • production and test (sandbox) environments
  • implements BIR1 version 1.1
  • context-aware HTTP requests

To access production environment you need user key issued by REGON administrators.

Installation

go get github.com/orkanap/regonapi

Basic usage

Find entities by NIP.

// New client, empty key connects to test envinroment
regonsvc := regonapi.NewClient(context.Background(), os.Getenv("REGON_API_KEY"))

err := regonsvc.Login()
if err != nil {
    log.Fatal(err)
}
defer regonsvc.Logout()

entities, err := regonsvc.SearchByNIP("5261040828")
if err != nil {
    log.Fatal(err)
}

for _, entity := range entities {
    fmt.Println("[", entity.Type, "]")
    fmt.Println("NIP:", entity.NIP, "REGON:", entity.REGON)
    fmt.Println(entity.Name)
    fmt.Println(entity.Street, entity.PropertyNumber, entity.ApartmentNumber)
    fmt.Println(entity.PostalCode, entity.City)
}

Get more details

// List PKDs
pkds, err := regonsvc.LegalPersonPKDList("340771731")
if err != nil {
    log.Fatal(err)
}

fmt.Println("PKD:")
for _, pkd := range pkds {
    fmt.Println(pkd.Code, pkd.Name)
}

For complete example check ./example folder, integration_test.go source file or godoc.

Tests

Integration tests make http requests to sandbox endpoint. Beware of API quotas. To perform tests make test or make test-unit for unit tests only.

Limitations

  • searching by group of identifiers is not implemented
  • only basic reports are implemented
  • no control of NIP, REGON, KRS identifiers

License

The MIT License (MIT) - see LICENSE.md for more details

Documentation

Overview

Package regonapi provides interface for REGON API (Polish National Official Business Register). This is a thin wrapper for official SOAP webservice, BIR1 version 1.1.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidKey is returned by Login
	ErrInvalidKey = errors.New("invalid API key")

	// ErrSessionNotStarted is returned when session not started. Login to start
	// a new session.
	ErrSessionNotStarted = errors.New("session not started")

	// ErrNoDataFound is returned by search API when no data is found in the
	// REGON database
	ErrNoDataFound = errors.New("no data found for the specified search criteria")

	// ErrEmptyResult is returned when API call returns an empty body. Check
	// session status and if session has expired login again.
	ErrEmptyResult = errors.New("empty result")
)

Functions

This section is empty.

Types

type Client

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

Client for REGON API webservice

func NewClient

func NewClient(ctx context.Context, key string) *Client

NewClient returns new REGON API client. For an empty key client connects to test endpoint (with test key). Provide context to control the underlying HTTP requests.

func (*Client) LegalPersonDetails

func (c *Client) LegalPersonDetails(regon string) (*LegalPerson, error)

LegalPersonDetails returns details of legal person (type P) or nil and error. Entity is identified by REGON.

func (*Client) LegalPersonLocalUnitPKDList added in v1.0.0

func (c *Client) LegalPersonLocalUnitPKDList(regon14 string) ([]LegalPersonLocalUnitPKD, error)

LegalPersonLocalUnitPKDList returns list of PKD for legal person or nil and error. Entity is identified by REGON14.

func (*Client) LegalPersonPKDList

func (c *Client) LegalPersonPKDList(regon string) ([]LegalPersonPKD, error)

LegalPersonPKDList returns list of PKD for legal person or nil and error. Entity is identified by REGON.

func (*Client) Login

func (c *Client) Login() error

Login starts a new session

func (*Client) Logout

func (c *Client) Logout() error

Logout ends session

func (*Client) NaturalPersonDetails

func (c *Client) NaturalPersonDetails(regon string) (*NaturalPerson, error)

NaturalPersonDetails returns details of natural person running economic activity (type F) or nil and error. Entity is identified by REGON.

func (*Client) NaturalPersonPKDList

func (c *Client) NaturalPersonPKDList(regon string) ([]NaturalPersonPKD, error)

NaturalPersonPKDList returns list of PKD for natural person or nil and error. Entity is identified by REGON.

func (*Client) SearchByKRS

func (c *Client) SearchByKRS(krs string) ([]Entity, error)

SearchByKRS searches the REGON database by KRS. Returns list of entities or nil and error. Input parameter 10 digits string.

func (*Client) SearchByNIP

func (c *Client) SearchByNIP(nip string) ([]Entity, error)

SearchByNIP searches the REGON database by NIP. Returns list of entities or nil and error. Input parameter 10 digits string.

func (*Client) SearchByREGON

func (c *Client) SearchByREGON(regon string) ([]Entity, error)

SearchByREGON searches the database by REGON. Returns list of entities or nil and error. Input parameter must be normalized: 9 or 14 digits.

func (*Client) SessionStatus

func (c *Client) SessionStatus() (string, error)

SessionStatus returns current session status: 1 = session active, 0 = session no longer active

type Entity

type Entity struct {
	ErrorCode       int    `xml:"ErrorCode"`
	REGON           string `xml:"Regon"`
	NIP             string `xml:"Nip"`
	StatusNIP       string `xml:"StatusNip"` // "", Uchylony, Unieważniony
	Name            string `xml:"Nazwa"`
	Province        string `xml:"Wojewodztwo"`
	District        string `xml:"Powiat"`
	Community       string `xml:"Gmina"`
	City            string `xml:"Miejscowosc"`
	PostalCode      string `xml:"KodPocztowy"`
	Street          string `xml:"Ulica"`
	PropertyNumber  string `xml:"NrNieruchomosci"`
	ApartmentNumber string `xml:"NrLokalu"`

	// (P) legal entity (F) natural person running economic activity (LP) local
	// unit of the legal entity (LF) local unit of a natural person
	Type            string `xml:"Typ"`
	SilosID         string `xml:"SilosID"`
	ActivityEndDate string `xml:"DataZakonczeniaDzialalnosci"`
	PostCity        string `xml:"MiejscowoscPoczty"`
}

Entity record in the REGON database describes business entity

type LegalPerson

type LegalPerson struct {
	ErrorCode             int    `xml:"ErrorCode"`
	REGON9                string `xml:"praw_regon9"`
	NIP                   string `xml:"praw_nip"`
	StatusNIP             string `xml:"praw_statusNip"` // "", Uchylony, Unieważniony
	Name                  string `xml:"praw_nazwa"`
	ShortName             string `xml:"praw_nazwaSkrocona"`
	RegistrationNumberReg string `xml:"praw_numerWRejestrzeEwidencji"`
	RegistrationDateReg   string `xml:"praw_dataWpisuDoRejestruEwidencji"`
	CreationDate          string `xml:"praw_dataPowstania"`
	StartDate             string `xml:"praw_dataRozpoczeciaDzialalnosci"`
	RegistrationDate      string `xml:"praw_dataWpisuDoRegon"`
	HoldDate              string `xml:"praw_dataZawieszeniaDzialalnosci"`
	RenevalDate           string `xml:"praw_dataWznowieniaDzialalnosci"`
	RemovalDate           string `xml:"praw_dataSkresleniaZRegon"`
	LastUpdateDate        string `xml:"praw_dataZaistnieniaZmiany"`
	EndDate               string `xml:"praw_dataZakonczeniaDzialalnosci"`
	Phone                 string `xml:"praw_numerTelefonu"`
	ExtPhone              string `xml:"praw_numerWewnetrznyTelefonu"`
	Fax                   string `xml:"praw_numerFaksu"`
	Email                 string `xml:"praw_adresEmail"`
	WWW                   string `xml:"praw_adresStronyinternetowej"`
	NumberOfLocalUnits    int    `xml:"praw_liczbaJednLokalnych"`
}

LegalPerson holds details of entities type (P)

type LegalPersonLocalUnitPKD added in v1.0.0

type LegalPersonLocalUnitPKD struct {
	ErrorCode int    `xml:"ErrorCode"`
	Code      string `xml:"lokpraw_pkdKod"`
	Name      string `xml:"lokpraw_pkdNazwa"`
	Primary   string `xml:"lokpraw_pkdPrzewazajace"`
}

LegalPersonLocalUnitPKD holds information of PKD (classification of business activity) for local unit of legal person (type LP). Local units are identified by REGON14 (14 digits).

type LegalPersonPKD

type LegalPersonPKD struct {
	ErrorCode int    `xml:"ErrorCode"`
	Code      string `xml:"praw_pkdKod"`
	Name      string `xml:"praw_pkdNazwa"`
	Primary   string `xml:"praw_pkdPrzewazajace"`
}

LegalPersonPKD holds information of PKD (classification of business activity) for legal person

type NaturalPerson

type NaturalPerson struct {
	ErrorCode             int    `xml:"ErrorCode"`
	REGON9                string `xml:"fiz_regon9"`
	NIP                   string `xml:"fiz_nip"`
	StatusNIP             string `xml:"fiz_statusNip"` // "", Uchylony, Unieważniony
	LastName              string `xml:"fiz_nazwisko"`
	FirstName1            string `xml:"fiz_imie1"`
	FirstName2            string `xml:"fiz_imie2"`
	REGONRegistrationDate string `xml:"fiz_dataWpisuDoREGON"`
	LastUpdateDate        string `xml:"fiz_dataZaistnieniaZmiany"`
	RemovalDate           string `xml:"fiz_dataSkresleniaPodmiotuZRegon"`
	BasicLegalFormCode    string `xml:"fiz_podstawowaFormaPrawna_Symbol"`
	SpecificLegalFormCode string `xml:"fiz_szczegolnaFormaPrawna_Symbol"`
	OwnershipFormCode     string `xml:"fiz_formaWlasnosci_Symbol"`
	BasicLegalFormName    string `xml:"fiz_podstawowaFormaPrawna_Nazwa"`
	SpecificLegalFormName string `xml:"fiz_szczegolnaFormaPrawna_Nazwa"`
	OwnershipFormName     string `xml:"fiz_formaWlasnosci_Nazwa"`
	NumberOfLocalUnits    int    `xml:"fiz_liczbaJednLokalnych"`
}

NaturalPerson holds details of entities type (F)

type NaturalPersonPKD

type NaturalPersonPKD struct {
	ErrorCode   int    `xml:"ErrorCode"`
	Code        string `xml:"fiz_pkd_Kod"`
	Name        string `xml:"fiz_pkd_Nazwa"`
	Primary     string `xml:"fiz_pkd_Przewazajace"`
	SilosID     int    `xml:"fiz_SilosID"`
	SilosCode   string `xml:"fiz_Silos_Symbol"`
	RemovalDate string `xml:"fiz_dataSkresleniaDzialalnosciZRegon"`
}

NaturalPersonPKD holds information of PKD (classification of business activity) for natural person

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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