lkdr

package module
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 8 Imported by: 1

README

lkdr-api

Go Reference Go Report Go Coverage CodeQL

Клиент для сервиса ФНС Мои Чеки Онлайн.

Пример

Выполнение авторизации (если нужно, код будет запрошен из стандартного ввода) и получение некоторой информации о чеках с выводом в консоль.

Использует RuCaptcha для получения токена капчи для авторизации.

Переменная LKDR_TOKENS_FILE должна содержать путь к файлу с токенами в формате JSON. Если файл не существует, авторизация будет выполнена автоматически, но для этого необходимо задать корректный ключ для RuCaptcha в переменной RUCAPTCHA_KEY.

LKDR_DEVICE_ID можно вытащить прямо с сайта сервиса.

LKDR_USER_AGENT рекомендуется указывать как у реального браузера.

RUCAPTCHA_KEY="key" LKDR_PHONE="79999999999" LKDR_TOKENS_FILE="/tmp/lkdr-tokens.json" LKDR_DEVICE_ID="deviceId" LKDR_USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" go run example/main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDataNotFound added in v1.1.0

func IsDataNotFound(err error) bool

func WithAuthorizer

func WithAuthorizer(ctx context.Context, authorizer Authorizer) context.Context

Types

type Authorizer

type Authorizer interface {
	GetCaptchaToken(ctx context.Context, userAgent, siteKey, pageURL string) (string, error)
	GetConfirmationCode(ctx context.Context, phone string) (string, error)
}

type Brand

type Brand struct {
	Description string  `json:"description"`
	Id          int64   `json:"id"`
	Image       *string `json:"image"`
	Name        string  `json:"name"`
}

type Client

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

func NewClient added in v1.0.0

func NewClient(params ClientParams) (*Client, error)

func (*Client) FiscalData

func (c *Client) FiscalData(ctx context.Context, in *FiscalDataIn) (*FiscalDataOut, error)

func (*Client) Receipt

func (c *Client) Receipt(ctx context.Context, in *ReceiptIn) (*ReceiptOut, error)

type ClientParams added in v1.0.0

type ClientParams struct {
	Phone        string       `validate:"required"`
	Clock        based.Clock  `validate:"required"`
	DeviceID     string       `validate:"required"`
	UserAgent    string       `validate:"required"`
	TokenStorage TokenStorage `validate:"required"`

	Transport http.RoundTripper
}

type Date

type Date time.Time

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

func (Date) Time

func (d Date) Time() time.Time

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

type DateTime

type DateTime time.Time

func (DateTime) MarshalJSON

func (dt DateTime) MarshalJSON() ([]byte, error)

func (DateTime) Time

func (dt DateTime) Time() time.Time

func (*DateTime) UnmarshalJSON

func (dt *DateTime) UnmarshalJSON(data []byte) error

type DateTimeMilliOffset

type DateTimeMilliOffset time.Time

func (DateTimeMilliOffset) MarshalJSON

func (dt DateTimeMilliOffset) MarshalJSON() ([]byte, error)

func (DateTimeMilliOffset) Time

func (dt DateTimeMilliOffset) Time() time.Time

func (*DateTimeMilliOffset) UnmarshalJSON

func (dt *DateTimeMilliOffset) UnmarshalJSON(data []byte) error

type DateTimeTZ

type DateTimeTZ time.Time

func (DateTimeTZ) MarshalJSON

func (dt DateTimeTZ) MarshalJSON() ([]byte, error)

func (DateTimeTZ) Time

func (dt DateTimeTZ) Time() time.Time

func (*DateTimeTZ) UnmarshalJSON

func (dt *DateTimeTZ) UnmarshalJSON(data []byte) error

type Error

type Error struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
}

func (Error) Error

func (e Error) Error() string

type ErrorCode

type ErrorCode string
const (
	SmsVerificationNotExpired ErrorCode = "registration.sms.verification.not.expired"
	BlockedCaptcha            ErrorCode = "blocked.captcha"
	ReceiptFiscalDataNotFound ErrorCode = "receipt.fiscaldata.not.found.dr"
)

type FiscalDataIn

