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](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).

Constant Summary collapse

OBJECT_NAME =
"price"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

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

#==, #[], #[]=, 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

Class Method Details

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

Creates a new price for an existing product. The price can be recurring or one-time.



23
24
25
# File 'lib/stripe/resources/price.rb', line 23

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

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

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



28
29
30
# File 'lib/stripe/resources/price.rb', line 28

def self.list(filters = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/prices", params: filters, 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



32
33
34
# File 'lib/stripe/resources/price.rb', line 32

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



36
37
38
# File 'lib/stripe/resources/price.rb', line 36

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

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

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



41
42
43
44
45
46
47
48
# File 'lib/stripe/resources/price.rb', line 41

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