-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceipt.go
131 lines (109 loc) · 4.06 KB
/
receipt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package yandex
import (
"encoding/json"
"log"
"github.com/google/go-querystring/query"
"github.com/shopspring/decimal"
)
type Customer struct {
FullName string `json:"full_name,omitempty"`
INN string `json:"inn,omitempty"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
}
type Supplier struct {
Name string `json:"name,omitempty"`
Phone string `json:"phone,omitempty"`
INN string `json:"inn,omitempty"`
}
type Item struct {
Description string `json:"description"`
Quantity decimal.Decimal `json:"quantity"`
Amount *Amount `json:"amount"`
VATCode uint32 `json:"vat_code"`
PaymentSubject string `json:"payment_subject,omitempty"`
PaymentMode string `json:"payment_mode,omitempty"`
ProductCode string `json:"product_code,omitempty"`
CountryOfOriginCode string `json:"country_of_origin_code,omitempty"`
CustomsDeclarationNumber string `json:"customs_declaration_number,omitempty"`
Excise string `json:"excise,omitempty"`
Supplier *Supplier `json:"supplier,omitempty"`
AgentType string `json:"agent_type,omitempty"`
}
type Settlement struct {
Type string `json:"type"`
Amount *Amount `json:"amount"`
}
type Receipt struct {
Id string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
PaymentId string `json:"payment_id,omitempty"`
RefundId string `json:"refund_id,omitempty"`
Status string `json:"status,omitempty"`
FiscalDocumentNumber string `json:"fiscal_document_number,omitempty"`
FiscalStorageNumber string `json:"fiscal_storage_number,omitempty"`
FiscalAttribute string `json:"fiscal_attribute,omitempty"`
RegisteredAt string `json:"registered_at,omitempty"`
FiscalProviderId string `json:"fiscal_provider_id,omitempty"`
Settlements []*Settlement `json:"settlements,omitempty"`
Customer *Customer `json:"customer,omitempty"`
Items []*Item `json:"items"`
TaxSystemCode uint32 `json:"tax_system_code,omitempty"`
Phone string `json:"phone,omitempty"`
Email string `json:"email,omitempty"`
OnBehalfOf string `json:"on_behalf_of,omitempty"`
}
type ReceiptRequest struct {
Type string `json:"type"`
PaymentId string `json:"payment_id,omitempty"`
RefundId string `json:"refund_id,omitempty"`
Customer *Customer `json:"customer"`
Items []*Item `json:"items"`
TaxSystemCode uint32 `json:"tax_system_code,omitempty"`
Send bool `json:"send"`
Settlements []*Settlement `json:"settlements"`
OnBehalfOf string `json:"on_behalf_of,omitempty"`
}
func (y *Yandex) CreateReceipt(idempKey string, req *ReceiptRequest) (*Receipt, error) {
q, err := query.Values(req)
if err != nil {
log.Printf("Failed creating query: %v\n", err)
return nil, err
}
r := &HttpRequest{
Method: "POST",
Path: "/receipts",
ShopId: y.ShopId,
SecretKey: y.SecretKey,
IdempotenceKey: idempKey,
Data: q,
}
bytes, err := r.SendRequest()
if err != nil {
return nil, err
}
res := &Receipt{}
if err := json.Unmarshal(bytes, res); err != nil {
log.Printf("Failed unmarshaling bytes to struct: %v\n", err)
return nil, err
}
return res, nil
}
func (y *Yandex) GetReceiptInfo(id string) (*Receipt, error) {
r := &HttpRequest{
Method: "GET",
Path: "/receipts/" + id,
ShopId: y.ShopId,
SecretKey: y.SecretKey,
}
bytes, err := r.SendRequest()
if err != nil {
return nil, err
}
res := &Receipt{}
if err := json.Unmarshal(bytes, res); err != nil {
log.Printf("Failed unmarshaling bytes to struct: %v\n", err)
return nil, err
}
return res, nil
}