gosii

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 16 Imported by: 0

README

Chilean RUT Lookup Library (Sii)

This is a Golang library for fetching the name and commercial activities of a Chilean citizen using their RUT (Rol Único Tributario) from the Servicio de Impuestos Internos (SII) of Chile.

Installation

Use the go get command to install the library:

go get github.com/Eitol/gosii

Usage

// Print the name of a person given their RUT
package main

import (
	"fmt"
	"github.com/Eitol/gosii"	
	"strconv"
)

func main() {
	rutExample := "5.126.663-3" // RUT de Sebastian Piñera
	ssiClient := gosii.NewClient()
	citizen, err := ssiClient.GetNameByRUT(rutExample)
    if err != nil {
        panic(err)
    }
	fmt.Println(citizen.Name)
	// Output: MIGUEL JUAN SEBASTIAN PINERA ECHENIQUE
	
	fmt.Print(citizen.Activities[0])
	// Output: 829900
	
	// Note: "829900" is the code of "OTRAS ACTIVIDADES DE SERVICIOS DE APOYO A LAS EMPRESAS N.C.P"	
}   

How it Works

The library works by making HTTP requests to the SII's web services and parsing the responses. The flow can be summarized in the following steps:

1- Fetch a captcha challenge from SII's service (necessary for making requests).

2- Send a POST request to SII's service with the provided RUT and the fetched captcha.

3- Parse the HTML response to extract the citizen's name and associated commercial activities.

A crucial step in this process is fetching and solving the captcha challenge.

To solve the captcha, the library decodes a base64 encoded string provided by SII's service, which includes the captcha solution.

flow

Note

The Software is provided for academic purposes only. Commercial use is not permitted.

Documentation

Index

Constants

View Source
const (
	XpathRazonSocial = "html body div div:nth-child(4)"
	XpathActivities  = "html body div table tr"
)

Variables

View Source
var ErrCaptcha = errors.New("not found")
View Source
var ErrMaxCaptchaAttempts = errors.New("max captcha attempts reached")
View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Captcha

type Captcha struct {
	Text     string `json:"text"`
	Solution string `json:"solution"`
}

type CaptchaResp

type CaptchaResp struct {
	TxtCaptcha string `json:"txtCaptcha"`
}

func (CaptchaResp) MarshalEasyJSON added in v1.0.1

func (v CaptchaResp) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CaptchaResp) MarshalJSON added in v1.0.1

func (v CaptchaResp) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CaptchaResp) UnmarshalEasyJSON added in v1.0.1

func (v *CaptchaResp) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CaptchaResp) UnmarshalJSON added in v1.0.1

func (v *CaptchaResp) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Citizen

type Citizen struct {
	Rut        string               `json:"rut"`
	Run        string               `json:"run"`
	Name       string               `json:"name"`
	Activities []CommercialActivity `json:"activities"`
}

func (Citizen) MarshalEasyJSON added in v1.0.1

func (v Citizen) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Citizen) MarshalJSON added in v1.0.1

func (v Citizen) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Citizen) UnmarshalEasyJSON added in v1.0.1

func (v *Citizen) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Citizen) UnmarshalJSON added in v1.0.1

func (v *Citizen) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Client

type Client interface {
	GetNameByRUT(rut string) (*Citizen, error)
}

func NewClient

func NewClient(opts *Opts) Client

type CommercialActivity

type CommercialActivity struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

func (CommercialActivity) MarshalEasyJSON added in v1.0.1

func (v CommercialActivity) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CommercialActivity) MarshalJSON added in v1.0.1

func (v CommercialActivity) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CommercialActivity) UnmarshalEasyJSON added in v1.0.1

func (v *CommercialActivity) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CommercialActivity) UnmarshalJSON added in v1.0.1

func (v *CommercialActivity) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Opts added in v0.1.0

type Opts struct {
	OnNewCaptcha func(captcha *Captcha)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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