1 Commits

3 changed files with 15 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import (
type Client struct {
token string
device string
isDM bool
resty *resty.Client
apiBaseURL string
fiscalEndpoint string
@@ -17,6 +18,7 @@ type Client struct {
func NewClient(token string) *Client {
return &Client{
token: token,
isDM: false,
resty: resty.New(),
apiBaseURL: "https://kasa.vchasno.ua/api/v3",
fiscalEndpoint: "/fiscal/execute",
@@ -38,6 +40,7 @@ func NewDMClient(token, dmURL, device string) *Client {
return &Client{
token: token,
device: device,
isDM: true,
resty: restyClient,
apiBaseURL: dmURL,
fiscalEndpoint: "/dm/execute",

View File

@@ -20,6 +20,11 @@ func (e *APIError) Error() string {
func (c *Client) executeRequest(ctx context.Context, request FiscalRequest, response interface{}) error {
request.Device = c.device
if c.isDM {
request.Ver = 6
request.Type = 1
}
reqJson, err := json.Marshal(request)
if err != nil {
return fmt.Errorf("failed to marshal request: %w", err)
@@ -72,7 +77,6 @@ func (c *Client) OpenShift(ctx context.Context, cashier string) (*SellResponse,
request := FiscalRequest{
Fiscal: Fiscal{
Task: TaskOpenShift,
Cashier: cashier,
},
}
@@ -88,7 +92,6 @@ func (c *Client) CloseShift(ctx context.Context, cashier string) (*ZReportRespon
request := FiscalRequest{
Fiscal: Fiscal{
Task: TaskZReport,
Cashier: cashier,
},
}

View File

@@ -1,8 +1,11 @@
package api
type FiscalRequest struct {
Source string `json:"source"`
Ver int `json:"ver,omitempty"`
Source string `json:"source,omitempty"`
Device string `json:"device,omitempty"`
Tag string `json:"tag,omitempty"`
Type int `json:"type,omitempty"`
Userinfo Userinfo `json:"userinfo,omitempty"`
Fiscal Fiscal `json:"fiscal"`
}
@@ -14,7 +17,7 @@ type Userinfo struct {
type Fiscal struct {
Task int `json:"task"`
Cashier string `json:"cashier"`
Cashier string `json:"cashier,omitempty"`
Receipt *Receipt `json:"receipt,omitempty"`
}