Class: ProcessOut::Token
- Inherits:
-
Object
- Object
- ProcessOut::Token
- Defined in:
- lib/processout/token.rb
Instance Attribute Summary collapse
-
#card ⇒ Object
Returns the value of attribute card.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#customer_id ⇒ Object
Returns the value of attribute customer_id.
-
#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.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#create(customer_id, source, options = {}) ⇒ Object
Create a new token for the given customer ID.
-
#create_from_request(customer_id, source, target, options = {}) ⇒ 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:
-
#delete(options = {}) ⇒ Object
- Delete a customer token Params:
options -
Hashof options.
- Delete a customer token 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 = {}) ⇒ Object
Find a customer’s token by its ID.
-
#initialize(client, data = {}) ⇒ Token
constructor
- Initializes the Token object Params:
client ProcessOutclient instancedata-
data that can be used to fill the object.
- Initializes the Token object Params:
-
#new(data = {}) ⇒ Object
Create a new Token using the current client.
Constructor Details
#initialize(client, data = {}) ⇒ Token
Initializes the Token object Params:
client-
ProcessOutclient instance data-
data that can be used to fill the object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/processout/token.rb', line 71 def initialize(client, data = {}) @client = client @id = data.fetch(:id, "") @customer = data.fetch(:customer, nil) @customer_id = data.fetch(:customer_id, "") @card = data.fetch(:card, nil) @type = data.fetch(:type, "") = data.fetch(:metadata, Hash.new) @is_subscription_only = data.fetch(:is_subscription_only, false) @created_at = data.fetch(:created_at, "") end |
Instance Attribute Details
#card ⇒ Object
Returns the value of attribute card.
13 14 15 |
# File 'lib/processout/token.rb', line 13 def card @card end |
#created_at ⇒ Object
Returns the value of attribute created_at.
17 18 19 |
# File 'lib/processout/token.rb', line 17 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 |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
12 13 14 |
# File 'lib/processout/token.rb', line 12 def customer_id @customer_id 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.
16 17 18 |
# File 'lib/processout/token.rb', line 16 def is_subscription_only @is_subscription_only end |
#metadata ⇒ Object
Returns the value of attribute metadata.
15 16 17 |
# File 'lib/processout/token.rb', line 15 def end |
#type ⇒ Object
Returns the value of attribute type.
14 15 16 |
# File 'lib/processout/token.rb', line 14 def type @type end |
Instance Method Details
#create(customer_id, source, options = {}) ⇒ 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
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/processout/token.rb', line 154 def create(customer_id, source, = {}) 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 = {}) ⇒ 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
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/processout/token.rb', line 182 def create_from_request(customer_id, source, target, = {}) 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 |
#delete(options = {}) ⇒ Object
Delete a customer token Params:
options-
Hashof options
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/processout/token.rb', line 208 def delete( = {}) request = Request.new(@client) path = "customers/" + CGI.escape(@customer_id) + "/tokens/" + CGI.escape(@id) + "" data = { } response = Response.new(request.delete(path, data, )) return_values = Array.new return_values.push(response.success) 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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/processout/token.rb', line 93 def fill_with_data(data) 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? "card" self.card = data["card"] end if data.include? "type" self.type = data["type"] end if data.include? "metadata" self. = data["metadata"] end if data.include? "is_subscription_only" self.is_subscription_only = data["is_subscription_only"] end if data.include? "created_at" self.created_at = data["created_at"] end self end |
#find(customer_id, token_id, options = {}) ⇒ 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/processout/token.rb', line 127 def find(customer_id, token_id, = {}) 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 |
#new(data = {}) ⇒ Object
Create a new Token using the current client
86 87 88 |
# File 'lib/processout/token.rb', line 86 def new(data = {}) Token.new(@client, data) end |