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

#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: {})
  @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

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

Instance Attribute Details

#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

#pricesArray[Price]

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

Returns:



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

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

#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

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.
  names.each_value { |k| hash.delete(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: hash)
end

.namesObject

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

.nullablesObject

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

.optionalsObject

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.

Parameters:



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