forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subschedule.go
193 lines (170 loc) · 9.09 KB
/
subschedule.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
package stripe
import (
"encoding/json"
)
// SubscriptionScheduleStatus is the list of allowed values for the schedule's status.
type SubscriptionScheduleStatus string
// List of values that SubscriptionScheduleStatus can take.
const (
SubscriptionScheduleStatusActive SubscriptionScheduleStatus = "active"
SubscriptionScheduleStatusCanceled SubscriptionScheduleStatus = "canceled"
SubscriptionScheduleStatusCompleted SubscriptionScheduleStatus = "completed"
SubscriptionScheduleStatusPastDue SubscriptionScheduleStatus = "not_started"
SubscriptionScheduleStatusTrialing SubscriptionScheduleStatus = "released"
)
// SubscriptionScheduleRenewalBehavior describe what happens to a schedule when it ends.
type SubscriptionScheduleRenewalBehavior string
// List of values that SubscriptionScheduleRenewalBehavior can take.
const (
SubscriptionScheduleRenewalBehaviorNone SubscriptionScheduleRenewalBehavior = "none"
SubscriptionScheduleRenewalBehaviorRenew SubscriptionScheduleRenewalBehavior = "release"
SubscriptionScheduleRenewalBehaviorRelease SubscriptionScheduleRenewalBehavior = "renew"
)
// SubscriptionScheduleInvoiceSettingsParams is a structure representing the parameters allowed to
// control invoice settings on invoices associated with a subscription schedule.
type SubscriptionScheduleInvoiceSettingsParams struct {
DaysUntilDue *int64 `form:"days_until_due"`
}
// SubscriptionSchedulePhaseItemParams is a structure representing the parameters allowed to control
// a specic plan on a phase on a subscription schedule.
type SubscriptionSchedulePhaseItemParams struct {
BillingThresholds *SubscriptionItemBillingThresholdsParams `form:"billing_thresholds"`
Plan *string `form:"plan"`
Quantity *int64 `form:"quantity"`
}
// SubscriptionSchedulePhaseParams is a structure representing the parameters allowed to control
// a phase on a subscription schedule.
type SubscriptionSchedulePhaseParams struct {
ApplicationFeePercent *int64 `form:"application_fee_percent"`
Coupon *string `form:"coupon"`
EndDate *int64 `form:"end_date"`
Iterations *int64 `form:"iterations"`
Plans []*SubscriptionSchedulePhaseItemParams `form:"plans"`
StartDate *int64 `form:"start_date"`
TaxPercent *float64 `form:"tax_percent"`
Trial *bool `form:"trial"`
TrialEnd *int64 `form:"trial_end"`
}
// SubscriptionScheduleRenewalIntervalParams is a structure representing the renewal interval
// for a given subscription schedule.
type SubscriptionScheduleRenewalIntervalParams struct {
Interval *string `form:"interval"`
Length *int64 `form:"length"`
}
// SubscriptionScheduleParams is the set of parameters that can be used when creating or updating a
// subscription schedule.
type SubscriptionScheduleParams struct {
Params `form:"*"`
Billing *string `form:"billing"`
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
Customer *string `form:"customer"`
FromSubscription *string `form:"from_subscription"`
InvoiceSettings *SubscriptionScheduleInvoiceSettingsParams `form:"invoice_settings"`
Phases []*SubscriptionSchedulePhaseParams `form:"phases"`
Prorate *bool `form:"prorate"`
RenewalBehavior *string `form:"renewal_behavior"`
RenewalInterval *SubscriptionScheduleRenewalIntervalParams `form:"renewal_interval"`
StartDate *int64 `form:"start_date"`
}
// SubscriptionScheduleCancelParams is the set of parameters that can be used when canceling a
// subscription schedule.
type SubscriptionScheduleCancelParams struct {
Params `form:"*"`
InvoiceNow *bool `form:"invoice_now"`
Prorate *bool `form:"prorate"`
}
// SubscriptionScheduleReleaseParams is the set of parameters that can be used when releasing a
// subscription schedule.
type SubscriptionScheduleReleaseParams struct {
Params `form:"*"`
PreserveCancelDate *bool `form:"preserve_cancel_date"`
}
// SubscriptionScheduleListParams is the set of parameters that can be used when listing
// subscription schedules.
type SubscriptionScheduleListParams struct {
ListParams `form:"*"`
CanceledAt int64 `form:"canceled_at"`
CanceledAtRange *RangeQueryParams `form:"canceled_at"`
CompletedAt int64 `form:"completed_at"`
CompletedAtRange *RangeQueryParams `form:"completed_at"`
Created int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
Customer string `form:"customer"`
ReleasedAt int64 `form:"released_at"`
ReleasedAtRange *RangeQueryParams `form:"released_at"`
Scheduled *bool `form:"scheduled"`
}
// SubscriptionScheduleCurrentPhase is a structure the current phase's period.
type SubscriptionScheduleCurrentPhase struct {
EndDate int64 `json:"end_date"`
StartDate int64 `json:"start_date"`
}
// SubscriptionScheduleInvoiceSettings is a structure representing the settings applied to invoices
// associated with a subscription schedule.
type SubscriptionScheduleInvoiceSettings struct {
DaysUntilDue int64 `json:"days_until_due"`
}
// SubscriptionSchedulePhaseItem represents plan details for a given phase
type SubscriptionSchedulePhaseItem struct {
BillingThresholds *SubscriptionItemBillingThresholds `json:"billing_thresholds"`
Plan *Plan `json:"plan"`
Quantity int64 `json:"quantity"`
}
// SubscriptionSchedulePhase is a structure a phase of a subscription schedule.
type SubscriptionSchedulePhase struct {
ApplicationFeePercent float64 `json:"application_fee_percent"`
Coupon *Coupon `json:"coupon"`
EndDate int64 `json:"end_date"`
Plans []*SubscriptionSchedulePhaseItem `json:"plans"`
StartDate int64 `json:"start_date"`
TaxPercent float64 `json:"tax_percent"`
TrialEnd int64 `json:"trial_end"`
}
// SubscriptionScheduleRenewalInterval represents the interval and duration of a schedule.
type SubscriptionScheduleRenewalInterval struct {
Interval PlanInterval `form:"interval"`
Length int64 `form:"length"`
}
// SubscriptionSchedule is the resource representing a Stripe subscription schedule.
type SubscriptionSchedule struct {
Billing SubscriptionBilling `json:"billing"`
BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"`
CanceledAt int64 `json:"canceled_at"`
CompletedAt int64 `json:"completed_at"`
Created int64 `json:"created"`
CurrentPhase *SubscriptionScheduleCurrentPhase `json:"current_phase"`
Customer *Customer `json:"customer"`
ID string `json:"id"`
InvoiceSettings *SubscriptionScheduleInvoiceSettings `json:"invoice_settings"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Object string `json:"object"`
Phases []*SubscriptionSchedulePhase `json:"phases"`
ReleasedSubscription *Subscription `json:"released_subscription"`
Revision *SubscriptionScheduleRevision `json:"revision"`
RenewalBehavior SubscriptionScheduleRenewalBehavior `json:"renewal_behavior"`
RenewalInterval *SubscriptionScheduleRenewalInterval `json:"renewal_interval"`
Status SubscriptionScheduleStatus `json:"status"`
Subscription *Subscription `json:"subscription"`
}
// SubscriptionScheduleList is a list object for subscription schedules.
type SubscriptionScheduleList struct {
ListMeta
Data []*SubscriptionSchedule `json:"data"`
}
// UnmarshalJSON handles deserialization of a SubscriptionSchedule.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (s *SubscriptionSchedule) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
s.ID = id
return nil
}
type schedule SubscriptionSchedule
var v schedule
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*s = SubscriptionSchedule(v)
return nil
}