Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a8b5cf0c5 | |||
| b33620f629 | |||
| 8006fd0935 | |||
| 4f9ca56157 | |||
| 328447f079 | |||
| 854187f98e |
@@ -8,10 +8,17 @@ 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)
|
||||
}
|
||||
fmt.Println(string(reqJson))
|
||||
|
||||
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 +78,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,
|
||||
@@ -94,6 +102,12 @@ func (c *Client) Sell(ctx context.Context, params SellParams) (*SellResponse, er
|
||||
request.Userinfo = *params.Userinfo
|
||||
}
|
||||
|
||||
reqJson, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(string(reqJson))
|
||||
|
||||
var response SellResponse
|
||||
if err := c.executeRequest(ctx, request, &response); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -17,7 +17,7 @@ func NewReceiptPayCash(sum float64, comment string) ReceiptPay {
|
||||
}
|
||||
}
|
||||
|
||||
func NewReceiptPayCard(sum float64, cardmask, bankID, rrnCode, authCode string) ReceiptPay {
|
||||
func NewReceiptPayCard(sum float64, cardmask, bankID, rrnCode, authCode, terminalID, bankName string) ReceiptPay {
|
||||
return ReceiptPay{
|
||||
Type: PayTypeCard,
|
||||
Sum: sum,
|
||||
@@ -26,6 +26,8 @@ func NewReceiptPayCard(sum float64, cardmask, bankID, rrnCode, authCode string)
|
||||
BankID: bankID,
|
||||
Rrn: rrnCode,
|
||||
AuthCode: authCode,
|
||||
TermID: terminalID,
|
||||
BankName: bankName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,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,
|
||||
}
|
||||
}
|
||||
|
||||
30
vchasno.go
30
vchasno.go
@@ -38,6 +38,7 @@ type DefaultParams struct {
|
||||
Taxgrp string
|
||||
PayType int
|
||||
DefaultTimeout time.Duration
|
||||
BankName string
|
||||
}
|
||||
|
||||
func NewClient(config Config) *Client {
|
||||
@@ -98,13 +99,16 @@ type SellParams struct {
|
||||
PayType int
|
||||
CardParams *CardParams
|
||||
Userinfo *api.Userinfo
|
||||
CommentUP string
|
||||
}
|
||||
|
||||
type CardParams struct {
|
||||
Cardmask string
|
||||
BankID string
|
||||
RrnCode string
|
||||
AuthCode string
|
||||
Cardmask string
|
||||
BankID string
|
||||
RrnCode string
|
||||
AuthCode string
|
||||
TerminalID string
|
||||
BankName string
|
||||
}
|
||||
|
||||
func (c *Client) NewSellParams() *SellParamsBuilder {
|
||||
@@ -155,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
|
||||
@@ -230,17 +239,20 @@ func (c *Client) Sell(ctx context.Context, params SellParams) (*api.SellResponse
|
||||
params.CardParams.BankID,
|
||||
params.CardParams.RrnCode,
|
||||
params.CardParams.AuthCode,
|
||||
params.CardParams.TerminalID,
|
||||
params.CardParams.BankName,
|
||||
)
|
||||
} else {
|
||||
pay = api.NewReceiptPayCash(sum, params.Comment)
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user