forked from recurly/recurly-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_on.go
222 lines (173 loc) · 8.76 KB
/
add_on.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
// This file is automatically created by Recurly's OpenAPI generation process
// and thus any edits you make by hand will be lost. If you wish to make a
// change to this file, please create a Github issue explaining the changes you
// need and we will usher them to the appropriate places.
package recurly
import (
"context"
"net/http"
"time"
)
type AddOn struct {
recurlyResponse *ResponseMetadata
// Add-on ID
Id string `json:"id,omitempty"`
// Object type
Object string `json:"object,omitempty"`
// Plan ID
PlanId string `json:"plan_id,omitempty"`
// The unique identifier for the add-on within its plan.
Code string `json:"code,omitempty"`
// Add-ons can be either active or inactive.
State string `json:"state,omitempty"`
// Describes your add-on and will appear in subscribers' invoices.
Name string `json:"name,omitempty"`
// Whether the add-on type is fixed, or usage-based.
AddOnType string `json:"add_on_type,omitempty"`
// Type of usage, returns usage type if `add_on_type` is `usage`.
UsageType string `json:"usage_type,omitempty"`
// The type of calculation to be employed for an add-on. Cumulative billing will sum all usage records created in the current billing cycle. Last-in-period billing will apply only the most recent usage record in the billing period. If no value is specified, cumulative billing will be used.
UsageCalculationType string `json:"usage_calculation_type,omitempty"`
// The percentage taken of the monetary amount of usage tracked. This can be up to 4 decimal places. A value between 0.0 and 100.0.
UsagePercentage float64 `json:"usage_percentage,omitempty"`
// System-generated unique identifier for an measured unit associated with the add-on.
MeasuredUnitId string `json:"measured_unit_id,omitempty"`
// The ID of a general ledger account. General ledger accounts are
// only accessible as a part of the Recurly RevRec Standard and
// Recurly RevRec Advanced features.
LiabilityGlAccountId string `json:"liability_gl_account_id,omitempty"`
// The ID of a general ledger account. General ledger accounts are
// only accessible as a part of the Recurly RevRec Standard and
// Recurly RevRec Advanced features.
RevenueGlAccountId string `json:"revenue_gl_account_id,omitempty"`
// The ID of a performance obligation. Performance obligations are
// only accessible as a part of the Recurly RevRec Standard and
// Recurly RevRec Advanced features.
PerformanceObligationId string `json:"performance_obligation_id,omitempty"`
// Accounting code for invoice line items for this add-on. If no value is provided, it defaults to add-on's code.
AccountingCode string `json:"accounting_code,omitempty"`
// When this add-on is invoiced, the line item will use this revenue schedule. If `item_code`/`item_id` is part of the request then `revenue_schedule_type` must be absent in the request as the value will be set from the item.
RevenueScheduleType string `json:"revenue_schedule_type,omitempty"`
// Used by Avalara for Communications taxes. The transaction type in combination with the service type describe how the add-on is taxed. Refer to [the documentation](https://help.avalara.com/AvaTax_for_Communications/Tax_Calculation/AvaTax_for_Communications_Tax_Engine/Mapping_Resources/TM_00115_AFC_Modules_Corresponding_Transaction_Types) for more available t/s types.
AvalaraTransactionType int `json:"avalara_transaction_type,omitempty"`
// Used by Avalara for Communications taxes. The transaction type in combination with the service type describe how the add-on is taxed. Refer to [the documentation](https://help.avalara.com/AvaTax_for_Communications/Tax_Calculation/AvaTax_for_Communications_Tax_Engine/Mapping_Resources/TM_00115_AFC_Modules_Corresponding_Transaction_Types) for more available t/s types.
AvalaraServiceType int `json:"avalara_service_type,omitempty"`
// Optional field used by Avalara, Vertex, and Recurly's In-the-Box tax solution to determine taxation rules. You can pass in specific tax codes using any of these tax integrations. For Recurly's In-the-Box tax offering you can also choose to instead use simple values of `unknown`, `physical`, or `digital` tax codes. If `item_code`/`item_id` is part of the request then `tax_code` must be absent.
TaxCode string `json:"tax_code,omitempty"`
// Determines if the quantity field is displayed on the hosted pages for the add-on.
DisplayQuantity bool `json:"display_quantity,omitempty"`
// Default quantity for the hosted pages.
DefaultQuantity int `json:"default_quantity,omitempty"`
// Whether the add-on is optional for the customer to include in their purchase on the hosted payment page. If false, the add-on will be included when a subscription is created through the Recurly UI. However, the add-on will not be included when a subscription is created through the API.
Optional bool `json:"optional,omitempty"`
// Add-on pricing
Currencies []AddOnPricing `json:"currencies,omitempty"`
// Just the important parts.
Item ItemMini `json:"item,omitempty"`
// The pricing model for the add-on. For more information,
// [click here](https://docs.recurly.com/docs/billing-models#section-quantity-based). See our
// [Guide](https://recurly.com/developers/guides/item-addon-guide.html) for an overview of how
// to configure quantity-based pricing models.
TierType string `json:"tier_type,omitempty"`
// The time at which usage totals are reset for billing purposes.
UsageTimeframe string `json:"usage_timeframe,omitempty"`
// Tiers
Tiers []Tier `json:"tiers,omitempty"`
// This feature is currently in development and requires approval and enablement, please contact support.
PercentageTiers []PercentageTiersByCurrency `json:"percentage_tiers,omitempty"`
// Optional, stock keeping unit to link the item to other inventory systems.
ExternalSku string `json:"external_sku,omitempty"`
// Created at
CreatedAt time.Time `json:"created_at,omitempty"`
// Last updated at
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Deleted at
DeletedAt time.Time `json:"deleted_at,omitempty"`
}
// GetResponse returns the ResponseMetadata that generated this resource
func (resource *AddOn) GetResponse() *ResponseMetadata {
return resource.recurlyResponse
}
// setResponse sets the ResponseMetadata that generated this resource
func (resource *AddOn) setResponse(res *ResponseMetadata) {
resource.recurlyResponse = res
}
// internal struct for deserializing accounts
type addOnList struct {
ListMetadata
Data []AddOn `json:"data"`
recurlyResponse *ResponseMetadata
}
// GetResponse returns the ResponseMetadata that generated this resource
func (resource *addOnList) GetResponse() *ResponseMetadata {
return resource.recurlyResponse
}
// setResponse sets the ResponseMetadata that generated this resource
func (resource *addOnList) setResponse(res *ResponseMetadata) {
resource.recurlyResponse = res
}
// AddOnList allows you to paginate AddOn objects
type AddOnList struct {
client HTTPCaller
requestOptions *RequestOptions
nextPagePath string
hasMore bool
data []AddOn
}
func NewAddOnList(client HTTPCaller, nextPagePath string, requestOptions *RequestOptions) *AddOnList {
return &AddOnList{
client: client,
requestOptions: requestOptions,
nextPagePath: nextPagePath,
hasMore: true,
}
}
type AddOnLister interface {
Fetch() error
FetchWithContext(ctx context.Context) error
Count() (*int64, error)
CountWithContext(ctx context.Context) (*int64, error)
Data() []AddOn
HasMore() bool
Next() string
}
func (list *AddOnList) HasMore() bool {
return list.hasMore
}
func (list *AddOnList) Next() string {
return list.nextPagePath
}
func (list *AddOnList) Data() []AddOn {
return list.data
}
// Fetch fetches the next page of data into the `Data` property
func (list *AddOnList) FetchWithContext(ctx context.Context) error {
resources := &addOnList{}
err := list.client.Call(ctx, http.MethodGet, list.nextPagePath, nil, nil, list.requestOptions, resources)
if err != nil {
return err
}
// copy over properties from the response
list.nextPagePath = resources.Next
list.hasMore = resources.HasMore
list.data = resources.Data
return nil
}
// Fetch fetches the next page of data into the `Data` property
func (list *AddOnList) Fetch() error {
return list.FetchWithContext(context.Background())
}
// Count returns the count of items on the server that match this pager
func (list *AddOnList) CountWithContext(ctx context.Context) (*int64, error) {
resources := &addOnList{}
err := list.client.Call(ctx, http.MethodHead, list.nextPagePath, nil, nil, list.requestOptions, resources)
if err != nil {
return nil, err
}
resp := resources.GetResponse()
return resp.TotalRecords, nil
}
// Count returns the count of items on the server that match this pager
func (list *AddOnList) Count() (*int64, error) {
return list.CountWithContext(context.Background())
}