Class: AdvancedBilling::Customer

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

Overview

Customer 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, id: SKIP, created_at: SKIP, updated_at: SKIP, address: SKIP, address_2: SKIP, city: SKIP, state: SKIP, state_name: SKIP, zip: SKIP, country: SKIP, country_name: SKIP, phone: SKIP, verified: SKIP, portal_customer_created_at: SKIP, portal_invite_last_sent_at: SKIP, portal_invite_last_accepted_at: SKIP, tax_exempt: SKIP, vat_number: SKIP, parent_id: SKIP, locale: SKIP, default_subscription_group_uid: SKIP, salesforce_id: SKIP, tax_exempt_reason: SKIP, default_auto_renewal_profile_id: SKIP, additional_properties: {}) ⇒ Customer

Returns a new instance of Customer.



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

def initialize(first_name: SKIP, last_name: SKIP, email: SKIP,
               cc_emails: SKIP, organization: SKIP, reference: SKIP,
               id: SKIP, created_at: SKIP, updated_at: SKIP, address: SKIP,
               address_2: SKIP, city: SKIP, state: SKIP, state_name: SKIP,
               zip: SKIP, country: SKIP, country_name: SKIP, phone: SKIP,
               verified: SKIP, portal_customer_created_at: SKIP,
               portal_invite_last_sent_at: SKIP,
               portal_invite_last_accepted_at: SKIP, tax_exempt: SKIP,
               vat_number: SKIP, parent_id: SKIP, locale: SKIP,
               default_subscription_group_uid: SKIP, salesforce_id: SKIP,
               tax_exempt_reason: SKIP,
               default_auto_renewal_profile_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
  @id = id unless id == SKIP
  @created_at = created_at unless created_at == SKIP
  @updated_at = updated_at unless updated_at == SKIP
  @address = address unless address == SKIP
  @address_2 = address_2 unless address_2 == SKIP
  @city = city unless city == SKIP
  @state = state unless state == SKIP
  @state_name = state_name unless state_name == SKIP
  @zip = zip unless zip == SKIP
  @country = country unless country == SKIP
  @country_name = country_name unless country_name == SKIP
  @phone = phone unless phone == SKIP
  @verified = verified unless verified == SKIP
  unless portal_customer_created_at == SKIP
    @portal_customer_created_at =
      portal_customer_created_at
  end
  unless portal_invite_last_sent_at == SKIP
    @portal_invite_last_sent_at =
      portal_invite_last_sent_at
  end
  unless portal_invite_last_accepted_at == SKIP
    @portal_invite_last_accepted_at =
      portal_invite_last_accepted_at
  end
  @tax_exempt = tax_exempt unless tax_exempt == SKIP
  @vat_number = vat_number unless vat_number == SKIP
  @parent_id = parent_id unless parent_id == SKIP
  @locale = locale unless locale == SKIP
  unless default_subscription_group_uid == SKIP
    @default_subscription_group_uid =
      default_subscription_group_uid
  end
  @salesforce_id = salesforce_id unless salesforce_id == SKIP
  @tax_exempt_reason = tax_exempt_reason unless tax_exempt_reason == SKIP
  unless default_auto_renewal_profile_id == SKIP
    @default_auto_renewal_profile_id =
      default_auto_renewal_profile_id
  end

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#addressString

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

Returns:

  • (String)


54
55
56
# File 'lib/advanced_billing/models/customer.rb', line 54

def address
  @address
end

#address_2String

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

Returns:

  • (String)


58
59
60
# File 'lib/advanced_billing/models/customer.rb', line 58

def address_2
  @address_2
end

#cc_emailsString

A comma-separated list of emails that should be cc’d on all customer communications (i.e. “[email protected], [email protected]”)

Returns:

  • (String)


28
29
30
# File 'lib/advanced_billing/models/customer.rb', line 28

def cc_emails
  @cc_emails
end

#cityString

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

Returns:

  • (String)


62
63
64
# File 'lib/advanced_billing/models/customer.rb', line 62

def city
  @city
end

#countryString

The customer shipping address country

Returns:

  • (String)


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

def country
  @country
end

#country_nameString

The customer’s full name of country

Returns:

  • (String)


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

def country_name
  @country_name
end

#created_atDateTime

The timestamp in which the customer object was created in Chargify

Returns:

  • (DateTime)


46
47
48
# File 'lib/advanced_billing/models/customer.rb', line 46

def created_at
  @created_at
end

#default_auto_renewal_profile_idInteger

The default auto-renewal profile ID for the customer

Returns:

  • (Integer)


141
142
143
# File 'lib/advanced_billing/models/customer.rb', line 141

def default_auto_renewal_profile_id
  @default_auto_renewal_profile_id
end

#default_subscription_group_uidString

The locale for the customer to identify language-region

Returns:

  • (String)


129
130
131
# File 'lib/advanced_billing/models/customer.rb', line 129

def default_subscription_group_uid
  @default_subscription_group_uid
end

#emailString

The email address of the customer

Returns:

  • (String)


23
24
25
# File 'lib/advanced_billing/models/customer.rb', line 23

def email
  @email
end

#first_nameString

The first name of the customer

Returns:

  • (String)


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

def first_name
  @first_name
end

#idInteger

The customer ID in Chargify

Returns:

  • (Integer)


42
43
44
# File 'lib/advanced_billing/models/customer.rb', line 42

def id
  @id
end

#last_nameString

The last name of the customer

Returns:

  • (String)


19
20
21
# File 'lib/advanced_billing/models/customer.rb', line 19

def last_name
  @last_name
end

#localeString

The locale for the customer to identify language-region

Returns:

  • (String)


125
126
127
# File 'lib/advanced_billing/models/customer.rb', line 125

def locale
  @locale
end

#organizationString

The organization of the customer. If no value, ‘null` or empty string is provided, `organization` will be populated with the customer’s first and last name, separated with a space.

Returns:

  • (String)


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

def organization
  @organization
end

#parent_idInteger

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

Returns:

  • (Integer)


121
122
123
# File 'lib/advanced_billing/models/customer.rb', line 121

def parent_id
  @parent_id
end

#phoneString

The phone number of the customer

Returns:

  • (String)


86
87
88
# File 'lib/advanced_billing/models/customer.rb', line 86

def phone
  @phone
end

#portal_customer_created_atDateTime

The timestamp of when the Billing Portal entry was created at for the customer

Returns:

  • (DateTime)


95
96
97
# File 'lib/advanced_billing/models/customer.rb', line 95

def portal_customer_created_at
  @portal_customer_created_at
end

#portal_invite_last_accepted_atDateTime

The timestamp of when the Billing Portal invite was last accepted

Returns:

  • (DateTime)


103
104
105
# File 'lib/advanced_billing/models/customer.rb', line 103

def portal_invite_last_accepted_at
  @portal_invite_last_accepted_at
end

#portal_invite_last_sent_atDateTime

The timestamp of when the Billing Portal invite was last sent at

Returns:

  • (DateTime)


99
100
101
# File 'lib/advanced_billing/models/customer.rb', line 99

def portal_invite_last_sent_at
  @portal_invite_last_sent_at
end

#referenceString

The unique identifier used within your own application for this customer

Returns:

  • (String)


38
39
40
# File 'lib/advanced_billing/models/customer.rb', line 38

def reference
  @reference
end

#salesforce_idString

The Salesforce ID for the customer

Returns:

  • (String)


133
134
135
# File 'lib/advanced_billing/models/customer.rb', line 133

def salesforce_id
  @salesforce_id
end

#stateString

The customer’s shipping address state (i.e. “MA”)

Returns:

  • (String)


66
67
68
# File 'lib/advanced_billing/models/customer.rb', line 66

def state
  @state
end

#state_nameString

The customer’s full name of state

Returns:

  • (String)


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

def state_name
  @state_name
end

#tax_exemptTrueClass | FalseClass

The tax exempt status for the customer. Acceptable values are true or 1 for true and false or 0 for false.

Returns:

  • (TrueClass | FalseClass)


108
109
110
# File 'lib/advanced_billing/models/customer.rb', line 108

def tax_exempt
  @tax_exempt
end

#tax_exempt_reasonString

The Tax Exemption Reason Code for the customer

Returns:

  • (String)


137
138
139
# File 'lib/advanced_billing/models/customer.rb', line 137

def tax_exempt_reason
  @tax_exempt_reason
end

#updated_atDateTime

The timestamp in which the customer object was last edited

Returns:

  • (DateTime)


50
51
52
# File 'lib/advanced_billing/models/customer.rb', line 50

def updated_at
  @updated_at
end

#vat_numberString

The VAT business identification number for the customer. This number is used to determine VAT tax opt out rules. It is not validated when added or updated on a customer record. Instead, it is validated via VIES before calculating taxes. Only valid business identification numbers will allow for VAT opt out.

Returns:

  • (String)


116
117
118
# File 'lib/advanced_billing/models/customer.rb', line 116

def vat_number
  @vat_number
end

#verifiedTrueClass | FalseClass

Is the customer verified to use ACH as a payment method.

Returns:

  • (TrueClass | FalseClass)


90
91
92
# File 'lib/advanced_billing/models/customer.rb', line 90

def verified
  @verified
end

#zipString

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

Returns:

  • (String)


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

def zip
  @zip
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



313
314
315
316
317
318
319
320
321
322
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
# File 'lib/advanced_billing/models/customer.rb', line 313

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
  id = hash.key?('id') ? hash['id'] : SKIP
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               else
                 SKIP
               end
  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
  state_name = hash.key?('state_name') ? hash['state_name'] : SKIP
  zip = hash.key?('zip') ? hash['zip'] : SKIP
  country = hash.key?('country') ? hash['country'] : SKIP
  country_name = hash.key?('country_name') ? hash['country_name'] : SKIP
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  verified = hash.key?('verified') ? hash['verified'] : SKIP
  portal_customer_created_at = if hash.key?('portal_customer_created_at')
                                 (DateTimeHelper.from_rfc3339(hash['portal_customer_created_at']) if hash['portal_customer_created_at'])
                               else
                                 SKIP
                               end
  portal_invite_last_sent_at = if hash.key?('portal_invite_last_sent_at')
                                 (DateTimeHelper.from_rfc3339(hash['portal_invite_last_sent_at']) if hash['portal_invite_last_sent_at'])
                               else
                                 SKIP
                               end
  portal_invite_last_accepted_at = if hash.key?('portal_invite_last_accepted_at')
                                     (DateTimeHelper.from_rfc3339(hash['portal_invite_last_accepted_at']) if hash['portal_invite_last_accepted_at'])
                                   else
                                     SKIP
                                   end
  tax_exempt = hash.key?('tax_exempt') ? hash['tax_exempt'] : SKIP
  vat_number = hash.key?('vat_number') ? hash['vat_number'] : SKIP
  parent_id = hash.key?('parent_id') ? hash['parent_id'] : SKIP
  locale = hash.key?('locale') ? hash['locale'] : SKIP
  default_subscription_group_uid =
    hash.key?('default_subscription_group_uid') ? hash['default_subscription_group_uid'] : SKIP
  salesforce_id = hash.key?('salesforce_id') ? hash['salesforce_id'] : SKIP
  tax_exempt_reason =
    hash.key?('tax_exempt_reason') ? hash['tax_exempt_reason'] : 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.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  Customer.new(first_name: first_name,
               last_name: last_name,
               email: email,
               cc_emails: cc_emails,
               organization: organization,
               reference: reference,
               id: id,
               created_at: created_at,
               updated_at: updated_at,
               address: address,
               address_2: address_2,
               city: city,
               state: state,
               state_name: state_name,
               zip: zip,
               country: country,
               country_name: country_name,
               phone: phone,
               verified: verified,
               portal_customer_created_at: portal_customer_created_at,
               portal_invite_last_sent_at: portal_invite_last_sent_at,
               portal_invite_last_accepted_at: portal_invite_last_accepted_at,
               tax_exempt: tax_exempt,
               vat_number: vat_number,
               parent_id: parent_id,
               locale: locale,
               default_subscription_group_uid: default_subscription_group_uid,
               salesforce_id: salesforce_id,
               tax_exempt_reason: tax_exempt_reason,
               default_auto_renewal_profile_id: default_auto_renewal_profile_id,
               additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



144
145
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
171
172
173
174
175
176
177
178
179
180
# File 'lib/advanced_billing/models/customer.rb', line 144

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['id'] = 'id'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['address'] = 'address'
  @_hash['address_2'] = 'address_2'
  @_hash['city'] = 'city'
  @_hash['state'] = 'state'
  @_hash['state_name'] = 'state_name'
  @_hash['zip'] = 'zip'
  @_hash['country'] = 'country'
  @_hash['country_name'] = 'country_name'
  @_hash['phone'] = 'phone'
  @_hash['verified'] = 'verified'
  @_hash['portal_customer_created_at'] = 'portal_customer_created_at'
  @_hash['portal_invite_last_sent_at'] = 'portal_invite_last_sent_at'
  @_hash['portal_invite_last_accepted_at'] =
    'portal_invite_last_accepted_at'
  @_hash['tax_exempt'] = 'tax_exempt'
  @_hash['vat_number'] = 'vat_number'
  @_hash['parent_id'] = 'parent_id'
  @_hash['locale'] = 'locale'
  @_hash['default_subscription_group_uid'] =
    'default_subscription_group_uid'
  @_hash['salesforce_id'] = 'salesforce_id'
  @_hash['tax_exempt_reason'] = 'tax_exempt_reason'
  @_hash['default_auto_renewal_profile_id'] =
    'default_auto_renewal_profile_id'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    cc_emails
    organization
    reference
    address
    address_2
    city
    state
    state_name
    zip
    country
    country_name
    phone
    verified
    portal_customer_created_at
    portal_invite_last_sent_at
    portal_invite_last_accepted_at
    vat_number
    parent_id
    locale
    default_subscription_group_uid
    salesforce_id
    tax_exempt_reason
    default_auto_renewal_profile_id
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    first_name
    last_name
    email
    cc_emails
    organization
    reference
    id
    created_at
    updated_at
    address
    address_2
    city
    state
    state_name
    zip
    country
    country_name
    phone
    verified
    portal_customer_created_at
    portal_invite_last_sent_at
    portal_invite_last_accepted_at
    tax_exempt
    vat_number
    parent_id
    locale
    default_subscription_group_uid
    salesforce_id
    tax_exempt_reason
    default_auto_renewal_profile_id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Customer | Hash)

    value against the validation is performed.



430
431
432
433
434
435
436
# File 'lib/advanced_billing/models/customer.rb', line 430

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

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#to_custom_created_atObject



408
409
410
# File 'lib/advanced_billing/models/customer.rb', line 408

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_portal_customer_created_atObject



416
417
418
# File 'lib/advanced_billing/models/customer.rb', line 416

def to_custom_portal_customer_created_at
  DateTimeHelper.to_rfc3339(portal_customer_created_at)
end

#to_custom_portal_invite_last_accepted_atObject



424
425
426
# File 'lib/advanced_billing/models/customer.rb', line 424

def to_custom_portal_invite_last_accepted_at
  DateTimeHelper.to_rfc3339(portal_invite_last_accepted_at)
end

#to_custom_portal_invite_last_sent_atObject



420
421
422
# File 'lib/advanced_billing/models/customer.rb', line 420

def to_custom_portal_invite_last_sent_at
  DateTimeHelper.to_rfc3339(portal_invite_last_sent_at)
end

#to_custom_updated_atObject



412
413
414
# File 'lib/advanced_billing/models/customer.rb', line 412

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end