Class: ProcessOut::Token
- Inherits:
-
Object
- Object
- ProcessOut::Token
- Defined in:
- lib/processout/token.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_subscription_only ⇒ Object
Returns the value of attribute is_subscription_only.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#create(customer_id, source, options = nil) ⇒ Object
Create a new token for the given customer ID.
-
#create_from_request(customer_id, source, target, options = nil) ⇒ Object
- Create a new token for the given customer ID from an authorization request Params:
customer_id - ID of the customer
source - Source used to create the token (most likely a card token generated by ProcessOut.js)
target - Authorization request ID
options -
Hashof options.
- Authorization request ID
- Source used to create the token (most likely a card token generated by ProcessOut.js)
- ID of the customer
- Create a new token for the given customer ID from an authorization request Params:
-
#fill_with_data(data) ⇒ Object
- Fills the object with data coming from the API Params:
data -
Hashof data coming from the API.
- Fills the object with data coming from the API Params:
-
#find(customer_id, token_id, options = nil) ⇒ Object
Find a customer’s token by its ID.
-
#initialize(client) ⇒ Token
constructor
- Initializes the Token object Params:
client -
ProcessOutclient instance.
- Initializes the Token object Params:
Constructor Details
#initialize(client) ⇒ Token
Initializes the Token object Params:
client-
ProcessOutclient instance
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/processout/token.rb', line 48 def initialize(client) @client = client @id = "" @customer = nil = Hash.new @is_subscription_only = false @created_at = "" end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/processout/token.rb', line 14 def created_at @created_at end |
#customer ⇒ Object
Returns the value of attribute customer.
11 12 13 |
# File 'lib/processout/token.rb', line 11 def customer @customer end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/processout/token.rb', line 10 def id @id end |
#is_subscription_only ⇒ Object
Returns the value of attribute is_subscription_only.
13 14 15 |
# File 'lib/processout/token.rb', line 13 def is_subscription_only @is_subscription_only end |
#metadata ⇒ Object
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/processout/token.rb', line 12 def end |
Instance Method Details
#create(customer_id, source, options = nil) ⇒ Object
Create a new token for the given customer ID. Params:
customer_id-
ID of the customer
source-
Source used to create the token (most likely a card token generated by ProcessOut.js)
options-
Hashof options
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/processout/token.rb', line 114 def create(customer_id, source, = nil) request = Request.new(@client) path = "/customers/" + CGI.escape(customer_id) + "/tokens" data = { "metadata": , 'source': source } response = Response.new(request.post(path, data, )) return_values = Array.new body = response.body body = body["token"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#create_from_request(customer_id, source, target, options = nil) ⇒ Object
Create a new token for the given customer ID from an authorization request Params:
customer_id-
ID of the customer
source-
Source used to create the token (most likely a card token generated by ProcessOut.js)
target-
Authorization request ID
options-
Hashof options
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/processout/token.rb', line 142 def create_from_request(customer_id, source, target, = nil) request = Request.new(@client) path = "/customers/" + CGI.escape(customer_id) + "/tokens" data = { "metadata": , 'source': source, 'target': target } response = Response.new(request.post(path, data, )) return_values = Array.new body = response.body body = body["token"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#fill_with_data(data) ⇒ Object
Fills the object with data coming from the API Params:
data-
Hashof data coming from the API
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/processout/token.rb', line 62 def fill_with_data(data) if data.include? "id" @id = data["id"] end if data.include? "customer" @customer = data["customer"] end if data.include? "metadata" = data["metadata"] end if data.include? "is_subscription_only" @is_subscription_only = data["is_subscription_only"] end if data.include? "created_at" @created_at = data["created_at"] end self end |
#find(customer_id, token_id, options = nil) ⇒ Object
Find a customer’s token by its ID. Params:
customer_id-
ID of the customer
token_id-
ID of the token
options-
Hashof options
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/processout/token.rb', line 87 def find(customer_id, token_id, = nil) request = Request.new(@client) path = "/customers/" + CGI.escape(customer_id) + "/tokens/" + CGI.escape(token_id) + "" data = { } response = Response.new(request.get(path, data, )) 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 |