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.
-
#card_id ⇒ Object
Returns the value of attribute card_id.
-
#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.
-
#gateway_configuration ⇒ Object
Returns the value of attribute gateway_configuration.
-
#gateway_configuration_id ⇒ Object
Returns the value of attribute gateway_configuration_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_default ⇒ Object
Returns the value of attribute is_default.
-
#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(options = {}) ⇒ Object
Create a new token for the given customer ID.
-
#delete(options = {}) ⇒ Object
Delete a customer token Params:
options::Hashof options. -
#fetch_customer_tokens(customer_id, options = {}) ⇒ Object
Get the customer's tokens.
-
#fill_with_data(data) ⇒ Object
Fills the object with data coming from the API Params:
data::Hashof data coming from the API. -
#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. -
#new(data = {}) ⇒ Object
Create a new Token using the current client.
-
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
data::Hashof data. -
#verify(options = {}) ⇒ Object
Verify a customer token's card is valid.
Constructor Details
#initialize(client, data = {}) ⇒ Token
Initializes the Token object Params:
clientProcessOutclient instancedatadata that can be used to fill the object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/processout/token.rb', line 113 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. = data.fetch(:metadata, nil) self.is_subscription_only = data.fetch(:is_subscription_only, nil) self.is_default = data.fetch(:is_default, nil) self.created_at = data.fetch(:created_at, nil) end |
Instance Attribute Details
#card ⇒ Object
Returns the value of attribute card.
15 16 17 |
# File 'lib/processout/token.rb', line 15 def card @card end |
#card_id ⇒ Object
Returns the value of attribute card_id.
16 17 18 |
# File 'lib/processout/token.rb', line 16 def card_id @card_id end |
#created_at ⇒ Object
Returns the value of attribute created_at.
21 22 23 |
# File 'lib/processout/token.rb', line 21 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 |
#gateway_configuration ⇒ Object
Returns the value of attribute gateway_configuration.
13 14 15 |
# File 'lib/processout/token.rb', line 13 def gateway_configuration @gateway_configuration end |
#gateway_configuration_id ⇒ Object
Returns the value of attribute gateway_configuration_id.
14 15 16 |
# File 'lib/processout/token.rb', line 14 def gateway_configuration_id @gateway_configuration_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_default ⇒ Object
Returns the value of attribute is_default.
20 21 22 |
# File 'lib/processout/token.rb', line 20 def is_default @is_default end |
#is_subscription_only ⇒ Object
Returns the value of attribute is_subscription_only.
19 20 21 |
# File 'lib/processout/token.rb', line 19 def is_subscription_only @is_subscription_only end |
#metadata ⇒ Object
Returns the value of attribute metadata.
18 19 20 |
# File 'lib/processout/token.rb', line 18 def @metadata end |
#type ⇒ Object
Returns the value of attribute type.
17 18 19 |
# File 'lib/processout/token.rb', line 17 def type @type end |
Instance Method Details
#create(options = {}) ⇒ Object
Create a new token for the given customer ID. Params:
optionsHashof options
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/processout/token.rb', line 290 def create( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@customer_id) + "/tokens" data = { "metadata" => @metadata, "source" => .fetch(:source, nil), "settings" => .fetch(:settings, nil), "target" => .fetch(:target, nil), "verify" => .fetch(:verify, nil), "verify_metadata" => .fetch(:verify_metadata, nil), "set_default" => .fetch(:set_default, nil) } 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:
optionsHashof options
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/processout/token.rb', line 322 def delete( = {}) self.prefill() 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 |
#fetch_customer_tokens(customer_id, options = {}) ⇒ Object
Get the customer's tokens. Params:
customer_idID of the customer
optionsHashof options
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/processout/token.rb', line 231 def fetch_customer_tokens(customer_id, = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(customer_id) + "/tokens" data = { } response = Response.new(request.get(path, data, )) 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) ⇒ Object
Fills the object with data coming from the API Params:
dataHashof data coming from the API
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/processout/token.rb', line 139 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. = 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? "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_idID of the customer
token_idID of the token
optionsHashof options
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/processout/token.rb', line 263 def find(customer_id, token_id, = {}) self.prefill() 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
132 133 134 |
# File 'lib/processout/token.rb', line 132 def new(data = {}) Token.new(@client, data) end |
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
dataHashof data
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/processout/token.rb', line 186 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. = data.fetch(:metadata, self.) self.is_subscription_only = data.fetch(:is_subscription_only, self.is_subscription_only) self.is_default = data.fetch(:is_default, self.is_default) self.created_at = data.fetch(:created_at, self.created_at) self end |
#verify(options = {}) ⇒ Object
Verify a customer token's card is valid. Params:
optionsHashof options
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/processout/token.rb', line 209 def verify( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@customer_id) + "/tokens/" + CGI.escape(@id) + "/verify" data = { } response = Response.new(request.post(path, data, )) return_values = Array.new return_values.push(response.success) return_values[0] end |