Class: ProcessOut::Customer
- Inherits:
-
Object
- Object
- ProcessOut::Customer
- Defined in:
- lib/processout/customer.rb
Instance Attribute Summary collapse
-
#address1 ⇒ Object
Returns the value of attribute address1.
-
#address2 ⇒ Object
Returns the value of attribute address2.
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#city ⇒ Object
Returns the value of attribute city.
-
#company_name ⇒ Object
Returns the value of attribute company_name.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#date_of_birth ⇒ Object
Returns the value of attribute date_of_birth.
-
#default_token ⇒ Object
Returns the value of attribute default_token.
-
#default_token_id ⇒ Object
Returns the value of attribute default_token_id.
-
#email ⇒ Object
Returns the value of attribute email.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#is_business ⇒ Object
Returns the value of attribute is_business.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#legal_document ⇒ Object
Returns the value of attribute legal_document.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#phone_number ⇒ Object
Returns the value of attribute phone_number.
-
#project ⇒ Object
Returns the value of attribute project.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#reference_id ⇒ Object
Returns the value of attribute reference_id.
-
#registered_at ⇒ Object
Returns the value of attribute registered_at.
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
-
#sex ⇒ Object
Returns the value of attribute sex.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
Get all the customers.
-
#create(options = {}) ⇒ Object
Create a new customer.
-
#delete(options = {}) ⇒ Object
Delete the customer.
-
#delete_token(token_id, options = {}) ⇒ Object
Delete a customer's token by its ID.
-
#fetch_tokens(options = {}) ⇒ Object
Get the customer's tokens.
-
#fetch_transactions(options = {}) ⇒ Object
Get the transactions belonging to the customer.
-
#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, options = {}) ⇒ Object
Find a customer by its ID.
-
#find_token(token_id, options = {}) ⇒ Object
Find a customer's token by its ID.
-
#initialize(client, data = {}) ⇒ Customer
constructor
Initializes the Customer object Params:
client::ProcessOutclient instancedata:: data that can be used to fill the object. -
#new(data = {}) ⇒ Object
Create a new Customer using the current client.
-
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
data::Hashof data. -
#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 = {}) ⇒ Customer
Initializes the Customer object Params:
clientProcessOutclient instancedatadata that can be used to fill the object
241 242 243 244 245 246 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 |
# File 'lib/processout/customer.rb', line 241 def initialize(client, data = {}) @client = client self.id = data.fetch(:id, nil) self.project = data.fetch(:project, nil) self.project_id = data.fetch(:project_id, nil) self.default_token = data.fetch(:default_token, nil) self.default_token_id = data.fetch(:default_token_id, nil) self.tokens = data.fetch(:tokens, nil) self.transactions = data.fetch(:transactions, nil) self.balance = data.fetch(:balance, nil) self.currency = data.fetch(:currency, nil) self.email = data.fetch(:email, nil) self.first_name = data.fetch(:first_name, nil) self.last_name = data.fetch(:last_name, nil) self.company_name = data.fetch(:company_name, nil) self.address1 = data.fetch(:address1, nil) self.address2 = data.fetch(:address2, nil) self.city = data.fetch(:city, nil) self.state = data.fetch(:state, nil) self.zip = data.fetch(:zip, nil) self.country_code = data.fetch(:country_code, nil) self.ip_address = data.fetch(:ip_address, nil) self.phone_number = data.fetch(:phone_number, nil) self.phone = data.fetch(:phone, nil) self.legal_document = data.fetch(:legal_document, nil) self.sex = data.fetch(:sex, nil) self.is_business = data.fetch(:is_business, nil) self. = data.fetch(:metadata, nil) self.sandbox = data.fetch(:sandbox, nil) self.created_at = data.fetch(:created_at, nil) self.registered_at = data.fetch(:registered_at, nil) self.date_of_birth = data.fetch(:date_of_birth, nil) self.reference_id = data.fetch(:reference_id, nil) end |
Instance Attribute Details
#address1 ⇒ Object
Returns the value of attribute address1.
24 25 26 |
# File 'lib/processout/customer.rb', line 24 def address1 @address1 end |
#address2 ⇒ Object
Returns the value of attribute address2.
25 26 27 |
# File 'lib/processout/customer.rb', line 25 def address2 @address2 end |
#balance ⇒ Object
Returns the value of attribute balance.
18 19 20 |
# File 'lib/processout/customer.rb', line 18 def balance @balance end |
#city ⇒ Object
Returns the value of attribute city.
26 27 28 |
# File 'lib/processout/customer.rb', line 26 def city @city end |
#company_name ⇒ Object
Returns the value of attribute company_name.
23 24 25 |
# File 'lib/processout/customer.rb', line 23 def company_name @company_name end |
#country_code ⇒ Object
Returns the value of attribute country_code.
29 30 31 |
# File 'lib/processout/customer.rb', line 29 def country_code @country_code end |
#created_at ⇒ Object
Returns the value of attribute created_at.
38 39 40 |
# File 'lib/processout/customer.rb', line 38 def created_at @created_at end |
#currency ⇒ Object
Returns the value of attribute currency.
19 20 21 |
# File 'lib/processout/customer.rb', line 19 def currency @currency end |
#date_of_birth ⇒ Object
Returns the value of attribute date_of_birth.
40 41 42 |
# File 'lib/processout/customer.rb', line 40 def date_of_birth @date_of_birth end |
#default_token ⇒ Object
Returns the value of attribute default_token.
14 15 16 |
# File 'lib/processout/customer.rb', line 14 def default_token @default_token end |
#default_token_id ⇒ Object
Returns the value of attribute default_token_id.
15 16 17 |
# File 'lib/processout/customer.rb', line 15 def default_token_id @default_token_id end |
#email ⇒ Object
Returns the value of attribute email.
20 21 22 |
# File 'lib/processout/customer.rb', line 20 def email @email end |
#first_name ⇒ Object
Returns the value of attribute first_name.
21 22 23 |
# File 'lib/processout/customer.rb', line 21 def first_name @first_name end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/processout/customer.rb', line 11 def id @id end |
#ip_address ⇒ Object
Returns the value of attribute ip_address.
30 31 32 |
# File 'lib/processout/customer.rb', line 30 def ip_address @ip_address end |
#is_business ⇒ Object
Returns the value of attribute is_business.
35 36 37 |
# File 'lib/processout/customer.rb', line 35 def is_business @is_business end |
#last_name ⇒ Object
Returns the value of attribute last_name.
22 23 24 |
# File 'lib/processout/customer.rb', line 22 def last_name @last_name end |
#legal_document ⇒ Object
Returns the value of attribute legal_document.
33 34 35 |
# File 'lib/processout/customer.rb', line 33 def legal_document @legal_document end |
#metadata ⇒ Object
Returns the value of attribute metadata.
36 37 38 |
# File 'lib/processout/customer.rb', line 36 def @metadata end |
#phone ⇒ Object
Returns the value of attribute phone.
32 33 34 |
# File 'lib/processout/customer.rb', line 32 def phone @phone end |
#phone_number ⇒ Object
Returns the value of attribute phone_number.
31 32 33 |
# File 'lib/processout/customer.rb', line 31 def phone_number @phone_number end |
#project ⇒ Object
Returns the value of attribute project.
12 13 14 |
# File 'lib/processout/customer.rb', line 12 def project @project end |
#project_id ⇒ Object
Returns the value of attribute project_id.
13 14 15 |
# File 'lib/processout/customer.rb', line 13 def project_id @project_id end |
#reference_id ⇒ Object
Returns the value of attribute reference_id.
41 42 43 |
# File 'lib/processout/customer.rb', line 41 def reference_id @reference_id end |
#registered_at ⇒ Object
Returns the value of attribute registered_at.
39 40 41 |
# File 'lib/processout/customer.rb', line 39 def registered_at @registered_at end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
37 38 39 |
# File 'lib/processout/customer.rb', line 37 def sandbox @sandbox end |
#sex ⇒ Object
Returns the value of attribute sex.
34 35 36 |
# File 'lib/processout/customer.rb', line 34 def sex @sex end |
#state ⇒ Object
Returns the value of attribute state.
27 28 29 |
# File 'lib/processout/customer.rb', line 27 def state @state end |
#tokens ⇒ Object
Returns the value of attribute tokens.
16 17 18 |
# File 'lib/processout/customer.rb', line 16 def tokens @tokens end |
#transactions ⇒ Object
Returns the value of attribute transactions.
17 18 19 |
# File 'lib/processout/customer.rb', line 17 def transactions @transactions end |
#zip ⇒ Object
Returns the value of attribute zip.
28 29 30 |
# File 'lib/processout/customer.rb', line 28 def zip @zip end |
Instance Method Details
#all(options = {}) ⇒ Object
Get all the customers. Params:
optionsHashof options
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/processout/customer.rb', line 578 def all( = {}) self.prefill() request = Request.new(@client) path = "/customers" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new a = Array.new body = response.body for v in body['customers'] tmp = Customer.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) return_values[0] end |
#create(options = {}) ⇒ Object
Create a new customer. Params:
optionsHashof options
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/processout/customer.rb', line 608 def create( = {}) self.prefill() request = Request.new(@client) path = "/customers" data = { "balance" => @balance, "currency" => @currency, "email" => @email, "first_name" => @first_name, "last_name" => @last_name, "company_name" => @company_name, "address1" => @address1, "address2" => @address2, "city" => @city, "state" => @state, "zip" => @zip, "country_code" => @country_code, "ip_address" => @ip_address, "phone" => @phone, "legal_document" => @legal_document, "date_of_birth" => @date_of_birth, "is_business" => @is_business, "sex" => @sex, "metadata" => @metadata, "id" => @id, "reference_id" => @reference_id, "registered_at" => @registered_at, "phone_number" => @phone_number } response = Response.new(request.post(path, data, )) return_values = Array.new body = response.body body = body.key?("customer") ? body["customer"] : nil return_values.push(self.fill_with_data(body)) return_values[0] end |
#delete(options = {}) ⇒ Object
Delete the customer. Params:
optionsHashof options
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/processout/customer.rb', line 730 def delete( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@id) + "" data = { } response = Response.new(request.delete(path, data, )) return_values = Array.new return_values.push(response.success) return_values[0] end |
#delete_token(token_id, options = {}) ⇒ Object
Delete a customer's token by its ID. Params:
token_idID of the token
optionsHashof options
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/processout/customer.rb', line 527 def delete_token(token_id, = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@id) + "/tokens/" + CGI.escape(token_id) + "" data = { } response = Response.new(request.delete(path, data, )) return_values = Array.new return_values.push(response.success) return_values[0] end |
#fetch_tokens(options = {}) ⇒ Object
Get the customer's tokens. Params:
optionsHashof options
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/processout/customer.rb', line 469 def fetch_tokens( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@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 |
#fetch_transactions(options = {}) ⇒ Object
Get the transactions belonging to the customer. Params:
optionsHashof options
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/processout/customer.rb', line 548 def fetch_transactions( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@id) + "/transactions" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new a = Array.new body = response.body for v in body['transactions'] tmp = Transaction.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
323 324 325 326 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 357 358 359 360 361 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 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/processout/customer.rb', line 323 def fill_with_data(data) if data.nil? return self end if data.include? "id" self.id = data["id"] end if data.include? "project" self.project = data["project"] end if data.include? "project_id" self.project_id = data["project_id"] end if data.include? "default_token" self.default_token = data["default_token"] end if data.include? "default_token_id" self.default_token_id = data["default_token_id"] end if data.include? "tokens" self.tokens = data["tokens"] end if data.include? "transactions" self.transactions = data["transactions"] end if data.include? "balance" self.balance = data["balance"] end if data.include? "currency" self.currency = data["currency"] end if data.include? "email" self.email = data["email"] end if data.include? "first_name" self.first_name = data["first_name"] end if data.include? "last_name" self.last_name = data["last_name"] end if data.include? "company_name" self.company_name = data["company_name"] end if data.include? "address1" self.address1 = data["address1"] end if data.include? "address2" self.address2 = data["address2"] end if data.include? "city" self.city = data["city"] end if data.include? "state" self.state = data["state"] end if data.include? "zip" self.zip = data["zip"] end if data.include? "country_code" self.country_code = data["country_code"] end if data.include? "ip_address" self.ip_address = data["ip_address"] end if data.include? "phone_number" self.phone_number = data["phone_number"] end if data.include? "phone" self.phone = data["phone"] end if data.include? "legal_document" self.legal_document = data["legal_document"] end if data.include? "sex" self.sex = data["sex"] end if data.include? "is_business" self.is_business = data["is_business"] end if data.include? "metadata" self. = data["metadata"] end if data.include? "sandbox" self.sandbox = data["sandbox"] end if data.include? "created_at" self.created_at = data["created_at"] end if data.include? "registered_at" self.registered_at = data["registered_at"] end if data.include? "date_of_birth" self.date_of_birth = data["date_of_birth"] end if data.include? "reference_id" self.reference_id = data["reference_id"] end self end |
#find(customer_id, options = {}) ⇒ Object
Find a customer by its ID. Params:
customer_idID of the customer
optionsHashof options
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'lib/processout/customer.rb', line 657 def find(customer_id, = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(customer_id) + "" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new body = response.body body = body.key?("customer") ? body["customer"] : nil obj = Customer.new(@client) return_values.push(obj.fill_with_data(body)) return_values[0] end |
#find_token(token_id, options = {}) ⇒ Object
Find a customer's token by its ID. Params:
token_idID of the token
optionsHashof options
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/processout/customer.rb', line 500 def find_token(token_id, = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@id) + "/tokens/" + CGI.escape(token_id) + "" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new body = response.body body = body.key?("token") ? body["token"] : nil if !body.nil? token = Token.new(@client) return_values.push(token.fill_with_data(body)) end return_values[0] end |
#new(data = {}) ⇒ Object
Create a new Customer using the current client
279 280 281 |
# File 'lib/processout/customer.rb', line 279 def new(data = {}) Customer.new(@client, data) end |
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
dataHashof data
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 462 463 464 |
# File 'lib/processout/customer.rb', line 427 def prefill(data) if data.nil? return self end self.id = data.fetch(:id, self.id) self.project = data.fetch(:project, self.project) self.project_id = data.fetch(:project_id, self.project_id) self.default_token = data.fetch(:default_token, self.default_token) self.default_token_id = data.fetch(:default_token_id, self.default_token_id) self.tokens = data.fetch(:tokens, self.tokens) self.transactions = data.fetch(:transactions, self.transactions) self.balance = data.fetch(:balance, self.balance) self.currency = data.fetch(:currency, self.currency) self.email = data.fetch(:email, self.email) self.first_name = data.fetch(:first_name, self.first_name) self.last_name = data.fetch(:last_name, self.last_name) self.company_name = data.fetch(:company_name, self.company_name) self.address1 = data.fetch(:address1, self.address1) self.address2 = data.fetch(:address2, self.address2) self.city = data.fetch(:city, self.city) self.state = data.fetch(:state, self.state) self.zip = data.fetch(:zip, self.zip) self.country_code = data.fetch(:country_code, self.country_code) self.ip_address = data.fetch(:ip_address, self.ip_address) self.phone_number = data.fetch(:phone_number, self.phone_number) self.phone = data.fetch(:phone, self.phone) self.legal_document = data.fetch(:legal_document, self.legal_document) self.sex = data.fetch(:sex, self.sex) self.is_business = data.fetch(:is_business, self.is_business) self. = data.fetch(:metadata, self.) self.sandbox = data.fetch(:sandbox, self.sandbox) self.created_at = data.fetch(:created_at, self.created_at) self.registered_at = data.fetch(:registered_at, self.registered_at) self.date_of_birth = data.fetch(:date_of_birth, self.date_of_birth) self.reference_id = data.fetch(:reference_id, self.reference_id) self end |
#save(options = {}) ⇒ Object
Save the updated customer attributes. Params:
optionsHashof options
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/processout/customer.rb', line 684 def save( = {}) self.prefill() request = Request.new(@client) path = "/customers/" + CGI.escape(@id) + "" data = { "balance" => @balance, "default_token_id" => @default_token_id, "email" => @email, "first_name" => @first_name, "last_name" => @last_name, "company_name" => @company_name, "address1" => @address1, "address2" => @address2, "city" => @city, "state" => @state, "zip" => @zip, "country_code" => @country_code, "ip_address" => @ip_address, "phone" => @phone, "legal_document" => @legal_document, "date_of_birth" => @date_of_birth, "is_business" => @is_business, "sex" => @sex, "metadata" => @metadata, "registered_at" => @registered_at, "phone_number" => @phone_number } response = Response.new(request.put(path, data, )) return_values = Array.new body = response.body body = body.key?("customer") ? body["customer"] : nil return_values.push(self.fill_with_data(body)) return_values[0] end |
#to_json(options) ⇒ Object
Overrides the JSON marshaller to only send the fields we want
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 |
# File 'lib/processout/customer.rb', line 284 def to_json() { "id": self.id, "project": self.project, "project_id": self.project_id, "default_token": self.default_token, "default_token_id": self.default_token_id, "tokens": self.tokens, "transactions": self.transactions, "balance": self.balance, "currency": self.currency, "email": self.email, "first_name": self.first_name, "last_name": self.last_name, "company_name": self.company_name, "address1": self.address1, "address2": self.address2, "city": self.city, "state": self.state, "zip": self.zip, "country_code": self.country_code, "ip_address": self.ip_address, "phone_number": self.phone_number, "phone": self.phone, "legal_document": self.legal_document, "sex": self.sex, "is_business": self.is_business, "metadata": self., "sandbox": self.sandbox, "created_at": self.created_at, "registered_at": self.registered_at, "date_of_birth": self.date_of_birth, "reference_id": self.reference_id, }.to_json end |