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

#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, 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) ⇒ Component

Returns a new instance of Component.



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

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, 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)
  @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
  @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
end

Instance Attribute Details

#accounting_codeString

E.g. Internal ID or SKU Number

Returns:

  • (String)


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

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)


140
141
142
# File 'lib/advanced_billing/models/component.rb', line 140

def allow_fractional_quantities
  @allow_fractional_quantities
end

#archivedTrueClass | FalseClass

Boolean flag describing whether a component is archived or not.

Returns:

  • (TrueClass | FalseClass)


61
62
63
# File 'lib/advanced_billing/models/component.rb', line 61

def archived
  @archived
end

#archived_atString

Timestamp indicating when this component was archived

Returns:

  • (String)


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

def archived_at
  @archived_at
end

#created_atString

Timestamp indicating when this component was created

Returns:

  • (String)


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

def created_at
  @created_at
end

#default_price_point_idInteger

The description of the component.

Returns:

  • (Integer)


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

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)


92
93
94
# File 'lib/advanced_billing/models/component.rb', line 92

def default_price_point_name
  @default_price_point_name
end

#descriptionString

The description of the component.

Returns:

  • (String)


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

def description
  @description
end

#downgrade_creditString

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)


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

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)


159
160
161
# File 'lib/advanced_billing/models/component.rb', line 159

def event_based_billing_metric_id
  @event_based_billing_metric_id
end

#handleString

The component API handle

Returns:

  • (String)


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

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)


134
135
136
# File 'lib/advanced_billing/models/component.rb', line 134

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)


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

def id
  @id
end

#item_categoryItemCategory

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

Returns:



145
146
147
# File 'lib/advanced_billing/models/component.rb', line 145

def item_category
  @item_category
end

#kindComponentKind

A handle for the component type

Returns:



57
58
59
# File 'lib/advanced_billing/models/component.rb', line 57

def kind
  @kind
end

#nameString

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

Returns:

  • (String)


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

def name
  @name
end

#price_per_unit_in_centsInteger

deprecated - use unit_price instead

Returns:

  • (Integer)


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

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)


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

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)


87
88
89
# File 'lib/advanced_billing/models/component.rb', line 87

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:



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

def prices
  @prices
end

#pricing_schemeString

The handle for the pricing scheme. Available options: per_unit, volume, tiered, stairstep. See [Price Bracket Rules](chargify.zendesk.com/hc/en-us/articles/4407755865883#price- bracket-rules) for an overview of pricing schemes.

Returns:

  • (String)


31
32
33
# File 'lib/advanced_billing/models/component.rb', line 31

def pricing_scheme
  @pricing_scheme
end

#product_family_idInteger

The id of the Product Family to which the Component belongs

Returns:

  • (Integer)


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

def product_family_id
  @product_family_id
end

#product_family_nameString

The name of the Product Family to which the Component belongs

Returns:

  • (String)


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

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)


104
105
106
# File 'lib/advanced_billing/models/component.rb', line 104

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)


98
99
100
# File 'lib/advanced_billing/models/component.rb', line 98

def tax_code
  @tax_code
end

#taxableTrueClass | FalseClass

Boolean flag describing whether a component is taxable or not.

Returns:

  • (TrueClass | FalseClass)


65
66
67
# File 'lib/advanced_billing/models/component.rb', line 65

def taxable
  @taxable
end

#unit_nameString

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

Returns:

  • (String)


36
37
38
# File 'lib/advanced_billing/models/component.rb', line 36

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)


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

def unit_price
  @unit_price
end

#updated_atString

Timestamp indicating when this component was updated

Returns:

  • (String)


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

def updated_at
  @updated_at
end

#upgrade_chargeString

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)


110
111
112
# File 'lib/advanced_billing/models/component.rb', line 110

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)


150
151
152
# File 'lib/advanced_billing/models/component.rb', line 150

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.



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

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

  # Create object from extracted values.
  Component.new(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,
                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)
end

.namesObject

A mapping from model property names to API property names.



162
163
164
165
166
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
# File 'lib/advanced_billing/models/component.rb', line 162

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['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
end

.nullablesObject

An array for nullable fields



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/advanced_billing/models/component.rb', line 237

def self.nullables
  %w[
    pricing_scheme
    unit_price
    price_per_unit_in_cents
    description
    prices
    tax_code
    upgrade_charge
    downgrade_credit
    archived_at
    use_site_exchange_rate
    accounting_code
  ]
end

.optionalsObject

An array for optional fields



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

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
    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
  ]
end