Class: AdvancedBilling::CustomerAttributes

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/customer_attributes.rb

Overview

CustomerAttributes Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(first_name: SKIP, last_name: SKIP, email: SKIP, cc_emails: SKIP, organization: SKIP, reference: SKIP, address: SKIP, address_2: SKIP, city: SKIP, state: SKIP, zip: SKIP, country: SKIP, phone: SKIP, verified: SKIP, tax_exempt: SKIP, vat_number: SKIP, metafields: SKIP, parent_id: SKIP, salesforce_id: SKIP, additional_properties: {}) ⇒ CustomerAttributes

Returns a new instance of CustomerAttributes.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/advanced_billing/models/customer_attributes.rb', line 167

def initialize(first_name: SKIP, last_name: SKIP, email: SKIP,
               cc_emails: SKIP, organization: SKIP, reference: SKIP,
               address: SKIP, address_2: SKIP, city: SKIP, state: SKIP,
               zip: SKIP, country: SKIP, phone: SKIP, verified: SKIP,
               tax_exempt: SKIP, vat_number: SKIP, metafields: SKIP,
               parent_id: SKIP, salesforce_id: SKIP,
               additional_properties: {})
  @first_name = first_name unless first_name == SKIP
  @last_name = last_name unless last_name == SKIP
  @email = email unless email == SKIP
  @cc_emails = cc_emails unless cc_emails == SKIP
  @organization = organization unless organization == SKIP
  @reference = reference unless reference == SKIP
  @address = address unless address == SKIP
  @address_2 = address_2 unless address_2 == SKIP
  @city = city unless city == SKIP
  @state = state unless state == SKIP
  @zip = zip unless zip == SKIP
  @country = country unless country == SKIP
  @phone = phone unless phone == SKIP
  @verified = verified unless verified == SKIP
  @tax_exempt = tax_exempt unless tax_exempt == SKIP
  @vat_number = vat_number unless vat_number == SKIP
  @metafields = metafields unless metafields == SKIP
  @parent_id = parent_id unless parent_id == SKIP
  @salesforce_id = salesforce_id unless salesforce_id == SKIP

  # Add additional model properties to the instance.

  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#addressString

(Optional) The customer’s shipping street address (i.e. “123 Main St.”).

Returns:

  • (String)


45
46
47
# File 'lib/advanced_billing/models/customer_attributes.rb', line 45

def address
  @address
end

#address_2String

(Optional) Second line of the customer’s shipping address i.e. “Apt. 100”

Returns:

  • (String)


49
50
51
# File 'lib/advanced_billing/models/customer_attributes.rb', line 49

def address_2
  @address_2
end

#cc_emailsString

A list of emails that should be cc’d on all customer communications. Optional.

Returns:

  • (String)


30
31
32
# File 'lib/advanced_billing/models/customer_attributes.rb', line 30

def cc_emails
  @cc_emails
end

#cityString

(Optional) The customer’s shipping address city (i.e. “Boston”).

Returns:

  • (String)


53
54
55
# File 'lib/advanced_billing/models/customer_attributes.rb', line 53

def city
  @city
end

#countryString

