Class: AdvancedBilling::SubscriptionComponent

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

Overview

SubscriptionComponent 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, kind: SKIP, unit_name: SKIP, enabled: SKIP, unit_balance: SKIP, currency: SKIP, allocated_quantity: SKIP, pricing_scheme: SKIP, component_id: SKIP, component_handle: SKIP, subscription_id: SKIP, recurring: SKIP, upgrade_charge: SKIP, downgrade_credit: SKIP, archived_at: SKIP, price_point_id: SKIP, price_point_handle: SKIP, price_point_type: SKIP, price_point_name: SKIP, product_family_id: SKIP, product_family_handle: SKIP, created_at: SKIP, updated_at: SKIP, use_site_exchange_rate: SKIP, description: SKIP, allow_fractional_quantities: SKIP, subscription: SKIP, historic_usages: SKIP, display_on_hosted_page: SKIP, interval: SKIP, interval_unit: SKIP, additional_properties: {}) ⇒ SubscriptionComponent

Returns a new instance of SubscriptionComponent.



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

def initialize(id: SKIP, name: SKIP, kind: SKIP, unit_name: SKIP,
               enabled: SKIP, unit_balance: SKIP, currency: SKIP,
               allocated_quantity: SKIP, pricing_scheme: SKIP,
               component_id: SKIP, component_handle: SKIP,
               subscription_id: SKIP, recurring: SKIP, upgrade_charge: SKIP,
               downgrade_credit: SKIP, archived_at: SKIP,
               price_point_id: SKIP, price_point_handle: SKIP,
               price_point_type: SKIP, price_point_name: SKIP,
               product_family_id: SKIP, product_family_handle: SKIP,
               created_at: SKIP, updated_at: SKIP,
               use_site_exchange_rate: SKIP, description: SKIP,
               allow_fractional_quantities: SKIP, subscription: SKIP,
               historic_usages: SKIP, display_on_hosted_page: SKIP,
               interval: SKIP, interval_unit: SKIP,
               additional_properties: {})
  @id = id unless id == SKIP
  @name = name unless name == SKIP
  @kind = kind unless kind == SKIP
  @unit_name = unit_name unless unit_name == SKIP
  @enabled = enabled unless enabled == SKIP
  @unit_balance = unit_balance unless unit_balance == SKIP
  @currency = currency unless currency == SKIP
  @allocated_quantity = allocated_quantity unless allocated_quantity == SKIP
  @pricing_scheme = pricing_scheme unless pricing_scheme == SKIP
  @component_id = component_id unless component_id == SKIP
  @component_handle = component_handle unless component_handle == SKIP
  @subscription_id = subscription_id unless subscription_id == SKIP
  @recurring = recurring unless recurring == SKIP
  @upgrade_charge = upgrade_charge unless upgrade_charge == SKIP
  @downgrade_credit = downgrade_credit unless downgrade_credit == SKIP
  @archived_at = archived_at unless archived_at == SKIP
  @price_point_id = price_point_id unless price_point_id == SKIP
  @price_point_handle = price_point_handle unless price_point_handle == SKIP
  @price_point_type = price_point_type unless price_point_type == SKIP
  @price_point_name = price_point_name unless price_point_name == SKIP
  @product_family_id = product_family_id unless product_family_id == SKIP
  @product_family_handle = product_family_handle unless product_family_handle == SKIP
  @created_at = created_at unless created_at == SKIP
  @updated_at = updated_at unless updated_at == SKIP
  @use_site_exchange_rate = use_site_exchange_rate unless use_site_exchange_rate == SKIP
  @description = description unless description == SKIP
  unless allow_fractional_quantities == SKIP
    @allow_fractional_quantities =
      allow_fractional_quantities
  end
  @subscription = subscription unless subscription == SKIP
  @historic_usages = historic_usages unless historic_usages == SKIP
  @display_on_hosted_page = display_on_hosted_page unless display_on_hosted_page == SKIP
  @interval = interval unless interval == SKIP
  @interval_unit = interval_unit unless interval_unit == SKIP

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

Instance Attribute Details

