lknpd

package module
v0.0.0-...-4304b6f Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 7 Imported by: 0

README

go-lknpd

Неофициальный клиент HTTP-API сайта Мой налог для самозанятых. Используется метод логина через мобильный телефон. Для генерации id девайса и refresh-token используйте first-login:

    go run first-login/main.go

Вводим телефон (в формате 79XXXXXXXXX), код подтверждения из СМС.

Использование

    // Важно указать нужный часовой пояс, чтобы правильно формировалось время в чеке
    client := lknpd.NewClient(
		"Asia/Barnaul",
		os.Getenv("DEVICE_ID"),
		os.Getenv("REFRESH_TOKEN"))

    // Создание чека
	saleId, err := client.CreateSale(lknpd.CreateSaleRequest{
		PaymentType: lknpd.Cash,
		Services: []*lknpd.Service{
			{
				Label:    "Информационная услуга",
				Amount:   decimal.NewFromFloat(50.5),
				Quantity: 1,
			},
		},
		Client: &lknpd.Customer{IncomeType: lknpd.Individual}})
	if err != nil {
		log.Panic(err)
	}

    // Удаление чека
	if err = client.CancelSale(lknpd.CancelSaleRequest{
		CancelType:  lknpd.Cancel,
		ReceiptUUID: saleId,
	}); err != nil {
		log.Panic(err)
	}
Источники и другие реализации

Автоматизация для самозанятых: как интегрировать налог с IT проектом

JS lib alexstep/moy-nalog

PHP lib shoman4eg/moy-nalog

Go lib (с авторизация по логин/пароль) shoman4eg/go-moy-nalog

Documentation

Index

Constants

View Source
const (
	Individual    CustomerType = "FROM_INDIVIDUAL"
	LegalEntity   CustomerType = "FROM_LEGAL_ENTITY"
	ForeignAgency CustomerType = "FROM_FOREIGN_AGENCY"

	Cash    PaymentType = "CASH"
	Account PaymentType = "ACCOUNT"

	Cancel CancelType = "Чек сформирован ошибочно"
	Refund CancelType = "Возврат средств"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelSaleRequest

type CancelSaleRequest struct {
	RequestTime   time.Time  `json:"requestTime"`
	OperationTime time.Time  `json:"operationTime"`
	CancelType    CancelType `json:"comment"`
	ReceiptUUID   string     `json:"receiptUuid"`
	PartnerCode   string     `json:"partnerCode"`
}

type CancelType

type CancelType string

type Client

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

func NewClient

func NewClient(timezone, deviceId, refreshToken string) *Client

func (*Client) CancelSale

func (o *Client) CancelSale(sale CancelSaleRequest) (err error)

func (*Client) CheckTokenExpireIn

func (o *Client) CheckTokenExpireIn()

func (*Client) CreateSale

func (o *Client) CreateSale(sale CreateSaleRequest) (orderId string, err error)

func (*Client) RefreshToken

func (o *Client) RefreshToken() (err error)

type CreateSaleRequest

type CreateSaleRequest struct {
	PaymentType                     PaymentType `json:"paymentType"`
	Client                          *Customer   `json:"client"`
	RequestTime                     time.Time   `json:"requestTime"`
	OperationTime                   time.Time   `json:"operationTime"`
	Services                        []*Service  `json:"services"`
	TotalAmount                     string      `json:"totalAmount"`
	IgnoreMaxTotalIncomeRestriction bool        `json:"ignoreMaxTotalIncomeRestriction"`
}

type CreateSaleResponse

type CreateSaleResponse struct {
	ApprovedReceiptUUID string `json:"approvedReceiptUuid"`
}

type Customer

type Customer struct {
	ContactPhone string       `json:"contactPhone"`
	DisplayName  string       `json:"displayName"`
	IncomeType   CustomerType `json:"incomeType"`
	Inn          string       `json:"inn"`
}

type CustomerType

type CustomerType string

type Device

type Device struct {
	SourceDeviceId string `json:"sourceDeviceId"`
	SourceType     string `json:"sourceType"`
	AppVersion     string `json:"appVersion"`
	MetaDetails    struct {
		UserAgent string `json:"userAgent"`
	} `json:"metaDetails"`
}

func NewDevice

func NewDevice(deviceId string) *Device

type LoginRequest

type LoginRequest struct {
	Phone               string `json:"phone"`
	RequireTpToBeActive bool   `json:"requireTpToBeActive"`
}

type LoginResponse

type LoginResponse struct {
	ChallengeToken string    `json:"challengeToken"`
	ExpireDate     time.Time `json:"expireDate"`
	ExpireIn       int       `json:"expireIn"`
}

func LoginByPhone

func LoginByPhone(payload LoginRequest) (*LoginResponse, error)

type PaymentType

type PaymentType string

type RefreshTokenRequest

type RefreshTokenRequest struct {
	RefreshToken string      `json:"refreshToken"`
	DeviceInfo   interface{} `json:"deviceInfo"`
}

type RefreshTokenResponese

type RefreshTokenResponese struct {
	RefreshToken  string    `json:"refreshToken"`
	Token         string    `json:"token"`
	TokenExpireIn time.Time `json:"tokenExpireIn"`
}

type Service

type Service struct {
	Label    string          `json:"name"`
	Amount   decimal.Decimal `json:"amount"`
	Quantity int64           `json:"quantity"`
}

type VerifyCodeRequest

type VerifyCodeRequest struct {
	Phone          string      `json:"phone"`
	Code           string      ` json:"code"`
	ChallengeToken string      `json:"challengeToken"`
	DeviceInfo     interface{} `json:"deviceInfo"`
}

type VerifyCodeResponse

type VerifyCodeResponse struct {
	RefreshToken string `json:"refreshToken"`
}

func VerifyCode

func VerifyCode(payload VerifyCodeRequest) (*VerifyCodeResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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