(Optional) The customer shipping address country, required in [ISO_3166-1 alpha-2](en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format (i.e. “US”).

Returns:

  • (String)


70
71
72
# File 'lib/advanced_billing/models/customer_attributes.rb', line 70

def country
  @country
end

#emailString

The email address of the customer. Required when creating a customer via attributes.

Returns:

  • (String)


25
26
27
# File 'lib/advanced_billing/models/customer_attributes.rb', line 25

def email
  @email
end

#first_nameString

The first name of the customer. Required when creating a customer via attributes.

Returns:

  • (String)


15
16
17
# File 'lib/advanced_billing/models/customer_attributes.rb', line 15

def first_name
  @first_name
end

#last_nameString

The last name of the customer. Required when creating a customer via attributes.

Returns:

  • (String)


20
21
22
# File 'lib/advanced_billing/models/customer_attributes.rb', line 20

def last_name
  @last_name
end

#metafieldsHash[String, String]

(Optional) A set of key/value pairs representing custom fields and their values. Metafields will be created “on-the-fly” in your site for a given key, if they have not been created yet.

Returns:

  • (Hash[String, String])


97
98
99
# File 'lib/advanced_billing/models/customer_attributes.rb', line 97

def metafields
  @metafields
end

#organizationString

The organization/company of the customer. Optional.

Returns:

  • (String)


34
35
36
# File 'lib/advanced_billing/models/customer_attributes.rb', line 34

def organization
  @organization
end

#parent_idInteger

The parent ID in Chargify if applicable. Parent is another Customer object.

Returns:

  • (Integer)


102
103
104
# File 'lib/advanced_billing/models/customer_attributes.rb', line 102

def parent_id
  @parent_id
end

#phoneString

(Optional) The phone number of the customer.

Returns:

  • (String)


74
75
76
# File 'lib/advanced_billing/models/customer_attributes.rb', line 74

def phone
  @phone
end

#referenceString

A customer “reference”, or unique identifier from your app, stored in Chargify. Can be used so that you may reference your customer’s within Chargify using the same unique value you use in your application. Optional.

Returns:

  • (String)


41
42
43
# File 'lib/advanced_billing/models/customer_attributes.rb', line 41

def reference
  @reference
end

#salesforce_idString

(Optional) The Salesforce ID of the customer.

Returns:

  • (String)


106
107
108
# File 'lib/advanced_billing/models/customer_attributes.rb', line 106

def salesforce_id
  @salesforce_id
end

#stateString

(Optional) The customer’s shipping address state (i.e. “MA”). This must conform to the [ISO_3166-1](en.wikipedia.org/wiki/ISO_3166-1#Current_codes) in order to be valid for tax locale purposes.

Returns:

  • (String)


60
61
62
# File 'lib/advanced_billing/models/customer_attributes.rb', line 60

def state
  @state
end

#tax_exemptTrueClass | FalseClass

(Optional) The tax_exempt status of the customer. Acceptable values are true or 1 for true and false or 0 for false.

Returns:

  • (TrueClass | FalseClass)


83
84
85
# File 'lib/advanced_billing/models/customer_attributes.rb', line 83

def tax_exempt
  @tax_exempt
end

#vat_numberString

(Optional) Supplying the VAT number allows EU customer’s to opt-out of the Value Added Tax assuming the merchant address and customer billing address are not within the same EU country. It’s important to omit the country code from the VAT number upon entry. Otherwise, taxes will be assessed upon the purchase.

Returns:

  • (String)


91
92
93
# File 'lib/advanced_billing/models/customer_attributes.rb', line 91

def vat_number
  @vat_number
end

#verifiedTrueClass | FalseClass

(Optional) The phone number of the customer.

Returns:

  • (TrueClass | FalseClass)


78
79
80
# File 'lib/advanced_billing/models/customer_attributes.rb', line 78

def verified
  @verified
end

#zipString

(Optional) The customer’s shipping address zip code (i.e. “12345”).

Returns:

  • (String)


64
65
66
# File 'lib/advanced_billing/models/customer_attributes.rb', line 64

def zip
  @zip
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
243
244
245
246
247
248
249
# File 'lib/advanced_billing/models/customer_attributes.rb', line 201

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  first_name = hash.key?('first_name') ? hash['first_name'] : SKIP
  last_name = hash.key?('last_name') ? hash['last_name'] : SKIP
  email = hash.key?('email') ? hash['email'] : SKIP
  cc_emails = hash.key?('cc_emails') ? hash['cc_emails'] : SKIP
  organization = hash.key?('organization') ? hash['organization'] : SKIP
  reference = hash.key?('reference') ? hash['reference'] : SKIP
  address = hash.key?('address') ? hash['address'] : SKIP
  address_2 = hash.key?('address_2') ? hash['address_2'] : SKIP
  city = hash.key?('city') ? hash['city'] : SKIP
  state = hash.key?('state') ? hash['state'] : SKIP
  zip = hash.key?('zip') ? hash['zip'] : SKIP
  country = hash.key?('country') ? hash['country'] : SKIP
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  verified = hash.key?('verified') ? hash['verified'] : SKIP
  tax_exempt = hash.key?('tax_exempt') ? hash['tax_exempt'] : SKIP
  vat_number = hash.key?('vat_number') ? hash['vat_number'] : SKIP
  metafields = hash.key?('metafields') ? hash['metafields'] : SKIP
  parent_id = hash.key?('parent_id') ? hash['parent_id'] : SKIP
  salesforce_id = hash.key?('salesforce_id') ? hash['salesforce_id'] : SKIP

  # Clean out expected properties from Hash.

  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.

  CustomerAttributes.new(first_name: first_name,
                         last_name: last_name,
                         email: email,
                         cc_emails: cc_emails,
                         organization: organization,
                         reference: reference,
                         address: address,
                         address_2: address_2,
                         city: city,
                         state: state,
                         zip: zip,
                         country: country,
                         phone: phone,
                         verified: verified,
                         tax_exempt: tax_exempt,
                         vat_number: vat_number,
                         metafields: metafields,
                         parent_id: parent_id,
                         salesforce_id: salesforce_id,
                         additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/advanced_billing/models/customer_attributes.rb', line 109

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['first_name'] = 'first_name'
  @_hash['last_name'] = 'last_name'
  @_hash['email'] = 'email'
  @_hash['cc_emails'] = 'cc_emails'
  @_hash['organization'] = 'organization'
  @_hash['reference'] = 'reference'
  @_hash['address'] = 'address'
  @_hash['address_2'] = 'address_2'
  @_hash['city'] = 'city'
  @_hash['state'] = 'state'
  @_hash['zip'] = 'zip'
  @_hash['country'] = 'country'
  @_hash['phone'] = 'phone'
  @_hash['verified'] = 'verified'
  @_hash['tax_exempt'] = 'tax_exempt'
  @_hash['vat_number'] = 'vat_number'
  @_hash['metafields'] = 'metafields'
  @_hash['parent_id'] = 'parent_id'
  @_hash['salesforce_id'] = 'salesforce_id'
  @_hash
end

.nullablesObject

An array for nullable fields



159
160
161
162
163
164
165
# File 'lib/advanced_billing/models/customer_attributes.rb', line 159

def self.nullables
  %w[
    address_2
    parent_id
    salesforce_id
  ]
end

.optionalsObject

An array for optional fields



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/advanced_billing/models/customer_attributes.rb', line 134

def self.optionals
  %w[
    first_name
    last_name
    email
    cc_emails
    organization
    reference
    address
    address_2
    city
    state
    zip
    country
    phone
    verified
    tax_exempt
    vat_number
    metafields
    parent_id
    salesforce_id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



253
254
255
256
257
258
259
# File 'lib/advanced_billing/models/customer_attributes.rb', line 253

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end