Class: AdvancedBilling::ComponentCustomPrice

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

Overview

Create or update custom pricing unique to the subscription. Used in place of price_point_id.

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(prices:, tax_included: SKIP, pricing_scheme: SKIP, interval: SKIP, interval_unit: SKIP, list_price_point_id: SKIP, use_default_list_price: SKIP, renew_prepaid_allocation: SKIP, rollover_prepaid_remainder: SKIP, expiration_interval: SKIP, expiration_interval_unit: SKIP, additional_properties: {}) ⇒ ComponentCustomPrice

Returns a new instance of ComponentCustomPrice.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/advanced_billing/models/component_custom_price.rb', line 111

def initialize(prices:, tax_included: SKIP, pricing_scheme: SKIP,
               interval: SKIP, interval_unit: SKIP,
               list_price_point_id: SKIP, use_default_list_price: SKIP,
               renew_prepaid_allocation: SKIP,
               rollover_prepaid_remainder: SKIP, expiration_interval: SKIP,
               expiration_interval_unit: SKIP, additional_properties: {})
  # Add additional model properties to the instance.

  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @tax_included = tax_included unless tax_included == SKIP
  @pricing_scheme = pricing_scheme unless pricing_scheme == SKIP
  @interval = interval unless interval == SKIP
  @interval_unit = interval_unit unless interval_unit == SKIP
  @list_price_point_id = list_price_point_id unless list_price_point_id == SKIP
  @use_default_list_price = use_default_list_price unless use_default_list_price == SKIP
  @prices = prices
  @renew_prepaid_allocation = renew_prepaid_allocation unless renew_prepaid_allocation == SKIP
  unless rollover_prepaid_remainder == SKIP
    @rollover_prepaid_remainder =
      rollover_prepaid_remainder
  end
  @expiration_interval = expiration_interval unless expiration_interval == SKIP
  @expiration_interval_unit = expiration_interval_unit unless expiration_interval_unit == SKIP
end

Instance Attribute Details

#expiration_intervalInteger

