7 Commits
v0.0.3 ... main

Author SHA1 Message Date
daniel
b70e95ac5c Added null cheque 2025-10-16 04:36:48 +03:00
ac4f4670bb disabled test JSON logging 2025-10-15 10:08:54 +03:00
4a8b5cf0c5 Added comment to clarify JSON request execution in executeRequest function 2025-10-14 11:40:57 +03:00
b33620f629 json mashal instead of struct in body 2025-10-14 11:37:19 +03:00
8006fd0935 added debug json req logging 2025-10-14 11:30:31 +03:00
4f9ca56157 fixed comment 2025-10-13 16:16:06 +03:00
328447f079 Added commentUP field to fiscalAPI 2025-10-13 16:08:02 +03:00
3 changed files with 54 additions and 19 deletions

View File

@@ -8,10 +8,16 @@ import (
)
func (c *Client) executeRequest(ctx context.Context, request FiscalRequest, response interface{}) error {
//execute request with json body in request
reqJson, err := json.Marshal(request)
if err != nil {
return fmt.Errorf("failed to marshal request: %w", err)
}
resp, err := c.resty.R().
SetContext(ctx).
SetHeader("Authorization", c.token).
SetBody(request).
SetBody(reqJson).
Post(c.apiBaseURL + "/fiscal/execute")
if err != nil {
@@ -71,15 +77,16 @@ func (c *Client) CloseShift(ctx context.Context, cashier string) (*ZReportRespon
}
type SellParams struct {
Cashier string
Source string
Rows []ReceiptRow
Pays []ReceiptPay
Userinfo *Userinfo
Cashier string
Source string
Rows []ReceiptRow
Pays []ReceiptPay
Userinfo *Userinfo
CommentUP string
}
func (c *Client) Sell(ctx context.Context, params SellParams) (*SellResponse, error) {
receipt := NewReceipt(params.Rows, params.Pays)
receipt := NewReceipt(params.Rows, params.Pays, params.CommentUP)
request := FiscalRequest{
Source: params.Source,

View File

@@ -39,13 +39,14 @@ func CalculateReceiptSum(rows []ReceiptRow) float64 {
return sum
}
func NewReceipt(rows []ReceiptRow, pays []ReceiptPay) Receipt {
func NewReceipt(rows []ReceiptRow, pays []ReceiptPay, commentUp string) Receipt {
return Receipt{
Sum: CalculateReceiptSum(rows),
Round: 0.00,
Disc: 0,
DiscType: 0,
Rows: rows,
Pays: pays,
Sum: CalculateReceiptSum(rows),
Round: 0.00,
CommentUp: commentUp,
Disc: 0,
DiscType: 0,
Rows: rows,
Pays: pays,
}
}

View File

@@ -99,6 +99,7 @@ type SellParams struct {
PayType int
CardParams *CardParams
Userinfo *api.Userinfo
CommentUP string
}
type CardParams struct {
@@ -158,6 +159,11 @@ func (b *SellParamsBuilder) Comment(comment string) *SellParamsBuilder {
return b
}
func (b *SellParamsBuilder) CommentUp(commentUp string) *SellParamsBuilder {
b.params.CommentUP = commentUp
return b
}
func (b *SellParamsBuilder) PayCash() *SellParamsBuilder {
b.params.PayType = PayTypeCash
b.params.CardParams = nil
@@ -241,11 +247,12 @@ func (c *Client) Sell(ctx context.Context, params SellParams) (*api.SellResponse
}
return c.api.Sell(ctx, api.SellParams{
Cashier: c.cashier,
Source: c.source,
Rows: []api.ReceiptRow{row},
Pays: []api.ReceiptPay{pay},
Userinfo: params.Userinfo,
Cashier: c.cashier,
Source: c.source,
Rows: []api.ReceiptRow{row},
Pays: []api.ReceiptPay{pay},
Userinfo: params.Userinfo,
CommentUP: params.CommentUP,
})
}
@@ -267,3 +274,23 @@ func (c *Client) QuickSellNamed(ctx context.Context, name string, price float64)
Price: price,
})
}
func (c *Client) ZeroReceipt(ctx context.Context) (*api.SellResponse, error) {
return c.api.Sell(ctx, api.SellParams{
Cashier: c.cashier,
Source: c.source,
Rows: []api.ReceiptRow{},
Pays: []api.ReceiptPay{},
CommentUP: "Нульовий чек",
})
}
func (c *Client) ZeroReceiptWithTimeout(timeout time.Duration) (*api.SellResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return c.ZeroReceipt(ctx)
}
func (c *Client) ZeroReceiptDefault() (*api.SellResponse, error) {
return c.ZeroReceiptWithTimeout(c.defaults.DefaultTimeout)
}