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 {
|
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().
|
resp, err := c.resty.R().
|
||||||
SetContext(ctx).
|
SetContext(ctx).
|
||||||
SetHeader("Authorization", c.token).
|
SetHeader("Authorization", c.token).
|
||||||
SetBody(request).
|
SetBody(reqJson).
|
||||||
Post(c.apiBaseURL + "/fiscal/execute")
|
Post(c.apiBaseURL + "/fiscal/execute")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -76,10 +83,11 @@ type SellParams struct {
|
|||||||
Rows []ReceiptRow
|
Rows []ReceiptRow
|
||||||
Pays []ReceiptPay
|
Pays []ReceiptPay
|
||||||
Userinfo *Userinfo
|
Userinfo *Userinfo
|
||||||
|
CommentUP string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Sell(ctx context.Context, params SellParams) (*SellResponse, error) {
|
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{
|
request := FiscalRequest{
|
||||||
Source: params.Source,
|
Source: params.Source,
|
||||||
@@ -94,6 +102,12 @@ func (c *Client) Sell(ctx context.Context, params SellParams) (*SellResponse, er
|
|||||||
request.Userinfo = *params.Userinfo
|
request.Userinfo = *params.Userinfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqJson, err := json.Marshal(request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Println(string(reqJson))
|
||||||
|
|
||||||
var response SellResponse
|
var response SellResponse
|
||||||
if err := c.executeRequest(ctx, request, &response); err != nil {
|
if err := c.executeRequest(ctx, request, &response); err != nil {
|
||||||
return nil, err
|
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{
|
return ReceiptPay{
|
||||||
Type: PayTypeCard,
|
Type: PayTypeCard,
|
||||||
Sum: sum,
|
Sum: sum,
|
||||||
@@ -26,6 +26,8 @@ func NewReceiptPayCard(sum float64, cardmask, bankID, rrnCode, authCode string)
|
|||||||
BankID: bankID,
|
BankID: bankID,
|
||||||
Rrn: rrnCode,
|
Rrn: rrnCode,
|
||||||
AuthCode: authCode,
|
AuthCode: authCode,
|
||||||
|
TermID: terminalID,
|
||||||
|
BankName: bankName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,10 +39,11 @@ func CalculateReceiptSum(rows []ReceiptRow) float64 {
|
|||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReceipt(rows []ReceiptRow, pays []ReceiptPay) Receipt {
|
func NewReceipt(rows []ReceiptRow, pays []ReceiptPay, commentUp string) Receipt {
|
||||||
return Receipt{
|
return Receipt{
|
||||||
Sum: CalculateReceiptSum(rows),
|
Sum: CalculateReceiptSum(rows),
|
||||||
Round: 0.00,
|
Round: 0.00,
|
||||||
|
CommentUp: commentUp,
|
||||||
Disc: 0,
|
Disc: 0,
|
||||||
DiscType: 0,
|
DiscType: 0,
|
||||||
Rows: rows,
|
Rows: rows,
|
||||||
|
|||||||
12
vchasno.go
12
vchasno.go
@@ -38,6 +38,7 @@ type DefaultParams struct {
|
|||||||
Taxgrp string
|
Taxgrp string
|
||||||
PayType int
|
PayType int
|
||||||
DefaultTimeout time.Duration
|
DefaultTimeout time.Duration
|
||||||
|
BankName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(config Config) *Client {
|
func NewClient(config Config) *Client {
|
||||||
@@ -98,6 +99,7 @@ type SellParams struct {
|
|||||||
PayType int
|
PayType int
|
||||||
CardParams *CardParams
|
CardParams *CardParams
|
||||||
Userinfo *api.Userinfo
|
Userinfo *api.Userinfo
|
||||||
|
CommentUP string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CardParams struct {
|
type CardParams struct {
|
||||||
@@ -105,6 +107,8 @@ type CardParams struct {
|
|||||||
BankID string
|
BankID string
|
||||||
RrnCode string
|
RrnCode string
|
||||||
AuthCode string
|
AuthCode string
|
||||||
|
TerminalID string
|
||||||
|
BankName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) NewSellParams() *SellParamsBuilder {
|
func (c *Client) NewSellParams() *SellParamsBuilder {
|
||||||
@@ -155,6 +159,11 @@ func (b *SellParamsBuilder) Comment(comment string) *SellParamsBuilder {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *SellParamsBuilder) CommentUp(commentUp string) *SellParamsBuilder {
|
||||||
|
b.params.CommentUP = commentUp
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
func (b *SellParamsBuilder) PayCash() *SellParamsBuilder {
|
func (b *SellParamsBuilder) PayCash() *SellParamsBuilder {
|
||||||
b.params.PayType = PayTypeCash
|
b.params.PayType = PayTypeCash
|
||||||
b.params.CardParams = nil
|
b.params.CardParams = nil
|
||||||
@@ -230,6 +239,8 @@ func (c *Client) Sell(ctx context.Context, params SellParams) (*api.SellResponse
|
|||||||
params.CardParams.BankID,
|
params.CardParams.BankID,
|
||||||
params.CardParams.RrnCode,
|
params.CardParams.RrnCode,
|
||||||
params.CardParams.AuthCode,
|
params.CardParams.AuthCode,
|
||||||
|
params.CardParams.TerminalID,
|
||||||
|
params.CardParams.BankName,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
pay = api.NewReceiptPayCash(sum, params.Comment)
|
pay = api.NewReceiptPayCash(sum, params.Comment)
|
||||||
@@ -241,6 +252,7 @@ func (c *Client) Sell(ctx context.Context, params SellParams) (*api.SellResponse
|
|||||||
Rows: []api.ReceiptRow{row},
|
Rows: []api.ReceiptRow{row},
|
||||||
Pays: []api.ReceiptPay{pay},
|
Pays: []api.ReceiptPay{pay},
|
||||||
Userinfo: params.Userinfo,
|
Userinfo: params.Userinfo,
|
||||||
|
CommentUP: params.CommentUP,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user