#allocated_quantityObject

For Quantity-based components: The current allocation for the component on the given subscription. For On/Off components: Use 1 for on. Use 0 for off.

Returns:

  • (Object)


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

def allocated_quantity
  @allocated_quantity
end

#allow_fractional_quantitiesTrueClass | FalseClass

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:

  • (TrueClass | FalseClass)


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

def allow_fractional_quantities
  @allow_fractional_quantities
end

#archived_atDateTime

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:

  • (DateTime)


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

def archived_at
  @archived_at
end

#component_handleString

For Quantity-based components: The current allocation for the component on the given subscription. For On/Off components: Use 1 for on. Use 0 for off.

Returns:

  • (String)


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

def component_handle
  @component_handle
end

#component_idInteger

For Quantity-based components: The current allocation for the component on the given subscription. For On/Off components: Use 1 for on. Use 0 for off.

Returns:

  • (Integer)


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

def component_id
  @component_id
end

#created_atDateTime

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:

  • (DateTime)


138
139
140
# File 'lib/advanced_billing/models/subscription_component.rb', line 138

def created_at
  @created_at
end

#currencyString

(for on/off components) indicates if the component is enabled for the subscription

Returns:

  • (String)


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

def currency
  @currency
end

#descriptionString

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:

  • (String)


156
157
158
# File 'lib/advanced_billing/models/subscription_component.rb', line 156

def description
  @description
end

#display_on_hosted_pageTrueClass | FalseClass

An optional object, will be returned if provided ‘include=subscription` query param.

Returns:

  • (TrueClass | FalseClass)


177
178
179
# File 'lib/advanced_billing/models/subscription_component.rb', line 177

def display_on_hosted_page
  @display_on_hosted_page
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:



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

def downgrade_credit
  @downgrade_credit
end

#enabledTrueClass | FalseClass

(for on/off components) indicates if the component is enabled for the subscription

Returns:

  • (TrueClass | FalseClass)


32
33
34
# File 'lib/advanced_billing/models/subscription_component.rb', line 32

def enabled
  @enabled
end

#historic_usagesArray[HistoricUsage]

An optional object, will be returned if provided ‘include=subscription` query param.

Returns:



172
173
174
# File 'lib/advanced_billing/models/subscription_component.rb', line 172

def historic_usages
  @historic_usages
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

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 price point would renew every 30 days. This property is only available for sites with Multifrequency enabled.

Returns:

  • (Integer)


184
185
186
# File 'lib/advanced_billing/models/subscription_component.rb', line 184

def interval
  @interval
end

#interval_unitIntervalUnit

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

Returns:



190
191
192
# File 'lib/advanced_billing/models/subscription_component.rb', line 190

def interval_unit
  @interval_unit
end

#kindComponentKind

A handle for the component type

Returns:



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

def kind
  @kind
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def name
  @name
end

#price_point_handleString

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:

  • (String)


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

def price_point_handle
  @price_point_handle
end

#price_point_idInteger

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:

  • (Integer)


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

def price_point_id
  @price_point_id
end

#price_point_nameString

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:

  • (String)


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

def price_point_name
  @price_point_name
end

#price_point_typePricePointType

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:



114
115
116
# File 'lib/advanced_billing/models/subscription_component.rb', line 114

def price_point_type
  @price_point_type
end

#pricing_schemePricingScheme

For Quantity-based components: The current allocation for the component on the given subscription. For On/Off components: Use 1 for on. Use 0 for off.

Returns:



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

def pricing_scheme
  @pricing_scheme
end

#product_family_handleString

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:

  • (String)


132
133
134
# File 'lib/advanced_billing/models/subscription_component.rb', line 132

def product_family_handle
  @product_family_handle
end

#product_family_idInteger

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:

  • (Integer)


126
127
128
# File 'lib/advanced_billing/models/subscription_component.rb', line 126

def product_family_id
  @product_family_id
end

#recurringTrueClass | FalseClass

For Quantity-based components: The current allocation for the component on the given subscription. For On/Off components: Use 1 for on. Use 0 for off.

Returns:

  • (TrueClass | FalseClass)


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

