-
Notifications
You must be signed in to change notification settings - Fork 460
/
orderitem.go
92 lines (79 loc) · 3.25 KB
/
orderitem.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
//
//
// File generated from our OpenAPI spec
//
//
package stripe
import "encoding/json"
// The type of line item. One of `sku`, `tax`, `shipping`, or `discount`.
type OrderItemType string
// List of values that OrderItemType can take
const (
OrderItemTypeCoupon OrderItemType = "coupon"
OrderItemTypeDiscount OrderItemType = "discount"
OrderItemTypeSKU OrderItemType = "sku"
OrderItemTypeShipping OrderItemType = "shipping"
OrderItemTypeTax OrderItemType = "tax"
)
// OrderItemParentType represents the type of order item parent
type OrderItemParentType string
// List of values that OrderItemParentType can take.
const (
OrderItemParentTypeCoupon OrderItemParentType = "coupon"
OrderItemParentTypeDiscount OrderItemParentType = "discount"
OrderItemParentTypeSKU OrderItemParentType = "sku"
OrderItemParentTypeShipping OrderItemParentType = "shipping"
OrderItemParentTypeTax OrderItemParentType = "tax"
)
// OrderItemParent describes the parent of an order item.
type OrderItemParent struct {
ID string `json:"id"`
SKU *SKU `json:"-"`
Type OrderItemParentType `json:"object"`
}
// A representation of the constituent items of any given order. Can be used to
// represent [SKUs](https://stripe.com/docs/api#skus), shipping costs, or taxes owed on the order.
//
// Related guide: [Orders](https://stripe.com/docs/orders/guide).
type OrderItem struct {
// A positive integer in the smallest currency unit (that is, 100 cents for $1.00, or 1 for ¥1, Japanese Yen being a zero-decimal currency) representing the total amount for the line item.
Amount int64 `json:"amount"`
// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
Currency Currency `json:"currency"`
// Description of the line item, meant to be displayable to the user (e.g., `"Express shipping"`).
Description string `json:"description"`
// String representing the object's type. Objects of the same type share the same value.
Object string `json:"object"`
// The ID of the associated object for this line item. Expandable if not null (e.g., expandable to a SKU).
Parent *OrderItemParent `json:"parent"`
// A positive integer representing the number of instances of `parent` that are included in this order item. Applicable/present only if `type` is `sku`.
Quantity int64 `json:"quantity"`
// The type of line item. One of `sku`, `tax`, `shipping`, or `discount`.
Type OrderItemType `json:"type"`
}
// UnmarshalJSON handles deserialization of an OrderItemParent.
// This custom unmarshaling is needed because the resulting
// property may be an id or a full SKU struct if it was expanded.
func (p *OrderItemParent) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
p.ID = id
return nil
}
type orderItemParent OrderItemParent
var v orderItemParent
if err := json.Unmarshal(data, &v); err != nil {
return err
}
var err error
*p = OrderItemParent(v)
switch p.Type {
case OrderItemParentTypeSKU:
// Currently only SKUs `parent` is returned as an object when expanded.
// For other items only IDs are returned.
if err = json.Unmarshal(data, &p.SKU); err != nil {
return err
}
p.ID = p.SKU.ID
}
return nil
}