class ProcessOut::Token
Attributes
cancel_url[R]
card[R]
card_id[R]
created_at[R]
customer[R]
customer_id[R]
description[R]
gateway_configuration[R]
gateway_configuration_id[R]
id[R]
invoice[R]
invoice_id[R]
is_chargeable[R]
is_default[R]
is_subscription_only[R]
metadata[R]
return_url[R]
summary[R]
type[R]
Public Class Methods
new(client, data = {})
click to toggle source
Initializes the Token
object Params:
client
-
ProcessOut
client instance data
-
data that can be used to fill the object
# File lib/processout/token.rb, line 161 def initialize(client, data = {}) @client = client self.id = data.fetch(:id, nil) self.customer = data.fetch(:customer, nil) self.customer_id = data.fetch(:customer_id, nil) self.gateway_configuration = data.fetch(:gateway_configuration, nil) self.gateway_configuration_id = data.fetch(:gateway_configuration_id, nil) self.card = data.fetch(:card, nil) self.card_id = data.fetch(:card_id, nil) self.type = data.fetch(:type, nil) self.metadata = data.fetch(:metadata, nil) self.is_subscription_only = data.fetch(:is_subscription_only, nil) self.is_default = data.fetch(:is_default, nil) self.return_url = data.fetch(:return_url, nil) self.cancel_url = data.fetch(:cancel_url, nil) self.summary = data.fetch(:summary, nil) self.is_chargeable = data.fetch(:is_chargeable, nil) self.created_at = data.fetch(:created_at, nil) self.description = data.fetch(:description, nil) self.invoice = data.fetch(:invoice, nil) self.invoice_id = data.fetch(:invoice_id, nil) end
Public Instance Methods
cancel_url=(val)
click to toggle source
# File lib/processout/token.rb, line 116 def cancel_url=(val) @cancel_url = val end
card=(val)
click to toggle source
# File lib/processout/token.rb, line 76 def card=(val) if val.nil? @card = val return end if val.instance_of? Card @card = val else obj = Card.new(@client) obj.fill_with_data(val) @card = obj end end
card_id=(val)
click to toggle source
# File lib/processout/token.rb, line 92 def card_id=(val) @card_id = val end
create(options = {})
click to toggle source
Create a new token for the given customer ID. Params:
options
-
Hash
of options
# File lib/processout/token.rb, line 377 def create(options = {}) self.prefill(options) request = Request.new(@client) path = "/customers/" + CGI.escape(@customer_id) + "/tokens" data = { "metadata" => @metadata, "return_url" => @return_url, "cancel_url" => @cancel_url, "description" => @description, "source" => options.fetch(:source, nil), "settings" => options.fetch(:settings, nil), "device" => options.fetch(:device, nil), "verify" => options.fetch(:verify, nil), "verify_metadata" => options.fetch(:verify_metadata, nil), "set_default" => options.fetch(:set_default, nil) } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["token"] return_values.push(self.fill_with_data(body)) return_values[0] end
created_at=(val)
click to toggle source
# File lib/processout/token.rb, line 128 def created_at=(val) @created_at = val end
customer=(val)
click to toggle source
# File lib/processout/token.rb, line 36 def customer=(val) if val.nil? @customer = val return end if val.instance_of? Customer @customer = val else obj = Customer.new(@client) obj.fill_with_data(val) @customer = obj end end
customer_id=(val)
click to toggle source
# File lib/processout/token.rb, line 52 def customer_id=(val) @customer_id = val end
delete(options = {})
click to toggle source
Delete a customer token Params:
options
-
Hash
of options
# File lib/processout/token.rb, line 438 def delete(options = {}) self.prefill(options) request = Request.new(@client) path = "/customers/" + CGI.escape(@customer_id) + "/tokens/" + 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
description=(val)
click to toggle source
# File lib/processout/token.rb, line 132 def description=(val) @description = val end
fetch_customer_tokens(customer_id, options = {})
click to toggle source
Get the customer's tokens. Params:
customer_id
-
ID of the customer
options
-
Hash
of options
# File lib/processout/token.rb, line 318 def fetch_customer_tokens(customer_id, options = {}) self.prefill(options) request = Request.new(@client) path = "/customers/" + CGI.escape(customer_id) + "/tokens" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new a = Array.new body = response.body for v in body['tokens'] tmp = Token.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) 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/token.rb, line 219 def fill_with_data(data) if data.nil? return self end if data.include? "id" self.id = data["id"] end if data.include? "customer" self.customer = data["customer"] end if data.include? "customer_id" self.customer_id = data["customer_id"] end if data.include? "gateway_configuration" self.gateway_configuration = data["gateway_configuration"] end if data.include? "gateway_configuration_id" self.gateway_configuration_id = data["gateway_configuration_id"] end if data.include? "card" self.card = data["card"] end if data.include? "card_id" self.card_id = data["card_id"] end if data.include? "type" self.type = data["type"] end if data.include? "metadata" self.metadata = data["metadata"] end if data.include? "is_subscription_only" self.is_subscription_only = data["is_subscription_only"] end if data.include? "is_default" self.is_default = data["is_default"] 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? "summary" self.summary = data["summary"] end if data.include? "is_chargeable" self.is_chargeable = data["is_chargeable"] end if data.include? "created_at" self.created_at = data["created_at"] end if data.include? "description" self.description = data["description"] end if data.include? "invoice" self.invoice = data["invoice"] end if data.include? "invoice_id" self.invoice_id = data["invoice_id"] end self end
find(customer_id, token_id, options = {})
click to toggle source
Find a customer's token by its ID. Params:
customer_id
-
ID of the customer
token_id
-
ID of the token
options
-
Hash
of options
# File lib/processout/token.rb, line 350 def find(customer_id, token_id, options = {}) self.prefill(options) request = Request.new(@client) path = "/customers/" + CGI.escape(customer_id) + "/tokens/" + CGI.escape(token_id) + "" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new body = response.body body = body["token"] obj = Token.new(@client) return_values.push(obj.fill_with_data(body)) return_values[0] end
gateway_configuration=(val)
click to toggle source
# File lib/processout/token.rb, line 56 def gateway_configuration=(val) if val.nil? @gateway_configuration = val return end if val.instance_of? GatewayConfiguration @gateway_configuration = val else obj = GatewayConfiguration.new(@client) obj.fill_with_data(val) @gateway_configuration = obj end end
gateway_configuration_id=(val)
click to toggle source
# File lib/processout/token.rb, line 72 def gateway_configuration_id=(val) @gateway_configuration_id = val end
id=(val)
click to toggle source
# File lib/processout/token.rb, line 32 def id=(val) @id = val end
invoice=(val)
click to toggle source
# File lib/processout/token.rb, line 136 def invoice=(val) if val.nil? @invoice = val return end if val.instance_of? Invoice @invoice = val else obj = Invoice.new(@client) obj.fill_with_data(val) @invoice = obj end end
invoice_id=(val)
click to toggle source
# File lib/processout/token.rb, line 152 def invoice_id=(val) @invoice_id = val end
is_chargeable=(val)
click to toggle source
# File lib/processout/token.rb, line 124 def is_chargeable=(val) @is_chargeable = val end
is_default=(val)
click to toggle source
# File lib/processout/token.rb, line 108 def is_default=(val) @is_default = val end
is_subscription_only=(val)
click to toggle source
# File lib/processout/token.rb, line 104 def is_subscription_only=(val) @is_subscription_only = val end
metadata=(val)
click to toggle source
# File lib/processout/token.rb, line 100 def metadata=(val) @metadata = val end
new(data = {})
click to toggle source
Create a new Token
using the current client
# File lib/processout/token.rb, line 187 def new(data = {}) Token.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/token.rb, line 287 def prefill(data) if data.nil? return self end self.id = data.fetch(:id, self.id) self.customer = data.fetch(:customer, self.customer) self.customer_id = data.fetch(:customer_id, self.customer_id) self.gateway_configuration = data.fetch(:gateway_configuration, self.gateway_configuration) self.gateway_configuration_id = data.fetch(:gateway_configuration_id, self.gateway_configuration_id) self.card = data.fetch(:card, self.card) self.card_id = data.fetch(:card_id, self.card_id) self.type = data.fetch(:type, self.type) self.metadata = data.fetch(:metadata, self.metadata) self.is_subscription_only = data.fetch(:is_subscription_only, self.is_subscription_only) self.is_default = data.fetch(:is_default, self.is_default) self.return_url = data.fetch(:return_url, self.return_url) self.cancel_url = data.fetch(:cancel_url, self.cancel_url) self.summary = data.fetch(:summary, self.summary) self.is_chargeable = data.fetch(:is_chargeable, self.is_chargeable) self.created_at = data.fetch(:created_at, self.created_at) self.description = data.fetch(:description, self.description) self.invoice = data.fetch(:invoice, self.invoice) self.invoice_id = data.fetch(:invoice_id, self.invoice_id) self end
return_url=(val)
click to toggle source
# File lib/processout/token.rb, line 112 def return_url=(val) @return_url = val end
save(options = {})
click to toggle source
Save the updated customer attributes. Params:
options
-
Hash
of options
# File lib/processout/token.rb, line 412 def save(options = {}) self.prefill(options) request = Request.new(@client) path = "/customers/" + CGI.escape(@customer_id) + "/tokens/" + CGI.escape(@id) + "" data = { "source" => options.fetch(:source, nil), "settings" => options.fetch(:settings, nil), "device" => options.fetch(:device, nil), "verify" => options.fetch(:verify, nil), "verify_metadata" => options.fetch(:verify_metadata, nil), "set_default" => options.fetch(:set_default, nil) } response = Response.new(request.put(path, data, options)) return_values = Array.new return_values.push(response.success) return_values[0] end
summary=(val)
click to toggle source
# File lib/processout/token.rb, line 120 def summary=(val) @summary = val end
to_json(options)
click to toggle source
Overrides the JSON marshaller to only send the fields we want
# File lib/processout/token.rb, line 192 def to_json(options) { "id": self.id, "customer": self.customer, "customer_id": self.customer_id, "gateway_configuration": self.gateway_configuration, "gateway_configuration_id": self.gateway_configuration_id, "card": self.card, "card_id": self.card_id, "type": self.type, "metadata": self.metadata, "is_subscription_only": self.is_subscription_only, "is_default": self.is_default, "return_url": self.return_url, "cancel_url": self.cancel_url, "summary": self.summary, "is_chargeable": self.is_chargeable, "created_at": self.created_at, "description": self.description, "invoice": self.invoice, "invoice_id": self.invoice_id, }.to_json end
type=(val)
click to toggle source
# File lib/processout/token.rb, line 96 def type=(val) @type = val end