-
Notifications
You must be signed in to change notification settings - Fork 462
/
sku.go
91 lines (78 loc) · 2.87 KB
/
sku.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
package stripe
import "encoding/json"
// SKUInventoryType describe's the possible value for inventory type
type SKUInventoryType string
const (
SKUInventoryTypeBucket SKUInventoryType = "bucket"
SKUInventoryTypeFinite SKUInventoryType = "finite"
SKUInventoryTypeInfinite SKUInventoryType = "infinite"
)
// SKUInventoryValue describe's the possible value for inventory value
type SKUInventoryValue string
const (
SKUInventoryValueInStock SKUInventoryValue = "in_stock"
SKUInventoryValueLimited SKUInventoryValue = "limited"
SKUInventoryValueOutOfStock SKUInventoryValue = "out_of_stock"
)
type InventoryParams struct {
Quantity *int64 `form:"quantity"`
Type *string `form:"type"`
Value *string `form:"value"`
}
type SKUParams struct {
Params `form:"*"`
Active *bool `form:"active"`
Attributes map[string]string `form:"attributes"`
Currency *string `form:"currency"`
Description *string `form:"description"`
ID *string `form:"id"`
Image *string `form:"image"`
Inventory *InventoryParams `form:"inventory"`
PackageDimensions *PackageDimensionsParams `form:"package_dimensions"`
Price *int64 `form:"price"`
Product *string `form:"product"`
}
type Inventory struct {
Quantity int64 `json:"quantity"`
Type SKUInventoryType `json:"type"`
Value SKUInventoryValue `json:"value"`
}
type SKU struct {
Active bool `json:"active"`
Attributes map[string]string `json:"attributes"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Description string `json:"description"`
ID string `json:"id"`
Image string `json:"image"`
Inventory *Inventory `json:"inventory"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
PackageDimensions *PackageDimensions `json:"package_dimensions"`
Price int64 `json:"price"`
Product *Product `json:"product"`
Updated int64 `json:"updated"`
}
type SKUList struct {
ListMeta
Data []*SKU `json:"data"`
}
type SKUListParams struct {
ListParams `form:"*"`
Active *bool `form:"active"`
Attributes map[string]string `form:"attributes"`
IDs []*string `form:"ids"`
InStock *bool `form:"in_stock"`
Product *string `form:"product"`
}
func (s *SKU) UnmarshalJSON(data []byte) error {
type sku SKU
var sk sku
err := json.Unmarshal(data, &sk)
if err == nil {
*s = SKU(sk)
} else {
s.ID = string(data[1 : len(data)-1])
}
return nil
}