Applicable only when rollover is enabled. Number of ‘expiration_interval_unit`s after which rollover amounts expire.

Returns:

  • (Integer)


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

def expiration_interval
  @expiration_interval
end

#expiration_interval_unitExpirationIntervalUnit

Applicable only when rollover is enabled. Interval unit for rollover expiration (month or day).



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

def expiration_interval_unit
  @expiration_interval_unit
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)


26
27
28
# File 'lib/advanced_billing/models/component_custom_price.rb', line 26

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:



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

def interval_unit
  @interval_unit
end

#list_price_point_idInteger

Optional id of the price point to use for list price calculations when overriding the customer price.

Returns:

  • (Integer)


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

def list_price_point_id
  @list_price_point_id
end

#pricesArray[Price]

On/off components only need one price bracket starting at 1.

Returns:



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

def prices
  @prices
end

#pricing_schemePricingScheme

Omit for On/Off components

Returns:



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

def pricing_scheme
  @pricing_scheme
end

#renew_prepaid_allocationTrueClass | FalseClass

Applicable only to prepaid usage components. Controls whether the allocated quantity renews each period.

Returns:

  • (TrueClass | FalseClass)


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

def renew_prepaid_allocation
  @renew_prepaid_allocation
end

#rollover_prepaid_remainderTrueClass | FalseClass

Applicable only to prepaid usage components. Controls whether remaining units roll over to the next period.

Returns:

  • (TrueClass | FalseClass)


56
57
58
# File 'lib/advanced_billing/models/component_custom_price.rb', line 56

def rollover_prepaid_remainder
  @rollover_prepaid_remainder
end

#tax_includedTrueClass | FalseClass

Whether or not the price point includes tax

Returns:

  • (TrueClass | FalseClass)


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

def tax_included
  @tax_included
end

#use_default_list_priceTrueClass | FalseClass

When true, list price calculations will continue to use the default price point even when a custom_price is supplied.

Returns:

  • (TrueClass | FalseClass)


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

def use_default_list_price
  @use_default_list_price
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



139
140
141
142
143
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
181
182
183
184
185
186
187
# File 'lib/advanced_billing/models/component_custom_price.rb', line 139

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  # Parameter is an array, so we need to iterate through it

  prices = nil
  unless hash['prices'].nil?
    prices = []
    hash['prices'].each do |structure|
      prices << (Price.from_hash(structure) if structure)
    end
  end

  prices = nil unless hash.key?('prices')
  tax_included = hash.key?('tax_included') ? hash['tax_included'] : SKIP
  pricing_scheme =
    hash.key?('pricing_scheme') ? hash['pricing_scheme'] : SKIP
  interval = hash.key?('interval') ? hash['interval'] : SKIP
  interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : SKIP
  list_price_point_id =
    hash.key?('list_price_point_id') ? hash['list_price_point_id'] : SKIP
  use_default_list_price =
    hash.key?('use_default_list_price') ? hash['use_default_list_price'] : SKIP
  renew_prepaid_allocation =
    hash.key?('renew_prepaid_allocation') ? hash['renew_prepaid_allocation'] : SKIP
  rollover_prepaid_remainder =
    hash.key?('rollover_prepaid_remainder') ? hash['rollover_prepaid_remainder'] : SKIP
  expiration_interval =
    hash.key?('expiration_interval') ? hash['expiration_interval'] : SKIP
  expiration_interval_unit =
    hash.key?('expiration_interval_unit') ? hash['expiration_interval_unit'] : SKIP

  # Clean out expected properties from Hash.

  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.

  ComponentCustomPrice.new(prices: prices,
                           tax_included: tax_included,
                           pricing_scheme: pricing_scheme,
                           interval: interval,
                           interval_unit: interval_unit,
                           list_price_point_id: list_price_point_id,
                           use_default_list_price: use_default_list_price,
                           renew_prepaid_allocation: renew_prepaid_allocation,
                           rollover_prepaid_remainder: rollover_prepaid_remainder,
                           expiration_interval: expiration_interval,
                           expiration_interval_unit: expiration_interval_unit,
                           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/advanced_billing/models/component_custom_price.rb', line 69

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['tax_included'] = 'tax_included'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash['list_price_point_id'] = 'list_price_point_id'
  @_hash['use_default_list_price'] = 'use_default_list_price'
  @_hash['prices'] = 'prices'
  @_hash['renew_prepaid_allocation'] = 'renew_prepaid_allocation'
  @_hash['rollover_prepaid_remainder'] = 'rollover_prepaid_remainder'
  @_hash['expiration_interval'] = 'expiration_interval'
  @_hash['expiration_interval_unit'] = 'expiration_interval_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



102
103
104
105
106
107
108
109
# File 'lib/advanced_billing/models/component_custom_price.rb', line 102

def self.nullables
  %w[
    interval_unit
    list_price_point_id
    expiration_interval
    expiration_interval_unit
  ]
end

.optionalsObject

An array for optional fields



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/advanced_billing/models/component_custom_price.rb', line 86

def self.optionals
  %w[
    tax_included
    pricing_scheme
    interval
    interval_unit
    list_price_point_id
    use_default_list_price
    renew_prepaid_allocation
    rollover_prepaid_remainder
    expiration_interval
    expiration_interval_unit
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/advanced_billing/models/component_custom_price.rb', line 191

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.prices,
                                 ->(val) { Price.validate(val) },
                                 is_model_hash: true,
                                 is_inner_model_hash: true)
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['prices'],
                        ->(val) { Price.validate(val) },
                        is_model_hash: true,
                        is_inner_model_hash: true)
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/advanced_billing/models/component_custom_price.rb', line 220

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} tax_included: #{@tax_included.inspect}, pricing_scheme:"\
  " #{@pricing_scheme.inspect}, interval: #{@interval.inspect}, interval_unit:"\
  " #{@interval_unit.inspect}, list_price_point_id: #{@list_price_point_id.inspect},"\
  " use_default_list_price: #{@use_default_list_price.inspect}, prices: #{@prices.inspect},"\
  " renew_prepaid_allocation: #{@renew_prepaid_allocation.inspect},"\
  " rollover_prepaid_remainder: #{@rollover_prepaid_remainder.inspect}, expiration_interval:"\
  " #{@expiration_interval.inspect}, expiration_interval_unit:"\
  " #{@expiration_interval_unit.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



208
209
210
211
212
213
214
215
216
217
# File 'lib/advanced_billing/models/component_custom_price.rb', line 208

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} tax_included: #{@tax_included}, pricing_scheme: #{@pricing_scheme},"\
  " interval: #{@interval}, interval_unit: #{@interval_unit}, list_price_point_id:"\
  " #{@list_price_point_id}, use_default_list_price: #{@use_default_list_price}, prices:"\
  " #{@prices}, renew_prepaid_allocation: #{@renew_prepaid_allocation},"\
  " rollover_prepaid_remainder: #{@rollover_prepaid_remainder}, expiration_interval:"\
  " #{@expiration_interval}, expiration_interval_unit: #{@expiration_interval_unit},"\
  " additional_properties: #{get_additional_properties}>"
end