Class: AdvancedBilling::OnOffComponent

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

Overview

OnOffComponent 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(name:, unit_price:, description: SKIP, handle: SKIP, taxable: SKIP, upgrade_charge: SKIP, downgrade_credit: SKIP, price_points: SKIP, tax_code: SKIP, hide_date_range_on_invoice: SKIP, display_on_hosted_page: SKIP, allow_fractional_quantities: SKIP, public_signup_page_ids: SKIP, interval: SKIP, interval_unit: SKIP, additional_properties: {}) ⇒ OnOffComponent



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

def initialize(name:, unit_price:, description: SKIP, handle: SKIP,
               taxable: SKIP, upgrade_charge: SKIP, downgrade_credit: SKIP,
               price_points: SKIP, tax_code: SKIP,
               hide_date_range_on_invoice: SKIP,
               display_on_hosted_page: SKIP,
               allow_fractional_quantities: SKIP,
               public_signup_page_ids: 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

  @name = name
  @description = description unless description == SKIP
  @handle = handle unless handle == SKIP
  @taxable = taxable unless taxable == SKIP
  @upgrade_charge = upgrade_charge unless upgrade_charge == SKIP
  @downgrade_credit = downgrade_credit unless downgrade_credit == SKIP
  @price_points = price_points unless price_points == SKIP
  @unit_price = unit_price
  @tax_code = tax_code unless tax_code == SKIP
  unless hide_date_range_on_invoice == SKIP
    @hide_date_range_on_invoice =
      hide_date_range_on_invoice
  end
  @display_on_hosted_page = display_on_hosted_page unless display_on_hosted_page == SKIP
  unless allow_fractional_quantities == SKIP
    @allow_fractional_quantities =
      allow_fractional_quantities
  end
  @public_signup_page_ids =  unless  == SKIP
  @interval = interval unless interval == SKIP
  @interval_unit = interval_unit unless interval_unit == SKIP
end

Instance Attribute Details

#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.



79
80
81
# File 'lib/advanced_billing/models/on_off_component.rb', line 79

def allow_fractional_quantities
  @allow_fractional_quantities
end

#descriptionString

A description for the component that will be displayed to the user on the hosted signup page.



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

def description
  @description
end

#display_on_hosted_pageTrueClass | FalseClass

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



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

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`.



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

def downgrade_credit
  @downgrade_credit
end

#handleString

A unique identifier for your use that can be used to retrieve this component is subsequent requests. Must start with a letter or number and may only contain lowercase letters, numbers, or the characters ‘.’, ‘:’, ‘-’, or ‘_’.



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

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.



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

def hide_date_range_on_invoice
  @hide_date_range_on_invoice
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.



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

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.



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

def interval_unit
  @interval_unit
end

#nameString

A name for this component that is suitable for showing customers and displaying on billing statements, ie. “Minutes”.



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

def name
  @name
end

#price_pointsArray[ComponentPricePointItem]

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`.



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

def price_points
  @price_points
end

#public_signup_page_idsArray[Integer]

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



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

def 
  @public_signup_page_ids
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.



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

def tax_code
  @tax_code
end

#taxableTrueClass | FalseClass

Boolean flag describing whether a component is taxable or not.



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

def taxable
  @taxable
end

#unit_priceObject

This is the amount that the customer will be charged when they turn the component on for the subscription. The price can contain up to 8 decimal places. i.e. 1.00 or 0.0012 or 0.00000065



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

def unit_price
  @unit_price
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`.



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

def upgrade_charge
  @upgrade_charge
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/advanced_billing/models/on_off_component.rb', line 186

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  unit_price = hash.key?('unit_price') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:OnOffComponentUnitPrice), hash['unit_price']
  ) : nil
  description = hash.key?('description') ? hash['description'] : SKIP
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  taxable = hash.key?('taxable') ? hash['taxable'] : SKIP
  upgrade_charge =
    hash.key?('upgrade_charge') ? hash['upgrade_charge'] : SKIP
  downgrade_credit =
    hash.key?('downgrade_credit') ? hash['downgrade_credit'] : SKIP
  # Parameter is an array, so we need to iterate through it
  price_points = nil
  unless hash['price_points'].nil?
    price_points = []
    hash['price_points'].each do |structure|
      price_points << (ComponentPricePointItem.from_hash(structure) if structure)
    end
  end

  price_points = SKIP unless hash.key?('price_points')
  tax_code = hash.key?('tax_code') ? hash['tax_code'] : SKIP
  hide_date_range_on_invoice =
    hash.key?('hide_date_range_on_invoice') ? hash['hide_date_range_on_invoice'] : SKIP
  display_on_hosted_page =
    hash.key?('display_on_hosted_page') ? hash['display_on_hosted_page'] : SKIP
  allow_fractional_quantities =
    hash.key?('allow_fractional_quantities') ? hash['allow_fractional_quantities'] : SKIP
   =
    hash.key?('public_signup_page_ids') ? hash['public_signup_page_ids'] : 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.
  OnOffComponent.new(name: name,
                     unit_price: unit_price,
                     description: description,
                     handle: handle,
                     taxable: taxable,
                     upgrade_charge: upgrade_charge,
                     downgrade_credit: downgrade_credit,
                     price_points: price_points,
                     tax_code: tax_code,
                     hide_date_range_on_invoice: hide_date_range_on_invoice,
                     display_on_hosted_page: display_on_hosted_page,
                     allow_fractional_quantities: allow_fractional_quantities,
                     public_signup_page_ids: ,
                     interval: interval,
                     interval_unit: interval_unit,
                     additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/advanced_billing/models/on_off_component.rb', line 101

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['description'] = 'description'
  @_hash['handle'] = 'handle'
  @_hash['taxable'] = 'taxable'
  @_hash['upgrade_charge'] = 'upgrade_charge'
  @_hash['downgrade_credit'] = 'downgrade_credit'
  @_hash['price_points'] = 'price_points'
  @_hash['unit_price'] = 'unit_price'
  @_hash['tax_code'] = 'tax_code'
  @_hash['hide_date_range_on_invoice'] = 'hide_date_range_on_invoice'
  @_hash['display_on_hosted_page'] = 'display_on_hosted_page'
  @_hash['allow_fractional_quantities'] = 'allow_fractional_quantities'
  @_hash['public_signup_page_ids'] = 'public_signup_page_ids'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



141
142
143
144
145
146
147
# File 'lib/advanced_billing/models/on_off_component.rb', line 141

def self.nullables
  %w[
    upgrade_charge
    downgrade_credit
    interval_unit
  ]
end

.optionalsObject

An array for optional fields



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/advanced_billing/models/on_off_component.rb', line 122

def self.optionals
  %w[
    description
    handle
    taxable
    upgrade_charge
    downgrade_credit
    price_points
    tax_code
    hide_date_range_on_invoice
    display_on_hosted_page
    allow_fractional_quantities
    public_signup_page_ids
    interval
    interval_unit
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/advanced_billing/models/on_off_component.rb', line 247

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.name,
                            ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:OnOffComponentUnitPrice)
                       .validate(value.unit_price)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['name'],
                          ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:OnOffComponentUnitPrice)
                     .validate(value['unit_price'])
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/advanced_billing/models/on_off_component.rb', line 280

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name.inspect}, description: #{@description.inspect}, handle:"\
  " #{@handle.inspect}, taxable: #{@taxable.inspect}, upgrade_charge:"\
  " #{@upgrade_charge.inspect}, downgrade_credit: #{@downgrade_credit.inspect}, price_points:"\
  " #{@price_points.inspect}, unit_price: #{@unit_price.inspect}, tax_code:"\
  " #{@tax_code.inspect}, hide_date_range_on_invoice: #{@hide_date_range_on_invoice.inspect},"\
  " display_on_hosted_page: #{@display_on_hosted_page.inspect}, allow_fractional_quantities:"\
  " #{@allow_fractional_quantities.inspect}, public_signup_page_ids:"\
  " #{@public_signup_page_ids.inspect}, interval: #{@interval.inspect}, interval_unit:"\
  " #{@interval_unit.inspect}, additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



268
269
270
271
272
273
274
275
276
277
# File 'lib/advanced_billing/models/on_off_component.rb', line 268

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, description: #{@description}, handle: #{@handle}, taxable:"\
  " #{@taxable}, upgrade_charge: #{@upgrade_charge}, downgrade_credit: #{@downgrade_credit},"\
  " price_points: #{@price_points}, unit_price: #{@unit_price}, tax_code: #{@tax_code},"\
  " hide_date_range_on_invoice: #{@hide_date_range_on_invoice}, display_on_hosted_page:"\
  " #{@display_on_hosted_page}, allow_fractional_quantities: #{@allow_fractional_quantities},"\
  " public_signup_page_ids: #{@public_signup_page_ids}, interval: #{@interval}, interval_unit:"\
  " #{@interval_unit}, additional_properties: #{get_additional_properties}>"
end