Class: Stripe::Price

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List, APIOperations::Search
Includes:
APIOperations::Save
Defined in:
lib/stripe/resources/price.rb

Overview

Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products. [Products](api.stripe.com#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](docs.stripe.com/billing/subscriptions/set-up-subscription), [create an invoice](docs.stripe.com/billing/invoices/create), and more about [products and prices](docs.stripe.com/products-prices/overview).

Defined Under Namespace

Classes: CurrencyOptions, CustomUnitAmount, MigrateTo, Recurring, Tier, TransformQuantity

Constant Summary collapse

OBJECT_NAME =
"price"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Search

_search

Methods included from APIOperations::Save

included, #save

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, #_get_inner_class_type, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#activeObject (readonly)

Whether the price can be used for new purchases.



198
199
200
# File 'lib/stripe/resources/price.rb', line 198

def active
  @active
end

#billing_schemeObject (readonly)

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.



200
201
202
# File 'lib/stripe/resources/price.rb', line 200

def billing_scheme
  @billing_scheme
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



202
203
204
# File 'lib/stripe/resources/price.rb', line 202

def created
  @created
end

#currencyObject (readonly)

Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](stripe.com/docs/currencies).



204
205
206
# File 'lib/stripe/resources/price.rb', line 204

def currency
  @currency
end

#currency_optionsObject (readonly)

Prices defined in each available currency option. Each key must be a three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html) and a [supported currency](stripe.com/docs/currencies).



206
207
208
# File 'lib/stripe/resources/price.rb', line 206

def currency_options
  @currency_options
end

#custom_unit_amountObject (readonly)

When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.



208
209
210
# File 'lib/stripe/resources/price.rb', line 208

def custom_unit_amount
  @custom_unit_amount
end

#deletedObject (readonly)

Always true for a deleted object



210
211
212
# File 'lib/stripe/resources/price.rb', line 210

def deleted
  @deleted
end

#external_referenceObject (readonly)

A custom identifier for this price, such as a SKU number or product code, that can be used to reference records from external systems.



212
213
214
# File 'lib/stripe/resources/price.rb', line 212

def external_reference
  @external_reference
end

#idObject (readonly)

Unique identifier for the object.



214
215
216
# File 'lib/stripe/resources/price.rb', line 214

def id
  @id
end

#livemodeObject (readonly)

If the object exists in live mode, the value is ‘true`. If the object exists in test mode, the value is `false`.



216
217
218
# File 'lib/stripe/resources/price.rb', line 216

def livemode
  @livemode
end

#lookup_keyObject (readonly)

A lookup key used to retrieve prices dynamically from a static string. This may be up to 200 characters.



218
219
220
# File 'lib/stripe/resources/price.rb', line 218

def lookup_key
  @lookup_key
end

#metadataObject (readonly)

Set of [key-value pairs](docs.stripe.com/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



220
221
222
# File 'lib/stripe/resources/price.rb', line 220

def 
  @metadata
end

#migrate_toObject (readonly)

Subscriptions using this price will be migrated to use the new referenced price.



222
223
224
# File 'lib/stripe/resources/price.rb', line 222

def migrate_to
  @migrate_to
end

#nicknameObject (readonly)

A brief description of the price, hidden from customers.



224
225
226
# File 'lib/stripe/resources/price.rb', line 224

def nickname
  @nickname
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



226
227
228
# File 'lib/stripe/resources/price.rb', line 226

def object
  @object
end

#productObject (readonly)

The ID of the product this price is associated with.



228
229
230
# File 'lib/stripe/resources/price.rb', line 228

def product
  @product
end

#recurringObject (readonly)

The recurring components of a price such as ‘interval` and `usage_type`.



230
231
232
# File 'lib/stripe/resources/price.rb', line 230

def recurring
  @recurring
end

#tax_behaviorObject (readonly)

Only required if a [default tax behavior](docs.stripe.com/tax/products-prices-tax-categories-tax-behavior#setting-a-default-tax-behavior-(recommended)) was not provided in the Stripe Tax settings. 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.



232
233
234
# File 'lib/stripe/resources/price.rb', line 232

def tax_behavior
  @tax_behavior
end

#tiersObject (readonly)

Each element represents a pricing tier. This parameter requires ‘billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.



234
235
236
# File 'lib/stripe/resources/price.rb', line 234

def tiers
  @tiers
end

#tiers_modeObject (readonly)

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.



236
237
238
# File 'lib/stripe/resources/price.rb', line 236

def tiers_mode
  @tiers_mode
end

#transform_quantityObject (readonly)

Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with ‘tiers`.



238
239
240
# File 'lib/stripe/resources/price.rb', line 238

def transform_quantity
  @transform_quantity
end

#typeObject (readonly)

One of ‘one_time` or `recurring` depending on whether the price is for a one-time purchase or a recurring (subscription) purchase.



240
241
242
# File 'lib/stripe/resources/price.rb', line 240

def type
  @type
end

#unit_amountObject (readonly)

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`.



242
243
244
# File 'lib/stripe/resources/price.rb', line 242

def unit_amount
  @unit_amount
end

#unit_amount_decimalObject (readonly)

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`.



244
245
246
# File 'lib/stripe/resources/price.rb', line 244

def unit_amount_decimal
  @unit_amount_decimal
end

Class Method Details

.create(params = {}, opts = {}) ⇒ Object

Creates a new [Price for an existing <a href=“docs.stripe.com/api/products”>Product](docs.stripe.com/api/prices). The Price can be recurring or one-time.



247
248
249
# File 'lib/stripe/resources/price.rb', line 247

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/prices", params: params, opts: opts)
end

.field_encodingsObject



289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/stripe/resources/price.rb', line 289

def self.field_encodings
  @field_encodings = {
    tiers: {
      kind: :array,
      element: {
        kind: :object,
        fields: { flat_amount_decimal: :decimal_string, unit_amount_decimal: :decimal_string },
      },
    },
    unit_amount_decimal: :decimal_string,
  }
end

.field_remappingsObject



285
286
287
# File 'lib/stripe/resources/price.rb', line 285

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



274
275
276
277
278
279
280
281
282
283
# File 'lib/stripe/resources/price.rb', line 274

def self.inner_class_types
  @inner_class_types = {
    currency_options: CurrencyOptions,
    custom_unit_amount: CustomUnitAmount,
    migrate_to: MigrateTo,
    recurring: Recurring,
    tiers: Tier,
    transform_quantity: TransformQuantity,
  }
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of your active prices, excluding [inline prices](docs.stripe.com/docs/products-prices/pricing-models#inline-pricing). For the list of inactive prices, set active to false.



252
253
254
# File 'lib/stripe/resources/price.rb', line 252

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/prices", params: params, opts: opts)
end

.object_nameObject



18
19
20
# File 'lib/stripe/resources/price.rb', line 18

def self.object_name
  "price"
end

.search(params = {}, opts = {}) ⇒ Object



256
257
258
# File 'lib/stripe/resources/price.rb', line 256

def self.search(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/prices/search", params: params, opts: opts)
end

.search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object



260
261
262
# File 'lib/stripe/resources/price.rb', line 260

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
  search(params, opts).auto_paging_each(&blk)
end

.update(price, params = {}, opts = {}) ⇒ Object

Updates the specified price by setting the values of the parameters passed. Any parameters not provided are left unchanged.



265
266
267
268
269
270
271
272
# File 'lib/stripe/resources/price.rb', line 265

def self.update(price, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/prices/%<price>s", { price: CGI.escape(price) }),
    params: params,
    opts: opts
  )
end