Class: AdvancedBilling::ComponentCustomPrice
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- AdvancedBilling::ComponentCustomPrice
- 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
-
#interval ⇒ Integer
The numerical interval.
-
#interval_unit ⇒ IntervalUnit
A string representing the interval unit for this component price point, either month or day.
-
#prices ⇒ Array[Price]
On/off components only need one price bracket starting at 1.
-
#pricing_scheme ⇒ PricingScheme
Omit for On/Off components.
-
#tax_included ⇒ TrueClass | FalseClass
Whether or not the price point includes tax.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(prices:, tax_included: SKIP, pricing_scheme: SKIP, interval: SKIP, interval_unit: SKIP, additional_properties: {}) ⇒ ComponentCustomPrice
constructor
A new instance of ComponentCustomPrice.
Methods inherited from BaseModel
#check_for_conflict, #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, additional_properties: {}) ⇒ ComponentCustomPrice
Returns a new instance of ComponentCustomPrice.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 66 def initialize(prices:, tax_included: SKIP, pricing_scheme: 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 @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 @prices = prices end |
Instance Attribute Details
#interval ⇒ Integer
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.
26 27 28 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 26 def interval @interval end |
#interval_unit ⇒ IntervalUnit
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.
32 33 34 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 32 def interval_unit @interval_unit end |
#prices ⇒ Array[Price]
On/off components only need one price bracket starting at 1
36 37 38 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 36 def prices @prices end |
#pricing_scheme ⇒ PricingScheme
Omit for On/Off components
19 20 21 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 19 def pricing_scheme @pricing_scheme end |
#tax_included ⇒ TrueClass | FalseClass
Whether or not the price point includes tax
15 16 17 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 15 def tax_included @tax_included end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 82 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 # 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, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
39 40 41 42 43 44 45 46 47 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 39 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['prices'] = 'prices' @_hash end |
.nullables ⇒ Object
An array for nullable fields
60 61 62 63 64 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 60 def self.nullables %w[ interval_unit ] end |
.optionals ⇒ Object
An array for optional fields
50 51 52 53 54 55 56 57 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 50 def self.optionals %w[ tax_included pricing_scheme interval interval_unit ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/advanced_billing/models/component_custom_price.rb', line 116 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 |