-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathprice.go
471 lines (424 loc) · 30.2 KB
/
price.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
//
//
// File generated from our OpenAPI spec
//
//
package stripe
import (
"encoding/json"
"github.com/stripe/stripe-go/v72/form"
)
// Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `unit_amount` or `unit_amount_decimal`) will be charged per unit in `quantity` (for prices with `usage_type=licensed`), or per unit of total usage (for prices with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.
type PriceBillingScheme string
// List of values that PriceBillingScheme can take
const (
PriceBillingSchemePerUnit PriceBillingScheme = "per_unit"
PriceBillingSchemeTiered PriceBillingScheme = "tiered"
)
// Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
type PriceCurrencyOptionsTaxBehavior string
// List of values that PriceCurrencyOptionsTaxBehavior can take
const (
PriceCurrencyOptionsTaxBehaviorExclusive PriceCurrencyOptionsTaxBehavior = "exclusive"
PriceCurrencyOptionsTaxBehaviorInclusive PriceCurrencyOptionsTaxBehavior = "inclusive"
PriceCurrencyOptionsTaxBehaviorUnspecified PriceCurrencyOptionsTaxBehavior = "unspecified"
)
// Specifies a usage aggregation strategy for prices of `usage_type=metered`. Allowed values are `sum` for summing up all usage during a period, `last_during_period` for using the last usage record reported within a period, `last_ever` for using the last usage record ever (across period bounds) or `max` which uses the usage record with the maximum reported usage during a period. Defaults to `sum`.
type PriceRecurringAggregateUsage string
// List of values that PriceRecurringAggregateUsage can take
const (
PriceRecurringAggregateUsageLastDuringPeriod PriceRecurringAggregateUsage = "last_during_period"
PriceRecurringAggregateUsageLastEver PriceRecurringAggregateUsage = "last_ever"
PriceRecurringAggregateUsageMax PriceRecurringAggregateUsage = "max"
PriceRecurringAggregateUsageSum PriceRecurringAggregateUsage = "sum"
)
// The frequency at which a subscription is billed. One of `day`, `week`, `month` or `year`.
type PriceRecurringInterval string
// List of values that PriceRecurringInterval can take
const (
PriceRecurringIntervalDay PriceRecurringInterval = "day"
PriceRecurringIntervalMonth PriceRecurringInterval = "month"
PriceRecurringIntervalWeek PriceRecurringInterval = "week"
PriceRecurringIntervalYear PriceRecurringInterval = "year"
)
// Configures how the quantity per period should be determined. Can be either `metered` or `licensed`. `licensed` automatically bills the `quantity` set when adding it to a subscription. `metered` aggregates the total usage based on usage records. Defaults to `licensed`.
type PriceRecurringUsageType string
// List of values that PriceRecurringUsageType can take
const (
PriceRecurringUsageTypeLicensed PriceRecurringUsageType = "licensed"
PriceRecurringUsageTypeMetered PriceRecurringUsageType = "metered"
)
// Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
type PriceTaxBehavior string
// List of values that PriceTaxBehavior can take
const (
PriceTaxBehaviorExclusive PriceTaxBehavior = "exclusive"
PriceTaxBehaviorInclusive PriceTaxBehavior = "inclusive"
PriceTaxBehaviorUnspecified PriceTaxBehavior = "unspecified"
)
// Defines if the tiering price should be `graduated` or `volume` based. In `volume`-based tiering, the maximum quantity within a period determines the per unit price. In `graduated` tiering, pricing can change as the quantity grows.
type PriceTiersMode string
// List of values that PriceTiersMode can take
const (
PriceTiersModeGraduated PriceTiersMode = "graduated"
PriceTiersModeVolume PriceTiersMode = "volume"
)
// After division, either round the result `up` or `down`.
type PriceTransformQuantityRound string
// List of values that PriceTransformQuantityRound can take
const (
PriceTransformQuantityRoundDown PriceTransformQuantityRound = "down"
PriceTransformQuantityRoundUp PriceTransformQuantityRound = "up"
)
// One of `one_time` or `recurring` depending on whether the price is for a one-time purchase or a recurring (subscription) purchase.
type PriceType string
// List of values that PriceType can take
const (
PriceTypeOneTime PriceType = "one_time"
PriceTypeRecurring PriceType = "recurring"
)
// Search for prices you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language).
// Don't use search in read-after-write flows where strict consistency is necessary. Under normal operating
// conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up
// to an hour behind during outages. Search functionality is not available to merchants in India.
type PriceSearchParams struct {
SearchParams `form:"*"`
// A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
Page *string `form:"page"`
}
// Only return prices with these recurring fields.
type PriceRecurringListParams struct {
// Filter by billing frequency. Either `day`, `week`, `month` or `year`.
Interval *string `form:"interval"`
// Filter by the usage type for this price. Can be either `metered` or `licensed`.
UsageType *string `form:"usage_type"`
}
// Returns a list of your prices.
type PriceListParams struct {
ListParams `form:"*"`
// Only return prices that are active or inactive (e.g., pass `false` to list all inactive prices).
Active *bool `form:"active"`
// A filter on the list, based on the object `created` field. The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options.
Created *int64 `form:"created"`
// A filter on the list, based on the object `created` field. The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options.
CreatedRange *RangeQueryParams `form:"created"`
// Only return prices for the given currency.
Currency *string `form:"currency"`
// Only return the price with these lookup_keys, if any exist.
LookupKeys []*string `form:"lookup_keys"`
// Only return prices for the given product.
Product *string `form:"product"`
// Only return prices with these recurring fields.
Recurring *PriceRecurringListParams `form:"recurring"`
// Only return prices of type `recurring` or `one_time`.
Type *string `form:"type"`
}
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
type PriceCurrencyOptionsCustomUnitAmountParams struct {
// Pass in `true` to enable `custom_unit_amount`, otherwise omit `custom_unit_amount`.
Enabled *bool `form:"enabled"`
// The maximum unit amount the customer can specify for this item.
Maximum *int64 `form:"maximum"`
// The minimum unit amount the customer can specify for this item. Must be at least the minimum charge amount.
Minimum *int64 `form:"minimum"`
// The starting unit amount which can be updated by the customer.
Preset *int64 `form:"preset"`
}
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
type PriceCurrencyOptionsTierParams struct {
// The flat billing amount for an entire tier, regardless of the number of units in the tier.
FlatAmount *int64 `form:"flat_amount"`
// Same as `flat_amount`, but accepts a decimal value representing an integer in the minor units of the currency. Only one of `flat_amount` and `flat_amount_decimal` can be set.
FlatAmountDecimal *float64 `form:"flat_amount_decimal,high_precision"`
// The per unit billing amount for each individual unit for which this tier applies.
UnitAmount *int64 `form:"unit_amount"`
// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
// Specifies the upper bound of this tier. The lower bound of a tier is the upper bound of the previous tier adding one. Use `inf` to define a fallback tier.
UpTo *int64 `form:"up_to"`
UpToInf *bool `form:"-"` // See custom AppendTo
}
// AppendTo implements custom encoding logic for PriceCurrencyOptionsTierParams.
func (p *PriceCurrencyOptionsTierParams) AppendTo(body *form.Values, keyParts []string) {
if BoolValue(p.UpToInf) {
body.Add(form.FormatKey(append(keyParts, "up_to")), "inf")
}
}
// Prices defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
type PriceCurrencyOptionsParams struct {
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
CustomUnitAmount *PriceCurrencyOptionsCustomUnitAmountParams `form:"custom_unit_amount"`
// Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
TaxBehavior *string `form:"tax_behavior"`
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
Tiers []*PriceCurrencyOptionsTierParams `form:"tiers"`
// A positive integer in cents (or local equivalent) (or 0 for a free price) representing how much to charge.
UnitAmount *int64 `form:"unit_amount"`
// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
}
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
type PriceCustomUnitAmountParams struct {
// Pass in `true` to enable `custom_unit_amount`, otherwise omit `custom_unit_amount`.
Enabled *bool `form:"enabled"`
// The maximum unit amount the customer can specify for this item.
Maximum *int64 `form:"maximum"`
// The minimum unit amount the customer can specify for this item. Must be at least the minimum charge amount.
Minimum *int64 `form:"minimum"`
// The starting unit amount which can be updated by the customer.
Preset *int64 `form:"preset"`
}
// These fields can be used to create a new product that this price will belong to.
type PriceProductDataParams struct {
// Whether the product is currently available for purchase. Defaults to `true`.
Active *bool `form:"active"`
// The identifier for the product. Must be unique. If not provided, an identifier will be randomly generated.
ID *string `form:"id"`
// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
Metadata map[string]string `form:"metadata"`
// The product's name, meant to be displayable to the customer.
Name *string `form:"name"`
// An arbitrary string to be displayed on your customer's credit card or bank statement. While most banks display this information consistently, some may display it incorrectly or not at all.
//
// This may be up to 22 characters. The statement description may not include `<`, `>`, `\`, `"`, `'` characters, and will appear on your customer's statement in capital letters. Non-ASCII characters are automatically stripped.
StatementDescriptor *string `form:"statement_descriptor"`
// A [tax code](https://stripe.com/docs/tax/tax-categories) ID.
TaxCode *string `form:"tax_code"`
// A label that represents units of this product in Stripe and on customers' receipts and invoices. When set, this will be included in associated invoice line item descriptions.
UnitLabel *string `form:"unit_label"`
}
// The recurring components of a price such as `interval` and `usage_type`.
type PriceRecurringParams struct {
// Specifies a usage aggregation strategy for prices of `usage_type=metered`. Allowed values are `sum` for summing up all usage during a period, `last_during_period` for using the last usage record reported within a period, `last_ever` for using the last usage record ever (across period bounds) or `max` which uses the usage record with the maximum reported usage during a period. Defaults to `sum`.
AggregateUsage *string `form:"aggregate_usage"`
// Specifies billing frequency. Either `day`, `week`, `month` or `year`.
Interval *string `form:"interval"`
// The number of intervals between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months. Maximum of one year interval allowed (1 year, 12 months, or 52 weeks).
IntervalCount *int64 `form:"interval_count"`
// Default number of trial days when subscribing a customer to this plan using [`trial_from_plan=true`](https://stripe.com/docs/api#create_subscription-trial_from_plan).
TrialPeriodDays *int64 `form:"trial_period_days"`
// Configures how the quantity per period should be determined. Can be either `metered` or `licensed`. `licensed` automatically bills the `quantity` set when adding it to a subscription. `metered` aggregates the total usage based on usage records. Defaults to `licensed`.
UsageType *string `form:"usage_type"`
}
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
type PriceTierParams struct {
// The flat billing amount for an entire tier, regardless of the number of units in the tier.
FlatAmount *int64 `form:"flat_amount"`
// Same as `flat_amount`, but accepts a decimal value representing an integer in the minor units of the currency. Only one of `flat_amount` and `flat_amount_decimal` can be set.
FlatAmountDecimal *float64 `form:"flat_amount_decimal,high_precision"`
// The per unit billing amount for each individual unit for which this tier applies.
UnitAmount *int64 `form:"unit_amount"`
// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
// Specifies the upper bound of this tier. The lower bound of a tier is the upper bound of the previous tier adding one. Use `inf` to define a fallback tier.
UpTo *int64 `form:"up_to"`
UpToInf *bool `form:"-"` // See custom AppendTo
}
// AppendTo implements custom encoding logic for PriceTierParams.
func (p *PriceTierParams) AppendTo(body *form.Values, keyParts []string) {
if BoolValue(p.UpToInf) {
body.Add(form.FormatKey(append(keyParts, "up_to")), "inf")
}
}
// Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with `tiers`.
type PriceTransformQuantityParams struct {
// Divide usage by this number.
DivideBy *int64 `form:"divide_by"`
// After division, either round the result `up` or `down`.
Round *string `form:"round"`
}
// Creates a new price for an existing product. The price can be recurring or one-time.
type PriceParams struct {
Params `form:"*"`
// Whether the price can be used for new purchases. Defaults to `true`.
Active *bool `form:"active"`
// Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `unit_amount` or `unit_amount_decimal`) will be charged per unit in `quantity` (for prices with `usage_type=licensed`), or per unit of total usage (for prices with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.
BillingScheme *string `form:"billing_scheme"`
// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
Currency *string `form:"currency"`
// Prices defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
CurrencyOptions map[string]*PriceCurrencyOptionsParams `form:"currency_options"`
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
CustomUnitAmount *PriceCustomUnitAmountParams `form:"custom_unit_amount"`
// A lookup key used to retrieve prices dynamically from a static string. This may be up to 200 characters.
LookupKey *string `form:"lookup_key"`
// A brief description of the price, hidden from customers.
Nickname *string `form:"nickname"`
// The ID of the product that this price will belong to.
Product *string `form:"product"`
// These fields can be used to create a new product that this price will belong to.
ProductData *PriceProductDataParams `form:"product_data"`
// The recurring components of a price such as `interval` and `usage_type`.
Recurring *PriceRecurringParams `form:"recurring"`
// Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
TaxBehavior *string `form:"tax_behavior"`
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
Tiers []*PriceTierParams `form:"tiers"`
// Defines if the tiering price should be `graduated` or `volume` based. In `volume`-based tiering, the maximum quantity within a period determines the per unit price, in `graduated` tiering pricing can successively change as the quantity grows.
TiersMode *string `form:"tiers_mode"`
// If set to true, will atomically remove the lookup key from the existing price, and assign it to this price.
TransferLookupKey *bool `form:"transfer_lookup_key"`
// Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with `tiers`.
TransformQuantity *PriceTransformQuantityParams `form:"transform_quantity"`
// A positive integer in cents (or local equivalent) (or 0 for a free price) representing how much to charge.
UnitAmount *int64 `form:"unit_amount"`
// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
}
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
type PriceCurrencyOptionsCustomUnitAmount struct {
// The maximum unit amount the customer can specify for this item.
Maximum int64 `json:"maximum"`
// The minimum unit amount the customer can specify for this item. Must be at least the minimum charge amount.
Minimum int64 `json:"minimum"`
// The starting unit amount which can be updated by the customer.
Preset int64 `json:"preset"`
}
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
type PriceCurrencyOptionsTier struct {
// Price for the entire tier.
FlatAmount int64 `json:"flat_amount"`
// Same as `flat_amount`, but contains a decimal value with at most 12 decimal places.
FlatAmountDecimal float64 `json:"flat_amount_decimal,string"`
// Per unit price for units relevant to the tier.
UnitAmount int64 `json:"unit_amount"`
// Same as `unit_amount`, but contains a decimal value with at most 12 decimal places.
UnitAmountDecimal float64 `json:"unit_amount_decimal,string"`
// Up to and including to this quantity will be contained in the tier.
UpTo int64 `json:"up_to"`
}
// Prices defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
type PriceCurrencyOptions struct {
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
CustomUnitAmount *PriceCurrencyOptionsCustomUnitAmount `json:"custom_unit_amount"`
// Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
TaxBehavior PriceCurrencyOptionsTaxBehavior `json:"tax_behavior"`
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
Tiers []*PriceCurrencyOptionsTier `json:"tiers"`
// The unit amount in %s to be charged, represented as a whole integer if possible. Only set if `billing_scheme=per_unit`.
UnitAmount int64 `json:"unit_amount"`
// The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places. Only set if `billing_scheme=per_unit`.
UnitAmountDecimal float64 `json:"unit_amount_decimal,string"`
}
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
type PriceCustomUnitAmount struct {
// The maximum unit amount the customer can specify for this item.
Maximum int64 `json:"maximum"`
// The minimum unit amount the customer can specify for this item. Must be at least the minimum charge amount.
Minimum int64 `json:"minimum"`
// The starting unit amount which can be updated by the customer.
Preset int64 `json:"preset"`
}
// The recurring components of a price such as `interval` and `usage_type`.
type PriceRecurring struct {
// Specifies a usage aggregation strategy for prices of `usage_type=metered`. Allowed values are `sum` for summing up all usage during a period, `last_during_period` for using the last usage record reported within a period, `last_ever` for using the last usage record ever (across period bounds) or `max` which uses the usage record with the maximum reported usage during a period. Defaults to `sum`.
AggregateUsage PriceRecurringAggregateUsage `json:"aggregate_usage"`
// The frequency at which a subscription is billed. One of `day`, `week`, `month` or `year`.
Interval PriceRecurringInterval `json:"interval"`
// The number of intervals (specified in the `interval` attribute) between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months.
IntervalCount int64 `json:"interval_count"`
// Default number of trial days when subscribing a customer to this price using [`trial_from_plan=true`](https://stripe.com/docs/api#create_subscription-trial_from_plan).
TrialPeriodDays int64 `json:"trial_period_days"`
// Configures how the quantity per period should be determined. Can be either `metered` or `licensed`. `licensed` automatically bills the `quantity` set when adding it to a subscription. `metered` aggregates the total usage based on usage records. Defaults to `licensed`.
UsageType PriceRecurringUsageType `json:"usage_type"`
}
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
type PriceTier struct {
// Price for the entire tier.
FlatAmount int64 `json:"flat_amount"`
// Same as `flat_amount`, but contains a decimal value with at most 12 decimal places.
FlatAmountDecimal float64 `json:"flat_amount_decimal,string"`
// Per unit price for units relevant to the tier.
UnitAmount int64 `json:"unit_amount"`
// Same as `unit_amount`, but contains a decimal value with at most 12 decimal places.
UnitAmountDecimal float64 `json:"unit_amount_decimal,string"`
// Up to and including to this quantity will be contained in the tier.
UpTo int64 `json:"up_to"`
}
// Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with `tiers`.
type PriceTransformQuantity struct {
// Divide usage by this number.
DivideBy int64 `json:"divide_by"`
// After division, either round the result `up` or `down`.
Round PriceTransformQuantityRound `json:"round"`
}
// Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products.
// [Products](https://stripe.com/docs/api#products) help you track inventory or provisioning, and prices help you track payment terms. Different physical goods or levels of service should be represented by products, and pricing options should be represented by prices. This approach lets you change prices without having to change your provisioning scheme.
//
// For example, you might have a single "gold" product that has prices for $10/month, $100/year, and €9 once.
//
// Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription), [create an invoice](https://stripe.com/docs/billing/invoices/create), and more about [products and prices](https://stripe.com/docs/products-prices/overview).
type Price struct {
APIResource
// Whether the price can be used for new purchases.
Active bool `json:"active"`
// Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `unit_amount` or `unit_amount_decimal`) will be charged per unit in `quantity` (for prices with `usage_type=licensed`), or per unit of total usage (for prices with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.
BillingScheme PriceBillingScheme `json:"billing_scheme"`
// Time at which the object was created. Measured in seconds since the Unix epoch.
Created int64 `json:"created"`
// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
Currency Currency `json:"currency"`
// Prices defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
CurrencyOptions map[string]*PriceCurrencyOptions `json:"currency_options"`
// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
CustomUnitAmount *PriceCustomUnitAmount `json:"custom_unit_amount"`
Deleted bool `json:"deleted"`
// Unique identifier for the object.
ID string `json:"id"`
// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
Livemode bool `json:"livemode"`
// A lookup key used to retrieve prices dynamically from a static string. This may be up to 200 characters.
LookupKey string `json:"lookup_key"`
// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
Metadata map[string]string `json:"metadata"`
// A brief description of the price, hidden from customers.
Nickname string `json:"nickname"`
// String representing the object's type. Objects of the same type share the same value.
Object string `json:"object"`
// The ID of the product this price is associated with.
Product *Product `json:"product"`
// The recurring components of a price such as `interval` and `usage_type`.
Recurring *PriceRecurring `json:"recurring"`
// Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
TaxBehavior PriceTaxBehavior `json:"tax_behavior"`
// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
Tiers []*PriceTier `json:"tiers"`
// Defines if the tiering price should be `graduated` or `volume` based. In `volume`-based tiering, the maximum quantity within a period determines the per unit price. In `graduated` tiering, pricing can change as the quantity grows.
TiersMode PriceTiersMode `json:"tiers_mode"`
// Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with `tiers`.
TransformQuantity *PriceTransformQuantity `json:"transform_quantity"`
// One of `one_time` or `recurring` depending on whether the price is for a one-time purchase or a recurring (subscription) purchase.
Type PriceType `json:"type"`
// The unit amount in %s to be charged, represented as a whole integer if possible. Only set if `billing_scheme=per_unit`.
UnitAmount int64 `json:"unit_amount"`
// The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places. Only set if `billing_scheme=per_unit`.
UnitAmountDecimal float64 `json:"unit_amount_decimal,string"`
}
// PriceList is a list of Prices as retrieved from a list endpoint.
type PriceList struct {
APIResource
ListMeta
Data []*Price `json:"data"`
}
// PriceSearchResult is a list of Price search results as retrieved from a search endpoint.
type PriceSearchResult struct {
APIResource
SearchMeta
Data []*Price `json:"data"`
}
// UnmarshalJSON handles deserialization of a Price.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (p *Price) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
p.ID = id
return nil
}
type price Price
var v price
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*p = Price(v)
return nil
}