forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.go
85 lines (77 loc) · 2.67 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
package stripe
import "encoding/json"
// 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"`
Width float64 `json:"width"`
Weight float64 `json:"weight"`
}
// ProductParams is the set of parameters that can be used
// when creating or updating a product.
// For more details, see https://stripe.com/docs/api#create_product
// and https://stripe.com/docs/api#update_product.
type ProductParams struct {
Params
ID string
Active *bool
Name string
Caption string
Desc string
Attrs []string
Images []string
URL string
Shippable *bool
PackageDimensions *PackageDimensions
DeactivateOn []string
}
// Product is the resource representing a Stripe product.
// For more details see https://stripe.com/docs/api#products.
type Product struct {
ID string `json:"id"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
Live bool `json:"livemode"`
Active bool `json:"active"`
Name string `json:"name"`
Caption string `json:"caption"`
Desc string `json:"description"`
Attrs []string `json:"attributes"`
Shippable bool `json:"shippable"`
PackageDimensions *PackageDimensions `json:"package_dimensions"`
Images []string `json:"images"`
Meta map[string]string `json:"metadata"`
URL string `json:"url"`
DeactivateOn []string `json:"deactivate_on"`
Skus *SKUList `json:"skus"`
}
// ProductList is a list of products as retrieved from a list endpoint.
type ProductList struct {
ListMeta
Values []*Product `json:"data"`
}
// ProductListParams is the set of parameters that can be used when
// listing products. For more details, see:
// https://stripe.com/docs/api#list_products.
type ProductListParams struct {
ListParams
Active *bool
IDs []string
Shippable *bool
URL string
}
// 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 {
type product Product
var pr product
err := json.Unmarshal(data, &pr)
if err == nil {
*p = Product(pr)
} else {
p.ID = string(data[1 : len(data)-1])
}
return nil
}