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

#check_for_conflict, #get_additional_properties, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #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, surcharging: SKIP, vat_number: SKIP, metafields: SKIP, parent_id: SKIP, salesforce_id: SKIP, default_auto_renewal_profile_id: SKIP, additional_properties: {}) ⇒ CustomerAttributes

Returns a new instance of CustomerAttributes.



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
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/advanced_billing/models/customer_attributes.rb', line 182

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, surcharging: SKIP, vat_number: SKIP,
               metafields: SKIP, parent_id: SKIP, salesforce_id: SKIP,
               default_auto_renewal_profile_id: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @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
  @surcharging = surcharging unless surcharging == 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
  unless default_auto_renewal_profile_id == SKIP
    @default_auto_renewal_profile_id =
      default_auto_renewal_profile_id
  end
end

Instance Attribute Details

#addressString

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

Returns:

  • (String)


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

def address
  @address
end

#address_2String

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

Returns:

  • (String)


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

def address_2
  @address_2
end

#cc_emailsString

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

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 (e.g., “Boston”).

Returns:

  • (String)


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

def city
  @city
end

#countryString

“(Optional) The customer shipping address country, required in ISO_3166-1 alpha-2 format (e.g., “US”).”

Returns:

  • (String)


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

def country
  @country
end

#default_auto_renewal_profile_idInteger

(Optional) The default auto-renewal profile ID for the customer

Returns:

  • (Integer)


115
116
117
# File 'lib/advanced_billing/models/customer_attributes.rb', line 115

def default_auto_renewal_profile_id
  @default_auto_renewal_profile_id
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])


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

def metafields
  @metafields
end

#organizationString

(Optional) The organization/company of the customer.

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)


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

def parent_id
  @parent_id
end

#phoneString

(Optional) The phone number of the customer.

Returns:

  • (String)


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

def phone
  @phone
end

#referenceString

(Optional) 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.

Returns:

  • (String)


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

def reference
  @reference
end

#salesforce_idString

(Optional) The Salesforce ID of the customer.

Returns:

  • (String)


111
112
113
# File 'lib/advanced_billing/models/customer_attributes.rb', line 111

def salesforce_id
  @salesforce_id
end

#stateString

“(Optional) The customer’s shipping address state (e.g., “MA”). This must conform to the ISO_3166-1 in order to be valid for tax locale purposes.”

Returns:

  • (String)


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

def state
  @state
end

#surchargingTrueClass | FalseClass

(Optional) Whether surcharging is enabled for the customer. Defaults to true when omitted. Only applied on sites where surcharging control is enabled.

Returns:

  • (TrueClass | FalseClass)


88
89
90
# File 'lib/advanced_billing/models/customer_attributes.rb', line 88

def surcharging
  @surcharging
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)


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

def tax_exempt
  @tax_exempt
end

#vat_numberString

(Optional) Supplying the VAT number allows EU customers 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)


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

def vat_number
  @vat_number
end

#verifiedTrueClass | FalseClass

(Optional) The phone number of the customer.

Returns:

  • (TrueClass | FalseClass)


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

def verified
  @verified
end

#zipString

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

Returns:

  • (String)


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

def zip
  @zip
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
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
# File 'lib/advanced_billing/models/customer_attributes.rb', line 222

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
  surcharging = hash.key?('surcharging') ? hash['surcharging'] : 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
  default_auto_renewal_profile_id =
    hash.key?('default_auto_renewal_profile_id') ? hash['default_auto_renewal_profile_id'] : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(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,
                         surcharging: surcharging,
                         vat_number: vat_number,
                         metafields: metafields,
                         parent_id: parent_id,
                         salesforce_id: salesforce_id,
                         default_auto_renewal_profile_id: default_auto_renewal_profile_id,
                         additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/advanced_billing/models/customer_attributes.rb', line 118

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['surcharging'] = 'surcharging'
  @_hash['vat_number'] = 'vat_number'
  @_hash['metafields'] = 'metafields'
  @_hash['parent_id'] = 'parent_id'
  @_hash['salesforce_id'] = 'salesforce_id'
  @_hash['default_auto_renewal_profile_id'] =
    'default_auto_renewal_profile_id'
  @_hash
end

.nullablesObject

An array for nullable fields



173
174
175
176
177
178
179
180
# File 'lib/advanced_billing/models/customer_attributes.rb', line 173

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

.optionalsObject

An array for optional fields



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
# File 'lib/advanced_billing/models/customer_attributes.rb', line 146

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

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



279
280
281
282
283
284
285
# File 'lib/advanced_billing/models/customer_attributes.rb', line 279

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

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/advanced_billing/models/customer_attributes.rb', line 301

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} first_name: #{@first_name.inspect}, last_name: #{@last_name.inspect},"\
  " email: #{@email.inspect}, cc_emails: #{@cc_emails.inspect}, organization:"\
  " #{@organization.inspect}, reference: #{@reference.inspect}, address: #{@address.inspect},"\
  " address_2: #{@address_2.inspect}, city: #{@city.inspect}, state: #{@state.inspect}, zip:"\
  " #{@zip.inspect}, country: #{@country.inspect}, phone: #{@phone.inspect}, verified:"\
  " #{@verified.inspect}, tax_exempt: #{@tax_exempt.inspect}, surcharging:"\
  " #{@surcharging.inspect}, vat_number: #{@vat_number.inspect}, metafields:"\
  " #{@metafields.inspect}, parent_id: #{@parent_id.inspect}, salesforce_id:"\
  " #{@salesforce_id.inspect}, default_auto_renewal_profile_id:"\
  " #{@default_auto_renewal_profile_id.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



288
289
290
291
292
293
294
295
296
297
298
# File 'lib/advanced_billing/models/customer_attributes.rb', line 288

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} 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}, surcharging: #{@surcharging}, vat_number: #{@vat_number}, metafields:"\
  " #{@metafields}, parent_id: #{@parent_id}, salesforce_id: #{@salesforce_id},"\
  " default_auto_renewal_profile_id: #{@default_auto_renewal_profile_id},"\
  " additional_properties: #{get_additional_properties}>"
end