-
Notifications
You must be signed in to change notification settings - Fork 448
/
subschedule.go
232 lines (203 loc) · 11.6 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package stripe
import (
"encoding/json"
)
// SubscriptionScheduleEndBehavior describe what happens to a schedule when it ends.
type SubscriptionScheduleEndBehavior string
// List of values that SubscriptionScheduleEndBehavior can take.
const (
SubscriptionScheduleEndBehaviorCancel SubscriptionScheduleEndBehavior = "cancel"
SubscriptionScheduleEndBehaviorNone SubscriptionScheduleEndBehavior = "none"
SubscriptionScheduleEndBehaviorRenew SubscriptionScheduleEndBehavior = "release"
SubscriptionScheduleEndBehaviorRelease SubscriptionScheduleEndBehavior = "renew"
)
// 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 (
SubscriptionScheduleRenewalBehaviorCancel SubscriptionScheduleRenewalBehavior = "cancel"
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"`
TaxRates []*string `form:"tax_rates"`
}
// 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"`
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
CollectionMethod *string `form:"collection_method"`
Coupon *string `form:"coupon"`
DefaultPaymentMethod *string `form:"default_payment_method"`
DefaultTaxRates []*string `form:"default_tax_rates"`
EndDate *int64 `form:"end_date"`
InvoiceSettings *SubscriptionScheduleInvoiceSettingsParams `form:"invoice_settings"`
Iterations *int64 `form:"iterations"`
Plans []*SubscriptionSchedulePhaseItemParams `form:"plans"`
StartDate *int64 `form:"start_date"`
Trial *bool `form:"trial"`
TrialEnd *int64 `form:"trial_end"`
// This parameter is deprecated and we recommend that you use TaxRates instead.
TaxPercent *float64 `form:"tax_percent"`
}
// 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:"*"`
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
CollectionMethod *string `form:"collection_method"`
Customer *string `form:"customer"`
DefaultPaymentMethod *string `form:"default_payment_method"`
DefaultSource *string `form:"default_source"`
EndBehavior *string `form:"end_behavior"`
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"`
// This parameter is deprecated and we recommend that you use CollectionMethod instead.
Billing *string `form:"billing"`
}
// 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"`
TaxRates []*TaxRate `json:"tax_rates"`
}
// SubscriptionSchedulePhase is a structure a phase of a subscription schedule.
type SubscriptionSchedulePhase struct {
ApplicationFeePercent float64 `json:"application_fee_percent"`
BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"`
CollectionMethod SubscriptionCollectionMethod `json:"collection_method"`
Coupon *Coupon `json:"coupon"`
DefaultPaymentMethod *PaymentMethod `json:"default_payment_method"`
DefaultTaxRates []*TaxRate `json:"default_tax_rates"`
EndDate int64 `json:"end_date"`
InvoiceSettings *SubscriptionScheduleInvoiceSettings `json:"invoice_settings"`
Plans []*SubscriptionSchedulePhaseItem `json:"plans"`
StartDate int64 `json:"start_date"`
TrialEnd int64 `json:"trial_end"`
// This field is deprecated and we recommend that you use TaxRates instead.
TaxPercent float64 `json:"tax_percent"`
}
// 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 {
BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"`
CanceledAt int64 `json:"canceled_at"`
CollectionMethod SubscriptionCollectionMethod `json:"collection_method"`
CompletedAt int64 `json:"completed_at"`
Created int64 `json:"created"`
CurrentPhase *SubscriptionScheduleCurrentPhase `json:"current_phase"`
Customer *Customer `json:"customer"`
DefaultPaymentMethod *PaymentMethod `json:"default_payment_method"`
DefaultSource *PaymentSource `json:"default_source"`
EndBehavior SubscriptionScheduleEndBehavior `json:"end_behavior"`
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"`
RenewalBehavior SubscriptionScheduleRenewalBehavior `json:"renewal_behavior"`
RenewalInterval *SubscriptionScheduleRenewalInterval `json:"renewal_interval"`
Status SubscriptionScheduleStatus `json:"status"`
Subscription *Subscription `json:"subscription"`
// This field is deprecated and we recommend that you use CollectionMethod instead.
Billing SubscriptionBilling `json:"billing"`
}
// 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
}