def recurring
  @recurring
end

#subscriptionSubscriptionComponentSubscription

An optional object, will be returned if provided ‘include=subscription` query param.



167
168
169
# File 'lib/advanced_billing/models/subscription_component.rb', line 167

def subscription
  @subscription
end

#subscription_idInteger

For Quantity-based components: The current allocation for the component on the given subscription. For On/Off components: Use 1 for on. Use 0 for off.

Returns:

  • (Integer)


72
73
74
# File 'lib/advanced_billing/models/subscription_component.rb', line 72

def subscription_id
  @subscription_id
end

#unit_balanceInteger

(for on/off components) indicates if the component is enabled for the subscription

Returns:

  • (Integer)


37
38
39
# File 'lib/advanced_billing/models/subscription_component.rb', line 37

def unit_balance
  @unit_balance
end

#unit_nameString

A handle for the component type

Returns:

  • (String)


27
28
29
# File 'lib/advanced_billing/models/subscription_component.rb', line 27

def unit_name
  @unit_name
end

#updated_atDateTime

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:

  • (DateTime)


144
145
146
# File 'lib/advanced_billing/models/subscription_component.rb', line 144

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:



84
85
86
# File 'lib/advanced_billing/models/subscription_component.rb', line 84

def upgrade_charge
  @upgrade_charge
end

#use_site_exchange_rateTrueClass | FalseClass

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:

  • (TrueClass | FalseClass)


150
151
152
# File 'lib/advanced_billing/models/subscription_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.



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

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
  kind = hash.key?('kind') ? hash['kind'] : SKIP
  unit_name = hash.key?('unit_name') ? hash['unit_name'] : SKIP
  enabled = hash.key?('enabled') ? hash['enabled'] : SKIP
  unit_balance = hash.key?('unit_balance') ? hash['unit_balance'] : SKIP
  currency = hash.key?('currency') ? hash['currency'] : SKIP
  allocated_quantity = hash.key?('allocated_quantity') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:SubscriptionComponentAllocatedQuantity), hash['allocated_quantity']
  ) : SKIP
  pricing_scheme =
    hash.key?('pricing_scheme') ? hash['pricing_scheme'] : SKIP
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  component_handle =
    hash.key?('component_handle') ? hash['component_handle'] : SKIP
  subscription_id =
    hash.key?('subscription_id') ? hash['subscription_id'] : 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
  archived_at = if hash.key?('archived_at')
                  (DateTimeHelper.from_rfc3339(hash['archived_at']) if hash['archived_at'])
                else
                  SKIP
                end
  price_point_id =
    hash.key?('price_point_id') ? hash['price_point_id'] : SKIP
  price_point_handle =
    hash.key?('price_point_handle') ? hash['price_point_handle'] : SKIP
  price_point_type =
    hash.key?('price_point_type') ? hash['price_point_type'] : SKIP
  price_point_name =
    hash.key?('price_point_name') ? hash['price_point_name'] : SKIP
  product_family_id =
    hash.key?('product_family_id') ? hash['product_family_id'] : SKIP
  product_family_handle =
    hash.key?('product_family_handle') ? hash['product_family_handle'] : 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
  use_site_exchange_rate =
    hash.key?('use_site_exchange_rate') ? hash['use_site_exchange_rate'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  allow_fractional_quantities =
    hash.key?('allow_fractional_quantities') ? hash['allow_fractional_quantities'] : SKIP
  subscription = SubscriptionComponentSubscription.from_hash(hash['subscription']) if
    hash['subscription']
  # Parameter is an array, so we need to iterate through it
  historic_usages = nil
  unless hash['historic_usages'].nil?
    historic_usages = []
    hash['historic_usages'].each do |structure|
      historic_usages << (HistoricUsage.from_hash(structure) if structure)
    end
  end

  historic_usages = SKIP unless hash.key?('historic_usages')
  display_on_hosted_page =
    hash.key?('display_on_hosted_page') ? hash['display_on_hosted_page'] : SKIP
  interval = hash.key?('interval') ? hash['interval'] : SKIP
  interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : SKIP

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  SubscriptionComponent.new(id: id,
                            name: name,
                            kind: kind,
                            unit_name: unit_name,
                            enabled: enabled,
                            unit_balance: unit_balance,
                            currency: currency,
                            allocated_quantity: allocated_quantity,
                            pricing_scheme: pricing_scheme,
                            component_id: component_id,
                            component_handle: component_handle,
                            subscription_id: subscription_id,
                            recurring: recurring,
                            upgrade_charge: upgrade_charge,
                            downgrade_credit: downgrade_credit,
                            archived_at: archived_at,
                            price_point_id: price_point_id,
                            price_point_handle: price_point_handle,
                            price_point_type: price_point_type,
                            price_point_name: price_point_name,
                            product_family_id: product_family_id,
                            product_family_handle: product_family_handle,
                            created_at: created_at,
                            updated_at: updated_at,
                            use_site_exchange_rate: use_site_exchange_rate,
                            description: description,
                            allow_fractional_quantities: allow_fractional_quantities,
                            subscription: subscription,
                            historic_usages: historic_usages,
                            display_on_hosted_page: display_on_hosted_page,
                            interval: interval,
                            interval_unit: interval_unit,
                            additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



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
220
221
222
223
224
225
226
227
228
# File 'lib/advanced_billing/models/subscription_component.rb', line 193

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['kind'] = 'kind'
  @_hash['unit_name'] = 'unit_name'
  @_hash['enabled'] = 'enabled'
  @_hash['unit_balance'] = 'unit_balance'
  @_hash['currency'] = 'currency'
  @_hash['allocated_quantity'] = 'allocated_quantity'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['component_id'] = 'component_id'
  @_hash['component_handle'] = 'component_handle'
  @_hash['subscription_id'] = 'subscription_id'
  @_hash['recurring'] = 'recurring'
  @_hash['upgrade_charge'] = 'upgrade_charge'
  @_hash['downgrade_credit'] = 'downgrade_credit'
  @_hash['archived_at'] = 'archived_at'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['price_point_handle'] = 'price_point_handle'
  @_hash['price_point_type'] = 'price_point_type'
  @_hash['price_point_name'] = 'price_point_name'
  @_hash['product_family_id'] = 'product_family_id'
  @_hash['product_family_handle'] = 'product_family_handle'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['use_site_exchange_rate'] = 'use_site_exchange_rate'
  @_hash['description'] = 'description'
  @_hash['allow_fractional_quantities'] = 'allow_fractional_quantities'
  @_hash['subscription'] = 'subscription'
  @_hash['historic_usages'] = 'historic_usages'
  @_hash['display_on_hosted_page'] = 'display_on_hosted_page'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/advanced_billing/models/subscription_component.rb', line 269

def self.nullables
  %w[
    pricing_scheme
    component_handle
    upgrade_charge
    downgrade_credit
    archived_at
    price_point_id
    price_point_handle
    price_point_type
    price_point_name
    use_site_exchange_rate
    description
    interval_unit
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    id
    name
    kind
    unit_name
    enabled
    unit_balance
    currency
    allocated_quantity
    pricing_scheme
    component_id
    component_handle
    subscription_id
    recurring
    upgrade_charge
    downgrade_credit
    archived_at
    price_point_id
    price_point_handle
    price_point_type
    price_point_name
    product_family_id
    product_family_handle
    created_at
    updated_at
    use_site_exchange_rate
    description
    allow_fractional_quantities
    subscription
    historic_usages
    display_on_hosted_page
    interval
    interval_unit
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



472
473
474
475
476
477
478
# File 'lib/advanced_billing/models/subscription_component.rb', line 472

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_archived_atObject



458
459
460
# File 'lib/advanced_billing/models/subscription_component.rb', line 458

def to_custom_archived_at
  DateTimeHelper.to_rfc3339(archived_at)
end

#to_custom_created_atObject



462
463
464
# File 'lib/advanced_billing/models/subscription_component.rb', line 462

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



466
467
468
# File 'lib/advanced_billing/models/subscription_component.rb', line 466

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end