-
Notifications
You must be signed in to change notification settings - Fork 448
/
customer.go
212 lines (182 loc) · 8.54 KB
/
customer.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package stripe
import (
"encoding/json"
)
// CustomerTaxExempt is the type of tax exemption associated with a customer.
type CustomerTaxExempt string
// List of values that CustomerTaxInfoType can take.
const (
CustomerTaxExemptExempt CustomerTaxExempt = "exempt"
CustomerTaxExemptNone CustomerTaxExempt = "none"
CustomerTaxExemptReverse CustomerTaxExempt = "reverse"
)
// CustomerTaxInfoType is the type of tax info associated with a customer.
type CustomerTaxInfoType string
// List of values that CustomerTaxInfoType can take.
const (
CustomerTaxInfoTypeVAT CustomerTaxInfoType = "vat"
)
// CustomerTaxInfoVerificationStatus is the type of tax info associated with a customer.
type CustomerTaxInfoVerificationStatus string
// List of values that CustomerTaxInfoType can take.
const (
CustomerTaxInfoVerificationStatusPending CustomerTaxInfoVerificationStatus = "pending"
CustomerTaxInfoVerificationStatusUnverified CustomerTaxInfoVerificationStatus = "unverified"
CustomerTaxInfoVerificationStatusVerified CustomerTaxInfoVerificationStatus = "verified"
)
// CustomerParams is the set of parameters that can be used when creating or updating a customer.
// For more details see https://stripe.com/docs/api#create_customer and https://stripe.com/docs/api#update_customer.
type CustomerParams struct {
Params `form:"*"`
Address *AddressParams `form:"address"`
Balance *int64 `form:"balance"`
Coupon *string `form:"coupon"`
DefaultSource *string `form:"default_source"`
Description *string `form:"description"`
Email *string `form:"email"`
InvoicePrefix *string `form:"invoice_prefix"`
InvoiceSettings *CustomerInvoiceSettingsParams `form:"invoice_settings"`
Name *string `form:"name"`
PaymentMethod *string `form:"payment_method"`
Phone *string `form:"phone"`
PreferredLocales []*string `form:"preferred_locales"`
Shipping *CustomerShippingDetailsParams `form:"shipping"`
Source *SourceParams `form:"*"` // SourceParams has custom encoding so brought to top level with "*"
TaxExempt *string `form:"tax_exempt"`
TaxIDData []*CustomerTaxIDDataParams `form:"tax_id_data"`
Token *string `form:"-"` // This doesn't seem to be used?
// The following parameter is deprecated. Use Balance instead.
AccountBalance *int64 `form:"account_balance"`
// The following parameter is deprecated. Use TaxIDData instead.
TaxInfo *CustomerTaxInfoParams `form:"tax_info"`
// The parameters below are considered deprecated. Consider creating a Subscription separately instead.
Plan *string `form:"plan"`
Quantity *int64 `form:"quantity"`
TaxPercent *float64 `form:"tax_percent"`
TrialEnd *int64 `form:"trial_end"`
}
// CustomerInvoiceCustomFieldParams represents the parameters associated with one custom field on
// the customer's invoices.
type CustomerInvoiceCustomFieldParams struct {
Name *string `form:"name"`
Value *string `form:"value"`
}
// CustomerInvoiceSettingsParams is the structure containing the default settings for invoices
// associated with this customer.
type CustomerInvoiceSettingsParams struct {
CustomFields []*CustomerInvoiceCustomFieldParams `form:"custom_fields"`
DefaultPaymentMethod *string `form:"default_payment_method"`
Footer *string `form:"footer"`
}
// CustomerShippingDetailsParams is the structure containing shipping information.
type CustomerShippingDetailsParams struct {
Address *AddressParams `form:"address"`
Name *string `form:"name"`
Phone *string `form:"phone"`
}
// CustomerTaxIDDataParams lets you pass the tax id details associated with a Customer.
type CustomerTaxIDDataParams struct {
Type *string `form:"type"`
Value *string `form:"value"`
}
// CustomerTaxInfoParams is the structure containing tax information for the customer.
type CustomerTaxInfoParams struct {
TaxID *string `form:"tax_id"`
Type *string `form:"type"`
}
// SetSource adds valid sources to a CustomerParams object,
// returning an error for unsupported sources.
func (cp *CustomerParams) SetSource(sp interface{}) error {
source, err := SourceParamsFor(sp)
cp.Source = source
return err
}
// CustomerListParams is the set of parameters that can be used when listing customers.
// For more details see https://stripe.com/docs/api#list_customers.
type CustomerListParams struct {
ListParams `form:"*"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
Email *string `form:"email"`
}
// Customer is the resource representing a Stripe customer.
// For more details see https://stripe.com/docs/api#customers.
type Customer struct {
Address Address `json:"address"`
Balance int64 `json:"balance"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
DefaultSource *PaymentSource `json:"default_source"`
Deleted bool `json:"deleted"`
Delinquent bool `json:"delinquent"`
Description string `json:"description"`
Discount *Discount `json:"discount"`
Email string `json:"email"`
ID string `json:"id"`
InvoicePrefix string `json:"invoice_prefix"`
InvoiceSettings *CustomerInvoiceSettings `json:"invoice_settings"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Name string `json:"name"`
Phone string `json:"phone"`
PreferredLocales []string `json:"preferred_locales"`
Shipping *CustomerShippingDetails `json:"shipping"`
Sources *SourceList `json:"sources"`
Subscriptions *SubscriptionList `json:"subscriptions"`
TaxExempt CustomerTaxExempt `json:"tax_exempt"`
TaxIDs *TaxIDList `json:"tax_ids"`
// The following property is deprecated. Use Balance instead.
AccountBalance int64 `json:"account_balance"`
// The following properties are deprecated. Use TaxIds instead.
TaxInfo *CustomerTaxInfo `json:"tax_info"`
TaxInfoVerification *CustomerTaxInfoVerification `json:"tax_info_verification"`
}
// CustomerInvoiceCustomField represents a custom field associated with the customer's invoices.
type CustomerInvoiceCustomField struct {
Name *string `form:"name"`
Value *string `form:"value"`
}
// CustomerInvoiceSettings is the structure containing the default settings for invoices associated
// with this customer.
type CustomerInvoiceSettings struct {
CustomFields []*CustomerInvoiceCustomField `json:"custom_fields"`
DefaultPaymentMethod *PaymentMethod `json:"default_payment_method"`
Footer string `json:"footer"`
}
// CustomerList is a list of customers as retrieved from a list endpoint.
type CustomerList struct {
ListMeta
Data []*Customer `json:"data"`
}
// CustomerShippingDetails is the structure containing shipping information.
type CustomerShippingDetails struct {
Address Address `json:"address"`
Name string `json:"name"`
Phone string `json:"phone"`
}
// CustomerTaxInfo is the structure containing tax information for the customer.
type CustomerTaxInfo struct {
TaxID string `json:"tax_id"`
Type CustomerTaxInfoType `json:"type"`
}
// CustomerTaxInfoVerification is the structure containing tax verification for the customer.
type CustomerTaxInfoVerification struct {
Status CustomerTaxInfoVerificationStatus `json:"status"`
VerifiedName string `json:"verified_name"`
}
// UnmarshalJSON handles deserialization of a Customer.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (c *Customer) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
c.ID = id
return nil
}
type customer Customer
var v customer
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*c = Customer(v)
return nil
}