github.com/stripe/stripe-go/v76@v76.25.0/plan.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import ( 10 "encoding/json" 11 "github.com/stripe/stripe-go/v76/form" 12 "strconv" 13 ) 14 15 // Specifies a usage aggregation strategy for plans 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`. 16 type PlanAggregateUsage string 17 18 // List of values that PlanAggregateUsage can take 19 const ( 20 PlanAggregateUsageLastDuringPeriod PlanAggregateUsage = "last_during_period" 21 PlanAggregateUsageLastEver PlanAggregateUsage = "last_ever" 22 PlanAggregateUsageMax PlanAggregateUsage = "max" 23 PlanAggregateUsageSum PlanAggregateUsage = "sum" 24 ) 25 26 // Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans 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. 27 type PlanBillingScheme string 28 29 // List of values that PlanBillingScheme can take 30 const ( 31 PlanBillingSchemePerUnit PlanBillingScheme = "per_unit" 32 PlanBillingSchemeTiered PlanBillingScheme = "tiered" 33 ) 34 35 // The frequency at which a subscription is billed. One of `day`, `week`, `month` or `year`. 36 type PlanInterval string 37 38 // List of values that PlanInterval can take 39 const ( 40 PlanIntervalDay PlanInterval = "day" 41 PlanIntervalMonth PlanInterval = "month" 42 PlanIntervalWeek PlanInterval = "week" 43 PlanIntervalYear PlanInterval = "year" 44 ) 45 46 // 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. 47 type PlanTiersMode string 48 49 // List of values that PlanTiersMode can take 50 const ( 51 PlanTiersModeGraduated PlanTiersMode = "graduated" 52 PlanTiersModeVolume PlanTiersMode = "volume" 53 ) 54 55 // After division, either round the result `up` or `down`. 56 type PlanTransformUsageRound string 57 58 // List of values that PlanTransformUsageRound can take 59 const ( 60 PlanTransformUsageRoundDown PlanTransformUsageRound = "down" 61 PlanTransformUsageRoundUp PlanTransformUsageRound = "up" 62 ) 63 64 // 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`. 65 type PlanUsageType string 66 67 // List of values that PlanUsageType can take 68 const ( 69 PlanUsageTypeLicensed PlanUsageType = "licensed" 70 PlanUsageTypeMetered PlanUsageType = "metered" 71 ) 72 73 // Deleting plans means new subscribers can't be added. Existing subscribers aren't affected. 74 type PlanParams struct { 75 Params `form:"*"` 76 // Whether the plan is currently available for new subscriptions. Defaults to `true`. 77 Active *bool `form:"active"` 78 // Specifies a usage aggregation strategy for plans 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`. 79 AggregateUsage *string `form:"aggregate_usage"` 80 // A positive integer in cents (or local equivalent) (or 0 for a free plan) representing how much to charge on a recurring basis. 81 Amount *int64 `form:"amount"` 82 // Same as `amount`, but accepts a decimal value with at most 12 decimal places. Only one of `amount` and `amount_decimal` can be set. 83 AmountDecimal *float64 `form:"amount_decimal,high_precision"` 84 // Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans 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. 85 BillingScheme *string `form:"billing_scheme"` 86 // 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). 87 Currency *string `form:"currency"` 88 // Specifies which fields in the response should be expanded. 89 Expand []*string `form:"expand"` 90 // An identifier randomly generated by Stripe. Used to identify this plan when subscribing a customer. You can optionally override this ID, but the ID must be unique across all plans in your Stripe account. You can, however, use the same plan ID in both live and test modes. 91 ID *string `form:"id"` 92 // Specifies billing frequency. Either `day`, `week`, `month` or `year`. 93 Interval *string `form:"interval"` 94 // The number of intervals between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months. Maximum of three years interval allowed (3 years, 36 months, or 156 weeks). 95 IntervalCount *int64 `form:"interval_count"` 96 // 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`. 97 Metadata map[string]string `form:"metadata"` 98 // The meter tracking the usage of a metered price 99 Meter *string `form:"meter"` 100 // A brief description of the plan, hidden from customers. 101 Nickname *string `form:"nickname"` 102 // The product the plan belongs to. This cannot be changed once it has been used in a subscription or subscription schedule. 103 Product *PlanProductParams `form:"product"` 104 // The product the plan belongs to. This cannot be changed once it has been used in a subscription or subscription schedule. 105 ProductID *string `form:"product"` 106 // Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`. 107 Tiers []*PlanTierParams `form:"tiers"` 108 // 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. 109 TiersMode *string `form:"tiers_mode"` 110 // Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with `tiers`. 111 TransformUsage *PlanTransformUsageParams `form:"transform_usage"` 112 // 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). 113 TrialPeriodDays *int64 `form:"trial_period_days"` 114 // 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`. 115 UsageType *string `form:"usage_type"` 116 } 117 118 // AddExpand appends a new field to expand. 119 func (p *PlanParams) AddExpand(f string) { 120 p.Expand = append(p.Expand, &f) 121 } 122 123 // AddMetadata adds a new key-value pair to the Metadata. 124 func (p *PlanParams) AddMetadata(key string, value string) { 125 if p.Metadata == nil { 126 p.Metadata = make(map[string]string) 127 } 128 129 p.Metadata[key] = value 130 } 131 132 // Returns a list of your plans. 133 type PlanListParams struct { 134 ListParams `form:"*"` 135 // Only return plans that are active or inactive (e.g., pass `false` to list all inactive plans). 136 Active *bool `form:"active"` 137 // 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. 138 Created *int64 `form:"created"` 139 // 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. 140 CreatedRange *RangeQueryParams `form:"created"` 141 // Specifies which fields in the response should be expanded. 142 Expand []*string `form:"expand"` 143 // Only return plans for the given product. 144 Product *string `form:"product"` 145 } 146 147 // AddExpand appends a new field to expand. 148 func (p *PlanListParams) AddExpand(f string) { 149 p.Expand = append(p.Expand, &f) 150 } 151 152 type PlanProductParams struct { 153 // Whether the product is currently available for purchase. Defaults to `true`. 154 Active *bool `form:"active"` 155 // The identifier for the product. Must be unique. If not provided, an identifier will be randomly generated. 156 ID *string `form:"id"` 157 // 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`. 158 Metadata map[string]string `form:"metadata"` 159 // The product's name, meant to be displayable to the customer. 160 Name *string `form:"name"` 161 // 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. 162 // 163 // 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. 164 StatementDescriptor *string `form:"statement_descriptor"` 165 // A [tax code](https://stripe.com/docs/tax/tax-categories) ID. 166 TaxCode *string `form:"tax_code"` 167 // A label that represents units of this product. When set, this will be included in customers' receipts, invoices, Checkout, and the customer portal. 168 UnitLabel *string `form:"unit_label"` 169 } 170 171 // AddMetadata adds a new key-value pair to the Metadata. 172 func (p *PlanProductParams) AddMetadata(key string, value string) { 173 if p.Metadata == nil { 174 p.Metadata = make(map[string]string) 175 } 176 177 p.Metadata[key] = value 178 } 179 180 // Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`. 181 type PlanTierParams struct { 182 Params `form:"*"` 183 // The flat billing amount for an entire tier, regardless of the number of units in the tier. 184 FlatAmount *int64 `form:"flat_amount"` 185 // 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. 186 FlatAmountDecimal *float64 `form:"flat_amount_decimal,high_precision"` 187 // The per unit billing amount for each individual unit for which this tier applies. 188 UnitAmount *int64 `form:"unit_amount"` 189 // 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. 190 UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` 191 // 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. 192 UpTo *int64 `form:"-"` // See custom AppendTo 193 UpToInf *bool `form:"-"` // See custom AppendTo 194 } 195 196 // AppendTo implements custom encoding logic for PlanTierParams. 197 func (p *PlanTierParams) AppendTo(body *form.Values, keyParts []string) { 198 if BoolValue(p.UpToInf) { 199 body.Add(form.FormatKey(append(keyParts, "up_to")), "inf") 200 } else { 201 body.Add( 202 form.FormatKey(append(keyParts, "up_to")), 203 strconv.FormatInt(Int64Value(p.UpTo), 10), 204 ) 205 } 206 } 207 208 // Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with `tiers`. 209 type PlanTransformUsageParams struct { 210 // Divide usage by this number. 211 DivideBy *int64 `form:"divide_by"` 212 // After division, either round the result `up` or `down`. 213 Round *string `form:"round"` 214 } 215 216 // Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`. 217 type PlanTier struct { 218 // Price for the entire tier. 219 FlatAmount int64 `json:"flat_amount"` 220 // Same as `flat_amount`, but contains a decimal value with at most 12 decimal places. 221 FlatAmountDecimal float64 `json:"flat_amount_decimal,string"` 222 // Per unit price for units relevant to the tier. 223 UnitAmount int64 `json:"unit_amount"` 224 // Same as `unit_amount`, but contains a decimal value with at most 12 decimal places. 225 UnitAmountDecimal float64 `json:"unit_amount_decimal,string"` 226 // Up to and including to this quantity will be contained in the tier. 227 UpTo int64 `json:"up_to"` 228 } 229 230 // Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with `tiers`. 231 type PlanTransformUsage struct { 232 // Divide usage by this number. 233 DivideBy int64 `json:"divide_by"` 234 // After division, either round the result `up` or `down`. 235 Round PlanTransformUsageRound `json:"round"` 236 } 237 238 // You can now model subscriptions more flexibly using the [Prices API](https://stripe.com/docs/api#prices). It replaces the Plans API and is backwards compatible to simplify your migration. 239 // 240 // Plans define the base price, currency, and billing cycle for recurring purchases of products. 241 // [Products](https://stripe.com/docs/api#products) help you track inventory or provisioning, and plans help you track pricing. Different physical goods or levels of service should be represented by products, and pricing options should be represented by plans. This approach lets you change prices without having to change your provisioning scheme. 242 // 243 // For example, you might have a single "gold" product that has plans for $10/month, $100/year, €9/month, and €90/year. 244 // 245 // Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription) and more about [products and prices](https://stripe.com/docs/products-prices/overview). 246 type Plan struct { 247 APIResource 248 // Whether the plan can be used for new purchases. 249 Active bool `json:"active"` 250 // Specifies a usage aggregation strategy for plans 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`. 251 AggregateUsage PlanAggregateUsage `json:"aggregate_usage"` 252 // The unit amount in cents (or local equivalent) to be charged, represented as a whole integer if possible. Only set if `billing_scheme=per_unit`. 253 Amount int64 `json:"amount"` 254 // The unit amount in cents (or local equivalent) to be charged, represented as a decimal string with at most 12 decimal places. Only set if `billing_scheme=per_unit`. 255 AmountDecimal float64 `json:"amount_decimal,string"` 256 // Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans 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. 257 BillingScheme PlanBillingScheme `json:"billing_scheme"` 258 // Time at which the object was created. Measured in seconds since the Unix epoch. 259 Created int64 `json:"created"` 260 // 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). 261 Currency Currency `json:"currency"` 262 Deleted bool `json:"deleted"` 263 // Unique identifier for the object. 264 ID string `json:"id"` 265 // The frequency at which a subscription is billed. One of `day`, `week`, `month` or `year`. 266 Interval PlanInterval `json:"interval"` 267 // The number of intervals (specified in the `interval` attribute) between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months. 268 IntervalCount int64 `json:"interval_count"` 269 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 270 Livemode bool `json:"livemode"` 271 // 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. 272 Metadata map[string]string `json:"metadata"` 273 // The meter tracking the usage of a metered price 274 Meter string `json:"meter"` 275 // A brief description of the plan, hidden from customers. 276 Nickname string `json:"nickname"` 277 // String representing the object's type. Objects of the same type share the same value. 278 Object string `json:"object"` 279 // The product whose pricing this plan determines. 280 Product *Product `json:"product"` 281 // Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`. 282 Tiers []*PlanTier `json:"tiers"` 283 // 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. 284 TiersMode PlanTiersMode `json:"tiers_mode"` 285 // Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with `tiers`. 286 TransformUsage *PlanTransformUsage `json:"transform_usage"` 287 // 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). 288 TrialPeriodDays int64 `json:"trial_period_days"` 289 // 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`. 290 UsageType PlanUsageType `json:"usage_type"` 291 } 292 293 // PlanList is a list of Plans as retrieved from a list endpoint. 294 type PlanList struct { 295 APIResource 296 ListMeta 297 Data []*Plan `json:"data"` 298 } 299 300 // UnmarshalJSON handles deserialization of a Plan. 301 // This custom unmarshaling is needed because the resulting 302 // property may be an id or the full struct if it was expanded. 303 func (p *Plan) UnmarshalJSON(data []byte) error { 304 if id, ok := ParseID(data); ok { 305 p.ID = id 306 return nil 307 } 308 309 type plan Plan 310 var v plan 311 if err := json.Unmarshal(data, &v); err != nil { 312 return err 313 } 314 315 *p = Plan(v) 316 return nil 317 }