Class: ProcessOut::CardContact

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/card_contact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ CardContact

Initializes the CardContact object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/processout/card_contact.rb', line 53

def initialize(client, data = {})
  @client = client

  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.country_code = data.fetch(:country_code, nil)
  self.billing_country_code = data.fetch(:billing_country_code, nil)
  self.zip = data.fetch(:zip, nil)
  
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



11
12
13
# File 'lib/processout/card_contact.rb', line 11

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



12
13
14
# File 'lib/processout/card_contact.rb', line 12

def address2
  @address2
end

#billing_country_codeObject

Returns the value of attribute billing_country_code.



16
17
18
# File 'lib/processout/card_contact.rb', line 16

def billing_country_code
  @billing_country_code
end

#cityObject

Returns the value of attribute city.



13
14
15
# File 'lib/processout/card_contact.rb', line 13

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



15
16
17
# File 'lib/processout/card_contact.rb', line 15

def country_code
  @country_code
end

#stateObject

Returns the value of attribute state.



14
15
16
# File 'lib/processout/card_contact.rb', line 14

def state
  @state
end

#zipObject

Returns the value of attribute zip.



17
18
19
# File 'lib/processout/card_contact.rb', line 17

def zip
  @zip
end

Instance Method Details

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/processout/card_contact.rb', line 87

def fill_with_data(data)
  if data.nil?
    return self
  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? "country_code"
    self.country_code = data["country_code"]
  end
  if data.include? "billing_country_code"
    self.billing_country_code = data["billing_country_code"]
  end
  if data.include? "zip"
    self.zip = data["zip"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new CardContact using the current client



67
68
69
# File 'lib/processout/card_contact.rb', line 67

def new(data = {})
  CardContact.new(@client, data)
end

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/processout/card_contact.rb', line 119

def prefill(data)
  if data.nil?
    return self
  end
  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.country_code = data.fetch(:country_code, self.country_code)
  self.billing_country_code = data.fetch(:billing_country_code, self.billing_country_code)
  self.zip = data.fetch(:zip, self.zip)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/processout/card_contact.rb', line 72

def to_json(options)
  {
      "address1": self.address1,
      "address2": self.address2,
      "city": self.city,
      "state": self.state,
      "country_code": self.country_code,
      "billing_country_code": self.billing_country_code,
      "zip": self.zip,
  }.to_json
end