Add isDM flag to Client and update FiscalRequest structure for DM support
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
@@ -71,8 +76,7 @@ func (c *Client) executeRequest(ctx context.Context, request FiscalRequest, resp
|
||||
func (c *Client) OpenShift(ctx context.Context, cashier string) (*SellResponse, error) {
|
||||
request := FiscalRequest{
|
||||
Fiscal: Fiscal{
|
||||
Task: TaskOpenShift,
|
||||
Cashier: cashier,
|
||||
Task: TaskOpenShift,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -87,8 +91,7 @@ func (c *Client) OpenShift(ctx context.Context, cashier string) (*SellResponse,
|
||||
func (c *Client) CloseShift(ctx context.Context, cashier string) (*ZReportResponse, error) {
|
||||
request := FiscalRequest{
|
||||
Fiscal: Fiscal{
|
||||
Task: TaskZReport,
|
||||
Cashier: cashier,
|
||||
Task: TaskZReport,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user