Class: Stripe::ProductService

Inherits:
StripeService show all
Defined in:
lib/stripe/services/product_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StripeService

#request, #request_stream

Constructor Details

#initialize(requestor) ⇒ ProductService

Returns a new instance of ProductService.



8
9
10
11
# File 'lib/stripe/services/product_service.rb', line 8

def initialize(requestor)
  super
  @features = Stripe::ProductFeatureService.new(@requestor)
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



6
7
8
# File 'lib/stripe/services/product_service.rb', line 6

def features
  @features
end

Instance Method Details

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

Creates a new product object.



14
15
16
17
18
# File 'lib/stripe/services/product_service.rb', line 14

def create(params = {}, opts = {})
  params = ::Stripe::ProductCreateParams.coerce_params(params) unless params.is_a?(Stripe::RequestParams)

  request(method: :post, path: "/v1/products", params: params, opts: opts, base_address: :api)
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.



21
22
23
24
25
26
27
28
29
# File 'lib/stripe/services/product_service.rb', line 21

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

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

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



32
33
34
# File 'lib/stripe/services/product_service.rb', line 32

def list(params = {}, opts = {})
  request(method: :get, path: "/v1/products", params: params, opts: opts, base_address: :api)
end

#retrieve(id, params = {}, opts = {}) ⇒ Object

Retrieves the details of an existing product. Supply the unique product ID from either a product creation request or the product list, and Stripe will return the corresponding product information.



37
38
39
40
41
42
43
44
45
# File 'lib/stripe/services/product_service.rb', line 37

def retrieve(id, params = {}, opts = {})
  request(
    method: :get,
    path: format("/v1/products/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

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

Search for products you’ve previously created using Stripe’s [Search Query Language](docs.stripe.com/docs/search#search-query-language). Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.



51
52
53
54
55
56
57
58
59
# File 'lib/stripe/services/product_service.rb', line 51

def search(params = {}, opts = {})
  request(
    method: :get,
    path: "/v1/products/search",
    params: params,
    opts: opts,
    base_address: :api
  )
end

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

Serializes a Product create request into a batch job JSONL line.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/stripe/services/product_service.rb', line 62

def serialize_batch_create(params = {}, opts = {})
  request_id = SecureRandom.uuid
  stripe_version = opts[:stripe_version] || Stripe.api_version

  request_body = {
    id: request_id,
    params: params,
    stripe_version: stripe_version,
  }
  request_body[:context] = opts[:stripe_context] if opts[:stripe_context]
  JSON.generate(request_body)
end

#serialize_batch_delete(id, params = {}, opts = {}) ⇒ Object

Serializes a Product delete request into a batch job JSONL line.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/stripe/services/product_service.rb', line 76

def serialize_batch_delete(id, params = {}, opts = {})
  request_id = SecureRandom.uuid
  stripe_version = opts[:stripe_version] || Stripe.api_version

  request_body = {
    id: request_id,
    params: params,
    stripe_version: stripe_version,
  }
  request_body[:path_params] = { id: id }
  request_body[:context] = opts[:stripe_context] if opts[:stripe_context]
  JSON.generate(request_body)
end

#serialize_batch_update(id, params = {}, opts = {}) ⇒ Object

Serializes a Product update request into a batch job JSONL line.



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/stripe/services/product_service.rb', line 91

def serialize_batch_update(id, params = {}, opts = {})
  request_id = SecureRandom.uuid
  stripe_version = opts[:stripe_version] || Stripe.api_version

  request_body = {
    id: request_id,
    params: params,
    stripe_version: stripe_version,
  }
  request_body[:path_params] = { id: id }
  request_body[:context] = opts[:stripe_context] if opts[:stripe_context]
  JSON.generate(request_body)
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.



106
107
108
109
110
111
112
113
114
# File 'lib/stripe/services/product_service.rb', line 106

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