Class: Stripe::Price
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::Price
- 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](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](stripe.com/docs/billing/subscriptions/set-up-subscription), [create an invoice](stripe.com/docs/billing/invoices/create), and more about [products and prices](stripe.com/docs/products-prices/overview).
Defined Under Namespace
Classes: CreateParams, CurrencyOptions, CustomUnitAmount, ListParams, MigrateTo, Recurring, SearchParams, Tier, TransformQuantity, UpdateParams
Constant Summary collapse
- OBJECT_NAME =
"price"
Constants inherited from StripeObject
StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Whether the price can be used for new purchases.
-
#billing_scheme ⇒ Object
readonly
Describes how to compute the price per period.
-
#created ⇒ Object
readonly
Time at which the object was created.
-
#currency ⇒ Object
readonly
Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase.
-
#currency_options ⇒ Object
readonly
Prices defined in each available currency option.
-
#custom_unit_amount ⇒ Object
readonly
When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
-
#deleted ⇒ Object
readonly
Always true for a deleted object.
-
#id ⇒ Object
readonly
Unique identifier for the object.
-
#livemode ⇒ Object
readonly
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
-
#lookup_key ⇒ Object
readonly
A lookup key used to retrieve prices dynamically from a static string.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object.
-
#migrate_to ⇒ Object
readonly
Subscriptions using this price will be migrated to use the new referenced price.
-
#nickname ⇒ Object
readonly
A brief description of the price, hidden from customers.
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#product ⇒ Object
readonly
The ID of the product this price is associated with.
-
#recurring ⇒ Object
readonly
The recurring components of a price such as ‘interval` and `usage_type`.
-
#tax_behavior ⇒ Object
readonly
Only required if a [default tax behavior](stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#setting-a-default-tax-behavior-(recommended)) was not provided in the Stripe Tax settings.
-
#tiers ⇒ Object
readonly
Each element represents a pricing tier.
-
#tiers_mode ⇒ Object
readonly
Defines if the tiering price should be ‘graduated` or `volume` based.
-
#transform_quantity ⇒ Object
readonly
Apply a transformation to the reported usage or set quantity before computing the amount billed.
-
#type ⇒ Object
readonly
One of ‘one_time` or `recurring` depending on whether the price is for a one-time purchase or a recurring (subscription) purchase.
-
#unit_amount ⇒ Object
readonly
The unit amount in cents (or local equivalent) to be charged, represented as a whole integer if possible.
-
#unit_amount_decimal ⇒ Object
readonly
The unit amount in cents (or local equivalent) to be charged, represented as a decimal string with at most 12 decimal places.
Attributes inherited from APIResource
Attributes inherited from StripeObject
Class Method Summary collapse
-
.create(params = {}, opts = {}) ⇒ Object
Creates a new [Price for an existing <a href=“docs.stripe.com/api/products”>Product](docs.stripe.com/api/prices).
- .field_remappings ⇒ Object
- .inner_class_types ⇒ Object
-
.list(params = {}, opts = {}) ⇒ Object
Returns a list of your active prices, excluding [inline prices](docs.stripe.com/docs/products-prices/pricing-models#inline-pricing).
- .object_name ⇒ Object
- .search(params = {}, opts = {}) ⇒ Object
- .search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
-
.update(price, params = {}, opts = {}) ⇒ Object
Updates the specified price by setting the values of the parameters passed.
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::Search
Methods included from APIOperations::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
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
#active ⇒ Object (readonly)
Whether the price can be used for new purchases.
674 675 676 |
# File 'lib/stripe/resources/price.rb', line 674 def active @active end |
#billing_scheme ⇒ Object (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.
676 677 678 |
# File 'lib/stripe/resources/price.rb', line 676 def billing_scheme @billing_scheme end |
#created ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
678 679 680 |
# File 'lib/stripe/resources/price.rb', line 678 def created @created end |
#currency ⇒ Object (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).
680 681 682 |
# File 'lib/stripe/resources/price.rb', line 680 def currency @currency end |
#currency_options ⇒ Object (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).
682 683 684 |
# File 'lib/stripe/resources/price.rb', line 682 def @currency_options end |
#custom_unit_amount ⇒ Object (readonly)
When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
684 685 686 |
# File 'lib/stripe/resources/price.rb', line 684 def custom_unit_amount @custom_unit_amount end |
#deleted ⇒ Object (readonly)
Always true for a deleted object
718 719 720 |
# File 'lib/stripe/resources/price.rb', line 718 def deleted @deleted end |
#id ⇒ Object (readonly)
Unique identifier for the object.
686 687 688 |
# File 'lib/stripe/resources/price.rb', line 686 def id @id end |
#livemode ⇒ Object (readonly)
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
688 689 690 |
# File 'lib/stripe/resources/price.rb', line 688 def livemode @livemode end |
#lookup_key ⇒ Object (readonly)
A lookup key used to retrieve prices dynamically from a static string. This may be up to 200 characters.
690 691 692 |
# File 'lib/stripe/resources/price.rb', line 690 def lookup_key @lookup_key end |
#metadata ⇒ Object (readonly)
Set of [key-value pairs](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.
692 693 694 |
# File 'lib/stripe/resources/price.rb', line 692 def @metadata end |
#migrate_to ⇒ Object (readonly)
Subscriptions using this price will be migrated to use the new referenced price.
694 695 696 |
# File 'lib/stripe/resources/price.rb', line 694 def migrate_to @migrate_to end |
#nickname ⇒ Object (readonly)
A brief description of the price, hidden from customers.
696 697 698 |
# File 'lib/stripe/resources/price.rb', line 696 def nickname @nickname end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
698 699 700 |
# File 'lib/stripe/resources/price.rb', line 698 def object @object end |
#product ⇒ Object (readonly)
The ID of the product this price is associated with.
700 701 702 |
# File 'lib/stripe/resources/price.rb', line 700 def product @product end |
#recurring ⇒ Object (readonly)
The recurring components of a price such as ‘interval` and `usage_type`.
702 703 704 |
# File 'lib/stripe/resources/price.rb', line 702 def recurring @recurring end |
#tax_behavior ⇒ Object (readonly)
Only required if a [default tax behavior](stripe.com/docs/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.
704 705 706 |
# File 'lib/stripe/resources/price.rb', line 704 def tax_behavior @tax_behavior end |
#tiers ⇒ Object (readonly)
Each element represents a pricing tier. This parameter requires ‘billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
706 707 708 |
# File 'lib/stripe/resources/price.rb', line 706 def tiers @tiers end |
#tiers_mode ⇒ Object (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.
708 709 710 |
# File 'lib/stripe/resources/price.rb', line 708 def tiers_mode @tiers_mode end |
#transform_quantity ⇒ Object (readonly)
Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with ‘tiers`.
710 711 712 |
# File 'lib/stripe/resources/price.rb', line 710 def transform_quantity @transform_quantity end |
#type ⇒ Object (readonly)
One of ‘one_time` or `recurring` depending on whether the price is for a one-time purchase or a recurring (subscription) purchase.
712 713 714 |
# File 'lib/stripe/resources/price.rb', line 712 def type @type end |
#unit_amount ⇒ Object (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`.
714 715 716 |
# File 'lib/stripe/resources/price.rb', line 714 def unit_amount @unit_amount end |
#unit_amount_decimal ⇒ Object (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`.
716 717 718 |
# File 'lib/stripe/resources/price.rb', line 716 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.
721 722 723 |
# File 'lib/stripe/resources/price.rb', line 721 def self.create(params = {}, opts = {}) request_stripe_object(method: :post, path: "/v1/prices", params: params, opts: opts) end |
.field_remappings ⇒ Object
759 760 761 |
# File 'lib/stripe/resources/price.rb', line 759 def self.field_remappings @field_remappings = {} end |
.inner_class_types ⇒ Object
748 749 750 751 752 753 754 755 756 757 |
# File 'lib/stripe/resources/price.rb', line 748 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.
726 727 728 |
# File 'lib/stripe/resources/price.rb', line 726 def self.list(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/prices", params: params, opts: opts) end |
.object_name ⇒ Object
18 19 20 |
# File 'lib/stripe/resources/price.rb', line 18 def self.object_name "price" end |
.search(params = {}, opts = {}) ⇒ Object
730 731 732 |
# File 'lib/stripe/resources/price.rb', line 730 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
734 735 736 |
# File 'lib/stripe/resources/price.rb', line 734 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.
739 740 741 742 743 744 745 746 |
# File 'lib/stripe/resources/price.rb', line 739 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 |