forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.go
132 lines (116 loc) · 3.44 KB
/
order.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
132
package stripe
import (
"encoding/json"
)
// OrderStatus represents the statuses of an order object.
type OrderStatus string
const (
StatusCreated OrderStatus = "created"
StatusPaid OrderStatus = "paid"
StatusCanceled OrderStatus = "canceled"
StatusFulfilled OrderStatus = "fulfilled"
StatusReturned OrderStatus = "returned"
)
type OrderParams struct {
Params
Currency Currency
Customer string
Email string
Items []*OrderItemParams
Shipping *ShippingParams
}
type ShippingParams struct {
Name string
Address *AddressParams
Phone string
}
type AddressParams struct {
Line1 string
Line2 string
City string
State string
PostalCode string
Country string
}
type OrderUpdateParams struct {
Params
Coupon string
SelectedShippingMethod string
Status OrderStatus
}
type Shipping struct {
Name string `json:"name"`
Address Address `json:"address"`
Phone string `json:"phone"`
}
type ShippingMethod struct {
ID string `json:"id"`
Amount int64 `json:"amount"`
Currency Currency `json:"currency"`
Description string `json:"description"`
}
type Order struct {
ID string `json:"id"`
Amount int64 `json:"amount"`
Application string `json:"application"`
ApplicationFee int64 `json:"application_fee"`
Charge Charge `json:"charge"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Customer Customer `json:"customer"`
Email string `json:"email"`
Items []OrderItem `json:"items"`
Meta map[string]string `json:"metadata"`
SelectedShippingMethod *string `json:"selected_shipping_method"`
Shipping Shipping `json:"shipping"`
ShippingMethods []ShippingMethod `json:"shipping_methods"`
Status OrderStatus `json:"status"`
Updated int64 `json:"updated"`
}
// OrderList is a list of orders as retrieved from a list endpoint.
type OrderList struct {
ListMeta
Values []*Order `json:"data"`
}
// OrderListParams is the set of parameters that can be used when
// listing orders. For more details, see:
// https://stripe.com/docs/api#list_orders.
type OrderListParams struct {
ListParams
IDs []string
Status OrderStatus
}
// OrderPayParams is the set of parameters that can be used when
// paying orders. For more details, see:
// https://stripe.com/docs/api#pay_order.
type OrderPayParams struct {
Params
Source *SourceParams
Customer string
ApplicationFee int64
Email string
}
// SetSource adds valid sources to a OrderParams object,
// returning an error for unsupported sources.
func (op *OrderPayParams) SetSource(sp interface{}) error {
source, err := SourceParamsFor(sp)
op.Source = source
return err
}
// UnmarshalJSON handles deserialization of an Order.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (o *Order) UnmarshalJSON(data []byte) error {
type order Order
var oo order
err := json.Unmarshal(data, &oo)
if err == nil {
*o = Order(oo)
{
}
} else {
// the id is surrounded by "\" characters, so strip them
o.ID = string(data[1 : len(data)-1])
}
return nil
}