Class: ProcessOut::Token
- Inherits:
-
Object
- Object
- ProcessOut::Token
- Defined in:
- lib/processout/token.rb
Instance Attribute Summary collapse
-
#can_get_balance ⇒ Object
Returns the value of attribute can_get_balance.
-
#cancel_url ⇒ Object
Returns the value of attribute cancel_url.
-
#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.
-
#description ⇒ Object
Returns the value of attribute description.
-
#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.
-
#invoice ⇒ Object
Returns the value of attribute invoice.
-
#invoice_id ⇒ Object
Returns the value of attribute invoice_id.
-
#is_chargeable ⇒ Object
Returns the value of attribute is_chargeable.
-
#is_default ⇒ Object
Returns the value of attribute is_default.
-
#is_subscription_only ⇒ Object
Returns the value of attribute is_subscription_only.
-
#manual_invoice_cancellation ⇒ Object
Returns the value of attribute manual_invoice_cancellation.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#type ⇒ Object
Returns the value of attribute type.
-
#verification_status ⇒ Object
Returns the value of attribute verification_status.
-
#webhook_url ⇒ Object
Returns the value of attribute webhook_url.
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
-
Hash
of options.
- Delete a customer token Params:
-
#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
-
Hash
of 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
ProcessOut
client 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.
-
#prefill(data) ⇒ Object
- Prefills the object with the data passed as parameters Params:
data
-
Hash
of data.
- Prefills the object with the data passed as parameters Params:
-
#save(options = {}) ⇒ Object
Save the updated customer attributes.
-
#to_json(options) ⇒ Object
Overrides the JSON marshaller to only send the fields we want.
Constructor Details
#initialize(client, data = {}) ⇒ Token
Initializes the Token object Params:
client
-
ProcessOut
client instance data
-
data that can be used to fill the object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/processout/token.rb', line 181 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.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) self.manual_invoice_cancellation = data.fetch(:manual_invoice_cancellation, nil) self.verification_status = data.fetch(:verification_status, nil) self.can_get_balance = data.fetch(:can_get_balance, nil) self.webhook_url = data.fetch(:webhook_url, nil) end |
Instance Attribute Details
#can_get_balance ⇒ Object
Returns the value of attribute can_get_balance.
32 33 34 |
# File 'lib/processout/token.rb', line 32 def can_get_balance @can_get_balance end |
#cancel_url ⇒ Object
Returns the value of attribute cancel_url.
23 24 25 |
# File 'lib/processout/token.rb', line 23 def cancel_url @cancel_url end |
#card ⇒ Object
Returns the value of attribute card.
16 17 18 |
# File 'lib/processout/token.rb', line 16 def card @card end |
#card_id ⇒ Object
Returns the value of attribute card_id.
17 18 19 |
# File 'lib/processout/token.rb', line 17 def card_id @card_id end |
#created_at ⇒ Object
Returns the value of attribute created_at.
26 27 28 |
# File 'lib/processout/token.rb', line 26 def created_at @created_at end |
#customer ⇒ Object
Returns the value of attribute customer.
12 13 14 |
# File 'lib/processout/token.rb', line 12 def customer @customer end |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
13 14 15 |
# File 'lib/processout/token.rb', line 13 def customer_id @customer_id end |
#description ⇒ Object
Returns the value of attribute description.
27 28 29 |
# File 'lib/processout/token.rb', line 27 def description @description end |
#gateway_configuration ⇒ Object
Returns the value of attribute gateway_configuration.
14 15 16 |
# File 'lib/processout/token.rb', line 14 def gateway_configuration @gateway_configuration end |
#gateway_configuration_id ⇒ Object
Returns the value of attribute gateway_configuration_id.
15 16 17 |
# File 'lib/processout/token.rb', line 15 def gateway_configuration_id @gateway_configuration_id end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/processout/token.rb', line 11 def id @id end |
#invoice ⇒ Object
Returns the value of attribute invoice.
28 29 30 |
# File 'lib/processout/token.rb', line 28 def invoice @invoice end |
#invoice_id ⇒ Object
Returns the value of attribute invoice_id.
29 30 31 |
# File 'lib/processout/token.rb', line 29 def invoice_id @invoice_id end |
#is_chargeable ⇒ Object
Returns the value of attribute is_chargeable.
25 26 27 |
# File 'lib/processout/token.rb', line 25 def is_chargeable @is_chargeable end |
#is_default ⇒ Object
Returns the value of attribute is_default.
21 22 23 |
# File 'lib/processout/token.rb', line 21 def is_default @is_default end |
#is_subscription_only ⇒ Object
Returns the value of attribute is_subscription_only.
20 21 22 |
# File 'lib/processout/token.rb', line 20 def is_subscription_only @is_subscription_only end |
#manual_invoice_cancellation ⇒ Object
Returns the value of attribute manual_invoice_cancellation.
30 31 32 |
# File 'lib/processout/token.rb', line 30 def manual_invoice_cancellation @manual_invoice_cancellation end |
#metadata ⇒ Object
Returns the value of attribute metadata.
19 20 21 |
# File 'lib/processout/token.rb', line 19 def @metadata end |
#return_url ⇒ Object
Returns the value of attribute return_url.
22 23 24 |
# File 'lib/processout/token.rb', line 22 def return_url @return_url end |
#summary ⇒ Object
Returns the value of attribute summary.
24 25 26 |
# File 'lib/processout/token.rb', line 24 def summary @summary end |
#type ⇒ Object
Returns the value of attribute type.
18 19 20 |
# File 'lib/processout/token.rb', line 18 def type @type end |
#verification_status ⇒ Object
Returns the value of attribute verification_status.
31 32 33 |
# File 'lib/processout/token.rb', line 31 def verification_status @verification_status end |
#webhook_url ⇒ Object
Returns the value of attribute webhook_url.
33 34 35 |
# File 'lib/processout/token.rb', line 33 def webhook_url @webhook_url end |
Instance Method Details
#create(options = {}) ⇒ Object
Create a new token for the given customer ID. Params:
options
-
Hash
of options
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/processout/token.rb', line 421 def create( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@customer_id) + "/tokens" data = { "metadata" => @metadata, "return_url" => @return_url, "cancel_url" => @cancel_url, "description" => @description, "invoice_id" => @invoice_id, "manual_invoice_cancellation" => @manual_invoice_cancellation, "webhook_url" => @webhook_url, "source" => .fetch(:source, nil), "settings" => .fetch(:settings, nil), "device" => .fetch(:device, nil), "verify" => .fetch(:verify, nil), "verify_metadata" => .fetch(:verify_metadata, nil), "set_default" => .fetch(:set_default, nil), "verify_statement_descriptor" => .fetch(:verify_statement_descriptor, nil), "invoice_return_url" => .fetch(:invoice_return_url, nil), "summary" => .fetch(:summary, 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)) body = response.body body = body["customer_action"] customer_action = CustomerAction.new(@client) return_values.push(customer_action.fill_with_data(body)) return_values end |
#delete(options = {}) ⇒ Object
Delete a customer token Params:
options
-
Hash
of options
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/processout/token.rb', line 494 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_id
-
ID of the customer
options
-
Hash
of options
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/processout/token.rb', line 362 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:
data
-
Hash
of data coming from the API
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 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 318 319 320 321 322 |
# File 'lib/processout/token.rb', line 247 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? "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 if data.include? "manual_invoice_cancellation" self.manual_invoice_cancellation = data["manual_invoice_cancellation"] end if data.include? "verification_status" self.verification_status = data["verification_status"] end if data.include? "can_get_balance" self.can_get_balance = data["can_get_balance"] end if data.include? "webhook_url" self.webhook_url = data["webhook_url"] 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
-
Hash
of options
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/processout/token.rb', line 394 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
211 212 213 |
# File 'lib/processout/token.rb', line 211 def new(data = {}) Token.new(@client, data) end |
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
data
-
Hash
of data
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/processout/token.rb', line 327 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.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.manual_invoice_cancellation = data.fetch(:manual_invoice_cancellation, self.manual_invoice_cancellation) self.verification_status = data.fetch(:verification_status, self.verification_status) self.can_get_balance = data.fetch(:can_get_balance, self.can_get_balance) self.webhook_url = data.fetch(:webhook_url, self.webhook_url) self end |
#save(options = {}) ⇒ Object
Save the updated customer attributes. Params:
options
-
Hash
of options
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/processout/token.rb', line 466 def save( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@customer_id) + "/tokens/" + CGI.escape(@id) + "" data = { "source" => .fetch(:source, nil), "settings" => .fetch(:settings, nil), "device" => .fetch(:device, nil), "verify" => .fetch(:verify, nil), "verify_metadata" => .fetch(:verify_metadata, nil), "set_default" => .fetch(:set_default, nil), "verify_statement_descriptor" => .fetch(:verify_statement_descriptor, nil), "invoice_return_url" => .fetch(:invoice_return_url, nil) } response = Response.new(request.put(path, data, )) return_values = Array.new return_values.push(response.success) return_values[0] end |
#to_json(options) ⇒ Object
Overrides the JSON marshaller to only send the fields we want
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/processout/token.rb', line 216 def to_json() { "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., "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, "manual_invoice_cancellation": self.manual_invoice_cancellation, "verification_status": self.verification_status, "can_get_balance": self.can_get_balance, "webhook_url": self.webhook_url, }.to_json end |