type FiscalDataIn struct {
	Key string `json:"key"`
}

type FiscalDataItem

type FiscalDataItem struct {
	Name         string        `json:"name"`
	Nds          int           `json:"nds"`
	PaymentType  int           `json:"paymentType"`
	Price        float64       `json:"price"`
	ProductType  int           `json:"productType"`
	ProviderData *ProviderData `json:"providerData"`
	ProviderInn  *string       `json:"providerInn"`
	Quantity     float64       `json:"quantity"`
	Sum          float64       `json:"sum"`
}

type FiscalDataOut

type FiscalDataOut struct {
	BuyerAddress            string           `json:"buyerAddress"`
	CashTotalSum            float64          `json:"cashTotalSum"`
	CreditSum               float64          `json:"creditSum"`
	DateTime                DateTime         `json:"dateTime"`
	EcashTotalSum           float64          `json:"ecashTotalSum"`
	FiscalDocumentFormatVer string           `json:"fiscalDocumentFormatVer"`
	FiscalDocumentNumber    int64            `json:"fiscalDocumentNumber"`
	FiscalDriveNumber       string           `json:"fiscalDriveNumber"`
	FiscalSign              string           `json:"fiscalSign"`
	InternetSign            *int             `json:"internetSign"`
	Items                   []FiscalDataItem `json:"items"`
	KktRegId                string           `json:"kktRegId"`
	MachineNumber           *string          `json:"machineNumber"`
	Nds10                   *float64         `json:"nds10"`
	Nds18                   *float64         `json:"nds18"`
	OperationType           int              `json:"operationType"`
	Operator                *string          `json:"operator"`
	PrepaidSum              float64          `json:"prepaidSum"`
	ProvisionSum            float64          `json:"provisionSum"`
	RequestNumber           int64            `json:"requestNumber"`
	RetailPlace             *string          `json:"retailPlace"`
	RetailPlaceAddress      *string          `json:"retailPlaceAddress"`
	ShiftNumber             int64            `json:"shiftNumber"`
	TaxationType            int              `json:"taxationType"`
	TotalSum                float64          `json:"totalSum"`
	User                    *string          `json:"user"`
	UserInn                 string           `json:"userInn"`
}

type ProviderData

type ProviderData struct {
	ProviderPhone []string `json:"providerPhone"`
	ProviderName  string   `json:"providerName"`
}

type Receipt

type Receipt struct {
	BrandId              *int64   `json:"brandId"`
	Buyer                string   `json:"buyer"`
	BuyerType            string   `json:"buyerType"`
	CreatedDate          DateTime `json:"createdDate"`
	FiscalDocumentNumber string   `json:"fiscalDocumentNumber"`
	FiscalDriveNumber    string   `json:"fiscalDriveNumber"`
	Key                  string   `json:"key"`
	KktOwner             string   `json:"kktOwner"`
	KktOwnerInn          string   `json:"kktOwnerInn"`
	ReceiveDate          DateTime `json:"receiveDate"`
	TotalSum             string   `json:"totalSum"`
}

type ReceiptIn

type ReceiptIn struct {
	DateFrom *Date   `json:"dateFrom"`
	DateTo   *Date   `json:"dateTo"`
	Inn      *string `json:"inn"`
	KktOwner string  `json:"kktOwner"`
	Limit    int     `json:"limit"`
	Offset   int     `json:"offset"`
	OrderBy  string  `json:"orderBy"`
}

type ReceiptOut

type ReceiptOut struct {
	Brands   []Brand   `json:"brands"`
	Receipts []Receipt `json:"receipts"`
	HasMore  bool      `json:"hasMore"`
}

type TokenStorage

type TokenStorage interface {
	LoadTokens(ctx context.Context, phone string) (*Tokens, error)
	UpdateTokens(ctx context.Context, phone string, tokens *Tokens) error
}

type Tokens

type Tokens struct {
	RefreshToken          string      `json:"refreshToken"`
	RefreshTokenExpiresIn *DateTimeTZ `json:"refreshTokenExpiresIn,omitempty"`
	Token                 string      `json:"token"`
	TokenExpireIn         DateTimeTZ  `json:"tokenExpireIn"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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