forked from stripe/stripe-go
/
subschedule.go
230 lines (201 loc) · 11.3 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
package stripe
import (
"encoding/json"
"github.com/stripe/stripe-go/form"
)
// SubscriptionScheduleEndBehavior describe what happens to a schedule when it ends.
type SubscriptionScheduleEndBehavior string
// List of values that SubscriptionScheduleEndBehavior can take.
const (
SubscriptionScheduleEndBehaviorCancel SubscriptionScheduleEndBehavior = "cancel"
SubscriptionScheduleEndBehaviorRelease SubscriptionScheduleEndBehavior = "release"
)
// 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"
)
// 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"`
}
// SubscriptionScheduleDefaultSettingsParams is the set of parameters
// representing the subscription schedule’s default settings.
type SubscriptionScheduleDefaultSettingsParams struct {
Params `form:"*"`
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
CollectionMethod *string `form:"collection_method"`
DefaultPaymentMethod *string `form:"default_payment_method"`
InvoiceSettings *SubscriptionScheduleInvoiceSettingsParams `form:"invoice_settings"`
}
// 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"`
ProrationBehavior *string `form:"proration_behavior"`
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"`
}
// SubscriptionScheduleParams is the set of parameters that can be used when creating or updating a
// subscription schedule.
type SubscriptionScheduleParams struct {
Params `form:"*"`
Customer *string `form:"customer"`
DefaultSettings *SubscriptionScheduleDefaultSettingsParams `form:"default_settings"`
EndBehavior *string `form:"end_behavior"`
FromSubscription *string `form:"from_subscription"`
ProrationBehavior *string `form:"proration_behavior"`
Phases []*SubscriptionSchedulePhaseParams `form:"phases"`
StartDate *int64 `form:"start_date"`
StartDateNow *bool `form:"-"` // See custom AppendTo
// TODO remove in the next major version
// This propery is considered deprecated. Use ProrationBehavior instead
Prorate *bool `form:"prorate"`
}
// AppendTo implements custom encoding logic for SubscriptionScheduleParams so that the special
// "now" value for start_date can be implemented (they're otherwise timestamps rather than strings).
func (p *SubscriptionScheduleParams) AppendTo(body *form.Values, keyParts []string) {
if BoolValue(p.StartDateNow) {
body.Add(form.FormatKey(append(keyParts, "start_date")), "now")
}
}
// 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"`
}
// SubscriptionScheduleDefaultSettings is a structure representing the
// subscription schedule’s default settings.
type SubscriptionScheduleDefaultSettings struct {
BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"`
CollectionMethod SubscriptionCollectionMethod `json:"collection_method"`
DefaultPaymentMethod *PaymentMethod `json:"default_payment_method"`
InvoiceSettings *SubscriptionScheduleInvoiceSettings `json:"invoice_settings"`
}
// 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 {
CanceledAt int64 `json:"canceled_at"`
CompletedAt int64 `json:"completed_at"`
Created int64 `json:"created"`
CurrentPhase *SubscriptionScheduleCurrentPhase `json:"current_phase"`
Customer *Customer `json:"customer"`
DefaultSettings *SubscriptionScheduleDefaultSettings `json:"default_settings"`
EndBehavior SubscriptionScheduleEndBehavior `json:"end_behavior"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Object string `json:"object"`
Phases []*SubscriptionSchedulePhase `json:"phases"`
ReleasedSubscription *Subscription `json:"released_subscription"`
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
}