Class: AdvancedBilling::Component

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

Overview

Component Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id: SKIP, name: SKIP, handle: SKIP, pricing_scheme: SKIP, unit_name: SKIP, unit_price: SKIP, product_family_id: SKIP, product_family_name: SKIP, price_per_unit_in_cents: SKIP, kind: SKIP, archived: SKIP, taxable: SKIP, description: SKIP, default_price_point_id: SKIP, overage_prices: SKIP, prices: SKIP, price_point_count: SKIP, price_points_url: SKIP, default_price_point_name: SKIP, tax_code: SKIP, recurring: SKIP, upgrade_charge: SKIP, downgrade_credit: SKIP, created_at: SKIP, updated_at: SKIP, archived_at: SKIP, hide_date_range_on_invoice: SKIP, allow_fractional_quantities: SKIP, item_category: SKIP, use_site_exchange_rate: SKIP, accounting_code: SKIP, event_based_billing_metric_id: SKIP, interval: SKIP, interval_unit: SKIP, additional_properties: {}) ⇒ Component

Returns a new instance of Component.



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
311
312
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
# File 'lib/advanced_billing/models/component.rb', line 281

def initialize(id: SKIP, name: SKIP, handle: SKIP, pricing_scheme: SKIP,
               unit_name: SKIP, unit_price: SKIP, product_family_id: SKIP,
               product_family_name: SKIP, price_per_unit_in_cents: SKIP,
               kind: SKIP, archived: SKIP, taxable: SKIP, description: SKIP,
               default_price_point_id: SKIP, overage_prices: SKIP,
               prices: SKIP, price_point_count: SKIP,
               price_points_url: SKIP, default_price_point_name: SKIP,
               tax_code: SKIP, recurring: SKIP, upgrade_charge: SKIP,
               downgrade_credit: SKIP, created_at: SKIP, updated_at: SKIP,
               archived_at: SKIP, hide_date_range_on_invoice: SKIP,
               allow_fractional_quantities: SKIP, item_category: SKIP,
               use_site_exchange_rate: SKIP, accounting_code: SKIP,
               event_based_billing_metric_id: SKIP, interval: SKIP,
               interval_unit: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @id = id unless id == SKIP
  @name = name unless name == SKIP
  @handle = handle unless handle == SKIP
  @pricing_scheme = pricing_scheme unless pricing_scheme == SKIP
  @unit_name = unit_name unless unit_name == SKIP
  @unit_price = unit_price unless unit_price == SKIP
  @product_family_id = product_family_id unless product_family_id == SKIP
  @product_family_name = product_family_name unless product_family_name == SKIP
  @price_per_unit_in_cents = price_per_unit_in_cents unless price_per_unit_in_cents == SKIP
  @kind = kind unless kind == SKIP
  @archived = archived unless archived == SKIP
  @taxable = taxable unless taxable == SKIP
  @description = description unless description == SKIP
  @default_price_point_id = default_price_point_id unless default_price_point_id == SKIP
  @overage_prices = overage_prices unless overage_prices == SKIP
  @prices = prices unless prices == SKIP
  @price_point_count = price_point_count unless price_point_count == SKIP
  @price_points_url = price_points_url unless price_points_url == SKIP
  @default_price_point_name = default_price_point_name unless default_price_point_name == SKIP
  @tax_code = tax_code unless tax_code == SKIP
  @recurring = recurring unless recurring == SKIP
  @upgrade_charge = upgrade_charge unless upgrade_charge == SKIP
  @downgrade_credit = downgrade_credit unless downgrade_credit == SKIP
  @created_at = created_at unless created_at == SKIP
  @updated_at = updated_at unless updated_at == SKIP
  @archived_at = archived_at unless archived_at == SKIP
  unless hide_date_range_on_invoice == SKIP
    @hide_date_range_on_invoice =
      hide_date_range_on_invoice
  end
  unless allow_fractional_quantities == SKIP
    @allow_fractional_quantities =
      allow_fractional_quantities
  end
  @item_category = item_category unless item_category == SKIP
  @use_site_exchange_rate = use_site_exchange_rate unless use_site_exchange_rate == SKIP
  @accounting_code = accounting_code unless accounting_code == SKIP
  unless event_based_billing_metric_id == SKIP
    @event_based_billing_metric_id =
      event_based_billing_metric_id
  end
  @interval = interval unless interval == SKIP
  @interval_unit = interval_unit unless interval_unit == SKIP
end

Instance Attribute Details

#accounting_codeString

E.g. Internal ID or SKU Number

Returns:

  • (String)


157
158
159
# File 'lib/advanced_billing/models/component.rb', line 157

def accounting_code
  @accounting_code
end

#allow_fractional_quantitiesTrueClass | FalseClass

(Only available on Relationship Invoicing sites) Boolean flag describing if the service date range should show for the component on generated invoices.

Returns:

  • (TrueClass | FalseClass)


143
144
145
# File 'lib/advanced_billing/models/component.rb', line 143

def allow_fractional_quantities
  @allow_fractional_quantities
end

#archivedTrueClass | FalseClass

Boolean flag describing whether a component is archived or not.

Returns:

  • (TrueClass | FalseClass)


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

def archived
  @archived
end

#archived_atDateTime

Timestamp indicating when this component was archived

Returns:

  • (DateTime)


131
132
133
# File 'lib/advanced_billing/models/component.rb', line 131

def archived_at
  @archived_at
end

#created_atDateTime

Timestamp indicating when this component was created

Returns:

  • (DateTime)


123
124
125
# File 'lib/advanced_billing/models/component.rb', line 123

def created_at
  @created_at
end

#default_price_point_idInteger

The description of the component.

Returns:

  • (Integer)


71
72
73
# File 'lib/advanced_billing/models/component.rb', line 71

def default_price_point_id
  @default_price_point_id
end

#default_price_point_nameString

URL that points to the location to read the existing price points via GET request

Returns:

  • (String)


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

def default_price_point_name
  @default_price_point_name
end

#descriptionString

The description of the component.

Returns:

  • (String)


67
68
69
# File 'lib/advanced_billing/models/component.rb', line 67

def description
  @description
end

#downgrade_creditCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Available values: ‘full`, `prorated`, `none`.

Returns:



119
120
121
# File 'lib/advanced_billing/models/component.rb', line 119

def downgrade_credit
  @downgrade_credit
end

#event_based_billing_metric_idInteger

(Only for Event Based Components) This is an ID of a metric attached to the component. This metric is used to bill upon collected events.

Returns:

  • (Integer)


162
163
164
# File 'lib/advanced_billing/models/component.rb', line 162

def event_based_billing_metric_id
  @event_based_billing_metric_id
end

#handleString

The component API handle

Returns:

  • (String)


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

def handle
  @handle
end

#hide_date_range_on_invoiceTrueClass | FalseClass

(Only available on Relationship Invoicing sites) Boolean flag describing if the service date range should show for the component on generated invoices.

Returns:

  • (TrueClass | FalseClass)


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

def hide_date_range_on_invoice
  @hide_date_range_on_invoice
end

#idInteger

The unique ID assigned to the component by Chargify. This ID can be used to fetch the component from the API.

Returns:

  • (Integer)


16
17
18
# File 'lib/advanced_billing/models/component.rb', line 16

def id
  @id
end

#intervalInteger

The numerical interval. i.e. an interval of ‘30’ coupled with an interval_unit of day would mean this component’s default price point would renew every 30 days. This property is only available for sites with Multifrequency enabled.

Returns:

  • (Integer)


169
170
171
# File 'lib/advanced_billing/models/component.rb', line 169

def interval
  @interval
end

#interval_unitIntervalUnit

A string representing the interval unit for this component’s default price point, either month or day. This property is only available for sites with Multifrequency enabled.

Returns:



175
176
177
# File 'lib/advanced_billing/models/component.rb', line 175

def interval_unit
  @interval_unit
end

#item_categoryItemCategory

One of the following: Business Software, Consumer Software, Digital Services, Physical Goods, Other

Returns:



148
149
150
# File 'lib/advanced_billing/models/component.rb', line 148

def item_category
  @item_category
end

#kindComponentKind

A handle for the component type

Returns:



55
56
57
# File 'lib/advanced_billing/models/component.rb', line 55

def kind
  @kind
end

#nameString

The name of the Component, suitable for display on statements. i.e. Text Messages.

Returns:

  • (String)


21
22
23
# File 'lib/advanced_billing/models/component.rb', line 21

def name
  @name
end

#overage_pricesArray[ComponentPrice]

Applicable only to prepaid usage components. An array of overage price brackets.

Returns:



76
77
78
# File 'lib/advanced_billing/models/component.rb', line 76

def overage_prices
  @overage_prices
end

#price_per_unit_in_centsInteger

deprecated - use unit_price instead

Returns:

  • (Integer)


51
52
53
# File 'lib/advanced_billing/models/component.rb', line 51

def price_per_unit_in_cents
  @price_per_unit_in_cents
end

#price_point_countInteger

Count for the number of price points associated with the component

Returns:

  • (Integer)


85
86
87
# File 'lib/advanced_billing/models/component.rb', line 85

def price_point_count
  @price_point_count
end

#price_points_urlString

URL that points to the location to read the existing price points via GET request

Returns:

  • (String)


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

def price_points_url
  @price_points_url
end

#pricesArray[ComponentPrice]

An array of price brackets. If the component uses the ‘per_unit’ pricing scheme, this array will be empty.

Returns:



81
82
83
# File 'lib/advanced_billing/models/component.rb', line 81

def prices
  @prices
end

#pricing_schemePricingScheme

The component API handle

Returns:



29
30
31
# File 'lib/advanced_billing/models/component.rb', line 29

def pricing_scheme
  @pricing_scheme
end

#product_family_idInteger

The id of the Product Family to which the Component belongs

Returns:

  • (Integer)


43
44
45
# File 'lib/advanced_billing/models/component.rb', line 43

def product_family_id
  @product_family_id
end

#product_family_nameString

The name of the Product Family to which the Component belongs

Returns:

  • (String)


47
48
49
# File 'lib/advanced_billing/models/component.rb', line 47

def product_family_name
  @product_family_name
end

#recurringTrueClass | FalseClass

A string representing the tax code related to the component type. This is especially important when using the Avalara service to tax based on locale. This attribute has a max length of 10 characters.

Returns:

  • (TrueClass | FalseClass)


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

def recurring
  @recurring
end

#tax_codeString

A string representing the tax code related to the component type. This is especially important when using the Avalara service to tax based on locale. This attribute has a max length of 10 characters.

Returns:

  • (String)


101
102
103
# File 'lib/advanced_billing/models/component.rb', line 101

def tax_code
  @tax_code
end

#taxableTrueClass | FalseClass

Boolean flag describing whether a component is taxable or not.

Returns:

  • (TrueClass | FalseClass)


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

def taxable
  @taxable
end

#unit_nameString

The name of the unit that the component’s usage is measured in. i.e. message

Returns:

  • (String)


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

def unit_name
  @unit_name
end

#unit_priceString

The amount the customer will be charged per unit. This field is only populated for ‘per_unit’ pricing schemes, otherwise it may be null.

Returns:

  • (String)


39
40
41
# File 'lib/advanced_billing/models/component.rb', line 39

def unit_price
  @unit_price
end

#updated_atDateTime

Timestamp indicating when this component was updated

Returns:

  • (DateTime)


127
128
129
# File 'lib/advanced_billing/models/component.rb', line 127

def updated_at
  @updated_at
end

#upgrade_chargeCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Available values: ‘full`, `prorated`, `none`.

Returns:



113
114
115
# File 'lib/advanced_billing/models/component.rb', line 113

def upgrade_charge
  @upgrade_charge
end

#use_site_exchange_rateTrueClass | FalseClass

One of the following: Business Software, Consumer Software, Digital Services, Physical Goods, Other

Returns:

  • (TrueClass | FalseClass)


153
154
155
# File 'lib/advanced_billing/models/component.rb', line 153

def use_site_exchange_rate
  @use_site_exchange_rate
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
423
424
425
426
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
465
466
467
468
469
# File 'lib/advanced_billing/models/component.rb', line 346

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  pricing_scheme =
    hash.key?('pricing_scheme') ? hash['pricing_scheme'] : SKIP
  unit_name = hash.key?('unit_name') ? hash['unit_name'] : SKIP
  unit_price = hash.key?('unit_price') ? hash['unit_price'] : SKIP
  product_family_id =
    hash.key?('product_family_id') ? hash['product_family_id'] : SKIP
  product_family_name =
    hash.key?('product_family_name') ? hash['product_family_name'] : SKIP
  price_per_unit_in_cents =
    hash.key?('price_per_unit_in_cents') ? hash['price_per_unit_in_cents'] : SKIP
  kind = hash.key?('kind') ? hash['kind'] : SKIP
  archived = hash.key?('archived') ? hash['archived'] : SKIP
  taxable = hash.key?('taxable') ? hash['taxable'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  default_price_point_id =
    hash.key?('default_price_point_id') ? hash['default_price_point_id'] : SKIP
  # Parameter is an array, so we need to iterate through it
  overage_prices = nil
  unless hash['overage_prices'].nil?
    overage_prices = []
    hash['overage_prices'].each do |structure|
      overage_prices << (ComponentPrice.from_hash(structure) if structure)
    end
  end

  overage_prices = SKIP unless hash.key?('overage_prices')
  # Parameter is an array, so we need to iterate through it
  prices = nil
  unless hash['prices'].nil?
    prices = []
    hash['prices'].each do |structure|
      prices << (ComponentPrice.from_hash(structure) if structure)
    end
  end

  prices = SKIP unless hash.key?('prices')
  price_point_count =
    hash.key?('price_point_count') ? hash['price_point_count'] : SKIP
  price_points_url =
    hash.key?('price_points_url') ? hash['price_points_url'] : SKIP
  default_price_point_name =
    hash.key?('default_price_point_name') ? hash['default_price_point_name'] : SKIP
  tax_code = hash.key?('tax_code') ? hash['tax_code'] : SKIP
  recurring = hash.key?('recurring') ? hash['recurring'] : SKIP
  upgrade_charge =
    hash.key?('upgrade_charge') ? hash['upgrade_charge'] : SKIP
  downgrade_credit =
    hash.key?('downgrade_credit') ? hash['downgrade_credit'] : 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
  archived_at = if hash.key?('archived_at')
                  (DateTimeHelper.from_rfc3339(hash['archived_at']) if hash['archived_at'])
                else
                  SKIP
                end
  hide_date_range_on_invoice =
    hash.key?('hide_date_range_on_invoice') ? hash['hide_date_range_on_invoice'] : SKIP
  allow_fractional_quantities =
    hash.key?('allow_fractional_quantities') ? hash['allow_fractional_quantities'] : SKIP
  item_category = hash.key?('item_category') ? hash['item_category'] : SKIP
  use_site_exchange_rate =
    hash.key?('use_site_exchange_rate') ? hash['use_site_exchange_rate'] : SKIP
  accounting_code =
    hash.key?('accounting_code') ? hash['accounting_code'] : SKIP
  event_based_billing_metric_id =
    hash.key?('event_based_billing_metric_id') ? hash['event_based_billing_metric_id'] : SKIP
  interval = hash.key?('interval') ? hash['interval'] : SKIP
  interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  Component.new(id: id,
                name: name,
                handle: handle,
                pricing_scheme: pricing_scheme,
                unit_name: unit_name,
                unit_price: unit_price,
                product_family_id: product_family_id,
                product_family_name: product_family_name,
                price_per_unit_in_cents: price_per_unit_in_cents,
                kind: kind,
                archived: archived,
                taxable: taxable,
                description: description,
                default_price_point_id: default_price_point_id,
                overage_prices: overage_prices,
                prices: prices,
                price_point_count: price_point_count,
                price_points_url: price_points_url,
                default_price_point_name: default_price_point_name,
                tax_code: tax_code,
                recurring: recurring,
                upgrade_charge: upgrade_charge,
                downgrade_credit: downgrade_credit,
                created_at: created_at,
                updated_at: updated_at,
                archived_at: archived_at,
                hide_date_range_on_invoice: hide_date_range_on_invoice,
                allow_fractional_quantities: allow_fractional_quantities,
                item_category: item_category,
                use_site_exchange_rate: use_site_exchange_rate,
                accounting_code: accounting_code,
                event_based_billing_metric_id: event_based_billing_metric_id,
                interval: interval,
                interval_unit: interval_unit,
                additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



178
179
180
181
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
# File 'lib/advanced_billing/models/component.rb', line 178

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['unit_name'] = 'unit_name'
  @_hash['unit_price'] = 'unit_price'
  @_hash['product_family_id'] = 'product_family_id'
  @_hash['product_family_name'] = 'product_family_name'
  @_hash['price_per_unit_in_cents'] = 'price_per_unit_in_cents'
  @_hash['kind'] = 'kind'
  @_hash['archived'] = 'archived'
  @_hash['taxable'] = 'taxable'
  @_hash['description'] = 'description'
  @_hash['default_price_point_id'] = 'default_price_point_id'
  @_hash['overage_prices'] = 'overage_prices'
  @_hash['prices'] = 'prices'
  @_hash['price_point_count'] = 'price_point_count'
  @_hash['price_points_url'] = 'price_points_url'
  @_hash['default_price_point_name'] = 'default_price_point_name'
  @_hash['tax_code'] = 'tax_code'
  @_hash['recurring'] = 'recurring'
  @_hash['upgrade_charge'] = 'upgrade_charge'
  @_hash['downgrade_credit'] = 'downgrade_credit'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['archived_at'] = 'archived_at'
  @_hash['hide_date_range_on_invoice'] = 'hide_date_range_on_invoice'
  @_hash['allow_fractional_quantities'] = 'allow_fractional_quantities'
  @_hash['item_category'] = 'item_category'
  @_hash['use_site_exchange_rate'] = 'use_site_exchange_rate'
  @_hash['accounting_code'] = 'accounting_code'
  @_hash['event_based_billing_metric_id'] =
    'event_based_billing_metric_id'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/advanced_billing/models/component.rb', line 259

def self.nullables
  %w[
    handle
    pricing_scheme
    unit_price
    price_per_unit_in_cents
    description
    default_price_point_id
    overage_prices
    prices
    price_points_url
    tax_code
    upgrade_charge
    downgrade_credit
    archived_at
    item_category
    use_site_exchange_rate
    accounting_code
    interval_unit
  ]
end

.optionalsObject

An array for optional 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
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/advanced_billing/models/component.rb', line 219

def self.optionals
  %w[
    id
    name
    handle
    pricing_scheme
    unit_name
    unit_price
    product_family_id
    product_family_name
    price_per_unit_in_cents
    kind
    archived
    taxable
    description
    default_price_point_id
    overage_prices
    prices
    price_point_count
    price_points_url
    default_price_point_name
    tax_code
    recurring
    upgrade_charge
    downgrade_credit
    created_at
    updated_at
    archived_at
    hide_date_range_on_invoice
    allow_fractional_quantities
    item_category
    use_site_exchange_rate
    accounting_code
    event_based_billing_metric_id
    interval
    interval_unit
  ]
end

Instance Method Details

#to_custom_archived_atObject



479
480
481
# File 'lib/advanced_billing/models/component.rb', line 479

def to_custom_archived_at
  DateTimeHelper.to_rfc3339(archived_at)
end

#to_custom_created_atObject



471
472
473
# File 'lib/advanced_billing/models/component.rb', line 471

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



475
476
477
# File 'lib/advanced_billing/models/component.rb', line 475

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end