forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer.go
79 lines (69 loc) · 2.18 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
package stripe
import "encoding/json"
// 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
Balance int64
Token, Coupon string
Card *CardParams
Desc, Email string
Plan string
Quantity uint64
TrialEnd int64
DefaultCard string
}
// 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
Created int64
}
// Customer is the resource representing a Stripe customer.
// For more details see https://stripe.com/docs/api#customers.
type Customer struct {
Id string `json:"id"`
Live bool `json:"livemode"`
Cards *CardList `json:"cards"`
Created int64 `json:"created"`
Balance int64 `json:"account_balance"`
Currency Currency `json:"currency"`
DefaultCard *Card `json:"default_card"`
Delinquent bool `json:"delinquent"`
Desc string `json:"description"`
Discount *Discount `json:"discount"`
Email string `json:"email"`
Meta map[string]string `json:"metadata"`
Subs *SubList `json:"subscriptions"`
}
// CustomerIter is a iterator for list responses.
type CustomerIter struct {
Iter *Iter
}
// Next returns the next value in the list.
func (i *CustomerIter) Next() (*Customer, error) {
c, err := i.Iter.Next()
if err != nil {
return nil, err
}
return c.(*Customer), err
}
// Stop returns true if there are no more iterations to be performed.
func (i *CustomerIter) Stop() bool {
return i.Iter.Stop()
}
// Meta returns the list metadata.
func (i *CustomerIter) Meta() *ListMeta {
return i.Iter.Meta()
}
func (c *Customer) UnmarshalJSON(data []byte) error {
type customer Customer
var cc customer
err := json.Unmarshal(data, &cc)
if err == nil {
*c = Customer(cc)
} else {
c.Id = string(data[1 : len(data)-1])
}
return nil
}