-
Notifications
You must be signed in to change notification settings - Fork 459
/
product.go
111 lines (99 loc) · 4.07 KB
/
product.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
package stripe
import "encoding/json"
// ProductType is the type of a product.
type ProductType string
// List of values that ProductType can take.
const (
ProductTypeGood ProductType = "good"
ProductTypeService ProductType = "service"
)
// PackageDimensionsParams represents the set of parameters for the the dimension of a
// product or a SKU from the perspective of shipping .
type PackageDimensionsParams struct {
Height *float64 `form:"height"`
Length *float64 `form:"length"`
Weight *float64 `form:"weight"`
Width *float64 `form:"width"`
}
// ProductParams is the set of parameters that can be used when creating or updating a product.
type ProductParams struct {
Params `form:"*"`
Active *bool `form:"active"`
Attributes []*string `form:"attributes"`
Caption *string `form:"caption"`
DeactivateOn []*string `form:"deactivate_on"`
Description *string `form:"description"`
ID *string `form:"id"`
Images []*string `form:"images"`
Name *string `form:"name"`
PackageDimensions *PackageDimensionsParams `form:"package_dimensions"`
Shippable *bool `form:"shippable"`
StatementDescriptor *string `form:"statement_descriptor"`
Type *string `form:"type"`
UnitLabel *string `form:"unit_label"`
URL *string `form:"url"`
}
// PackageDimensions represents the dimension of a product or a SKU from the
// perspective of shipping.
type PackageDimensions struct {
Height float64 `json:"height"`
Length float64 `json:"length"`
Weight float64 `json:"weight"`
Width float64 `json:"width"`
}
// Product is the resource representing a Stripe product.
// For more details see https://stripe.com/docs/api#products.
type Product struct {
APIResource
Active bool `json:"active"`
Attributes []string `json:"attributes"`
Caption string `json:"caption"`
Created int64 `json:"created"`
DeactivateOn []string `json:"deactivate_on"`
Description string `json:"description"`
ID string `json:"id"`
Images []string `json:"images"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Name string `json:"name"`
PackageDimensions *PackageDimensions `json:"package_dimensions"`
Shippable bool `json:"shippable"`
StatementDescriptor string `json:"statement_descriptor"`
Type ProductType `json:"type"`
UnitLabel string `json:"unit_label"`
URL string `json:"url"`
Updated int64 `json:"updated"`
}
// ProductList is a list of products as retrieved from a list endpoint.
type ProductList struct {
APIResource
ListMeta
Data []*Product `json:"data"`
}
// ProductListParams is the set of parameters that can be used when listing products.
type ProductListParams struct {
ListParams `form:"*"`
Active *bool `form:"active"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
IDs []*string `form:"ids"`
Shippable *bool `form:"shippable"`
URL *string `form:"url"`
Type *string `form:"type"`
}
// UnmarshalJSON handles deserialization of a Product.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (p *Product) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
p.ID = id
return nil
}
type product Product
var v product
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*p = Product(v)
return nil
}