Class: Stripe::Product

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

Overview

Products describe the specific goods or services you offer to your customers. For example, you might offer a Standard and Premium version of your goods or service; each version would be a separate Product. They can be used in conjunction with [Prices](stripe.com/docs/api#prices) to configure pricing in Payment Links, Checkout, and Subscriptions.

Related guides: [Set up a subscription](stripe.com/docs/billing/subscriptions/set-up-subscription), [share a Payment Link](stripe.com/docs/payment-links), [accept payments with Checkout](stripe.com/docs/payments/accept-a-payment#create-product-prices-upfront), and more about [Products and Prices](stripe.com/docs/products-prices/overview)

Constant Summary collapse

OBJECT_NAME =
"product"

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

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::NestedResource

nested_resource_class_methods

Methods included from APIOperations::Search

_search

Methods included from APIOperations::Save

included, #save

Methods included from APIOperations::Delete

included

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 product object.



29
30
31
# File 'lib/stripe/resources/product.rb', line 29

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

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

Delete a product. Deleting a product is only possible if it has no prices associated with it. Additionally, deleting a product with type=good is only possible if it has no SKUs associated with it.



34
35
36
37
38
39
40
41
# File 'lib/stripe/resources/product.rb', line 34

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

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

Returns a list of your products. The products are returned sorted by creation date, with the most recently created products appearing first.



54
55
56
# File 'lib/stripe/resources/product.rb', line 54

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

.object_nameObject



22
23
24
# File 'lib/stripe/resources/product.rb', line 22

def self.object_name
  "product"
end

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



58
59
60
# File 'lib/stripe/resources/product.rb', line 58

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

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



62
63
64
# File 'lib/stripe/resources/product.rb', line 62

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

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

Updates the specific product by setting the values of the parameters passed. Any parameters not provided will be left unchanged.



67
68
69
70
71
72
73
74
# File 'lib/stripe/resources/product.rb', line 67

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

Instance Method Details

#delete(params = {}, opts = {}) ⇒ Object

Delete a product. Deleting a product is only possible if it has no prices associated with it. Additionally, deleting a product with type=good is only possible if it has no SKUs associated with it.



44
45
46
47
48
49
50
51
# File 'lib/stripe/resources/product.rb', line 44

def delete(params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/products/%<id>s", { id: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end