forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub.go
78 lines (70 loc) · 2.88 KB
/
sub.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
package stripe
import "encoding/json"
// SubStatus is the list of allowed values for the subscription's status.
// Allowed values are "trialing", "active", "past_due", "canceled", "unpaid".
type SubStatus string
// SubParams is the set of parameters that can be used when creating or updating a subscription.
// For more details see https://stripe.com/docs/api#create_subscription and https://stripe.com/docs/api#update_subscription.
type SubParams struct {
Params
Customer, Plan string
Coupon, Token string
TrialEnd int64
Card *CardParams
Quantity uint64
ProrationDate int64
FeePercent, TaxPercent float64
TaxPercentZero bool
NoProrate, EndCancel, QuantityZero, TrialEndNow bool
BillingCycleAnchor int64
BillingCycleAnchorNow bool
}
// SubListParams is the set of parameters that can be used when listing active subscriptions.
// For more details see https://stripe.com/docs/api#list_subscriptions.
type SubListParams struct {
ListParams
Customer string
Plan string
}
// Sub is the resource representing a Stripe subscription.
// For more details see https://stripe.com/docs/api#subscriptions.
type Sub struct {
ID string `json:"id"`
EndCancel bool `json:"cancel_at_period_end"`
Customer *Customer `json:"customer"`
Plan *Plan `json:"plan"`
Quantity uint64 `json:"quantity"`
Status SubStatus `json:"status"`
FeePercent float64 `json:"application_fee_percent"`
Canceled int64 `json:"canceled_at"`
Created int64 `json:"created"`
Start int64 `json:"start"`
PeriodEnd int64 `json:"current_period_end"`
PeriodStart int64 `json:"current_period_start"`
Discount *Discount `json:"discount"`
Ended int64 `json:"ended_at"`
Meta map[string]string `json:"metadata"`
TaxPercent float64 `json:"tax_percent"`
TrialEnd int64 `json:"trial_end"`
TrialStart int64 `json:"trial_start"`
}
// SubList is a list object for subscriptions.
type SubList struct {
ListMeta
Values []*Sub `json:"data"`
}
// UnmarshalJSON handles deserialization of a Sub.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (s *Sub) UnmarshalJSON(data []byte) error {
type sub Sub
var ss sub
err := json.Unmarshal(data, &ss)
if err == nil {
*s = Sub(ss)
} else {
// the id is surrounded by "\" characters, so strip them
s.ID = string(data[1 : len(data)-1])
}
return nil
}