class ProcessOut::Product
Attributes
amount[R]
cancel_url[R]
created_at[R]
currency[R]
id[R]
metadata[R]
name[R]
project[R]
project_id[R]
return_url[R]
sandbox[R]
url[R]
Public Class Methods
new(client, data = {})
click to toggle source
Initializes the Product
object Params:
client
-
ProcessOut
client instance data
-
data that can be used to fill the object
# File lib/processout/product.rb, line 90 def initialize(client, data = {}) @client = client self.id = data.fetch(:id, nil) self.project = data.fetch(:project, nil) self.project_id = data.fetch(:project_id, nil) self.url = data.fetch(:url, nil) self.name = data.fetch(:name, nil) self.amount = data.fetch(:amount, nil) self.currency = data.fetch(:currency, nil) self.metadata = data.fetch(:metadata, nil) self.return_url = data.fetch(:return_url, nil) self.cancel_url = data.fetch(:cancel_url, nil) self.sandbox = data.fetch(:sandbox, nil) self.created_at = data.fetch(:created_at, nil) end
Public Instance Methods
all(options = {})
click to toggle source
Get all the products. Params:
options
-
Hash
of options
# File lib/processout/product.rb, line 228 def all(options = {}) self.prefill(options) request = Request.new(@client) path = "/products" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new a = Array.new body = response.body for v in body['products'] tmp = Product.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) return_values[0] end
amount=(val)
click to toggle source
# File lib/processout/product.rb, line 57 def amount=(val) @amount = val end
cancel_url=(val)
click to toggle source
# File lib/processout/product.rb, line 73 def cancel_url=(val) @cancel_url = val end
create(options = {})
click to toggle source
Create a new product. Params:
options
-
Hash
of options
# File lib/processout/product.rb, line 258 def create(options = {}) self.prefill(options) request = Request.new(@client) path = "/products" data = { "name" => @name, "amount" => @amount, "currency" => @currency, "metadata" => @metadata, "return_url" => @return_url, "cancel_url" => @cancel_url } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["product"] return_values.push(self.fill_with_data(body)) return_values[0] end
create_invoice(options = {})
click to toggle source
Create a new invoice from the product. Params:
options
-
Hash
of options
# File lib/processout/product.rb, line 204 def create_invoice(options = {}) self.prefill(options) request = Request.new(@client) path = "/products/" + CGI.escape(@id) + "/invoices" data = { } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["invoice"] invoice = Invoice.new(@client) return_values.push(invoice.fill_with_data(body)) return_values[0] end
created_at=(val)
click to toggle source
# File lib/processout/product.rb, line 81 def created_at=(val) @created_at = val end
currency=(val)
click to toggle source
# File lib/processout/product.rb, line 61 def currency=(val) @currency = val end
delete(options = {})
click to toggle source
Delete the product. Params:
options
-
Hash
of options
# File lib/processout/product.rb, line 348 def delete(options = {}) self.prefill(options) request = Request.new(@client) path = "/products/" + CGI.escape(@id) + "" data = { } response = Response.new(request.delete(path, data, options)) return_values = Array.new return_values.push(response.success) return_values[0] end
fill_with_data(data)
click to toggle source
Fills the object with data coming from the API Params:
data
-
Hash
of data coming from the API
# File lib/processout/product.rb, line 134 def fill_with_data(data) if data.nil? return self end if data.include? "id" self.id = data["id"] end if data.include? "project" self.project = data["project"] end if data.include? "project_id" self.project_id = data["project_id"] end if data.include? "url" self.url = data["url"] end if data.include? "name" self.name = data["name"] end if data.include? "amount" self.amount = data["amount"] end if data.include? "currency" self.currency = data["currency"] end if data.include? "metadata" self.metadata = data["metadata"] end if data.include? "return_url" self.return_url = data["return_url"] end if data.include? "cancel_url" self.cancel_url = data["cancel_url"] end if data.include? "sandbox" self.sandbox = data["sandbox"] end if data.include? "created_at" self.created_at = data["created_at"] end self end
find(product_id, options = {})
click to toggle source
Find a product by its ID. Params:
product_id
-
ID of the product
options
-
Hash
of options
# File lib/processout/product.rb, line 290 def find(product_id, options = {}) self.prefill(options) request = Request.new(@client) path = "/products/" + CGI.escape(product_id) + "" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new body = response.body body = body["product"] obj = Product.new(@client) return_values.push(obj.fill_with_data(body)) return_values[0] end
id=(val)
click to toggle source
# File lib/processout/product.rb, line 25 def id=(val) @id = val end
metadata=(val)
click to toggle source
# File lib/processout/product.rb, line 65 def metadata=(val) @metadata = val end
name=(val)
click to toggle source
# File lib/processout/product.rb, line 53 def name=(val) @name = val end
new(data = {})
click to toggle source
Create a new Product
using the current client
# File lib/processout/product.rb, line 109 def new(data = {}) Product.new(@client, data) end
prefill(data)
click to toggle source
Prefills the object with the data passed as parameters Params:
data
-
Hash
of data
# File lib/processout/product.rb, line 181 def prefill(data) if data.nil? return self end self.id = data.fetch(:id, self.id) self.project = data.fetch(:project, self.project) self.project_id = data.fetch(:project_id, self.project_id) self.url = data.fetch(:url, self.url) self.name = data.fetch(:name, self.name) self.amount = data.fetch(:amount, self.amount) self.currency = data.fetch(:currency, self.currency) self.metadata = data.fetch(:metadata, self.metadata) self.return_url = data.fetch(:return_url, self.return_url) self.cancel_url = data.fetch(:cancel_url, self.cancel_url) self.sandbox = data.fetch(:sandbox, self.sandbox) self.created_at = data.fetch(:created_at, self.created_at) self end
project=(val)
click to toggle source
# File lib/processout/product.rb, line 29 def project=(val) if val.nil? @project = val return end if val.instance_of? Project @project = val else obj = Project.new(@client) obj.fill_with_data(val) @project = obj end end
project_id=(val)
click to toggle source
# File lib/processout/product.rb, line 45 def project_id=(val) @project_id = val end
return_url=(val)
click to toggle source
# File lib/processout/product.rb, line 69 def return_url=(val) @return_url = val end
sandbox=(val)
click to toggle source
# File lib/processout/product.rb, line 77 def sandbox=(val) @sandbox = val end
save(options = {})
click to toggle source
Save the updated product attributes. Params:
options
-
Hash
of options
# File lib/processout/product.rb, line 317 def save(options = {}) self.prefill(options) request = Request.new(@client) path = "/products/" + CGI.escape(@id) + "" data = { "name" => @name, "amount" => @amount, "currency" => @currency, "metadata" => @metadata, "return_url" => @return_url, "cancel_url" => @cancel_url } response = Response.new(request.put(path, data, options)) return_values = Array.new body = response.body body = body["product"] return_values.push(self.fill_with_data(body)) return_values[0] end
to_json(options)
click to toggle source
Overrides the JSON marshaller to only send the fields we want
# File lib/processout/product.rb, line 114 def to_json(options) { "id": self.id, "project": self.project, "project_id": self.project_id, "url": self.url, "name": self.name, "amount": self.amount, "currency": self.currency, "metadata": self.metadata, "return_url": self.return_url, "cancel_url": self.cancel_url, "sandbox": self.sandbox, "created_at": self.created_at, }.to_json end
url=(val)
click to toggle source
# File lib/processout/product.rb, line 49 def url=(val) @url = val end