Class: AdvancedBilling::ScheduledRenewalComponentCustomPrice

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

Overview

Custom pricing for a component within a scheduled renewal.

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(pricing_scheme:, prices:, tax_included: SKIP, additional_properties: {}) ⇒ ScheduledRenewalComponentCustomPrice

Returns a new instance of ScheduledRenewalComponentCustomPrice.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 45

def initialize(pricing_scheme:, prices:, tax_included: 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
  @prices = prices
end

Instance Attribute Details

#pricesArray[Price]

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

Returns:



22
23
24
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 22

def prices
  @prices
end

#pricing_schemePricingScheme

Omit for On/Off components

Returns:



18
19
20
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 18

def pricing_scheme
  @pricing_scheme
end

#tax_includedTrueClass | FalseClass

Whether or not the price point includes tax

Returns:

  • (TrueClass | FalseClass)


14
15
16
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 14

def tax_included
  @tax_included
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 58

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  pricing_scheme =
    hash.key?('pricing_scheme') ? hash['pricing_scheme'] : nil
  # 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

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  ScheduledRenewalComponentCustomPrice.new(pricing_scheme: pricing_scheme,
                                           prices: prices,
                                           tax_included: tax_included,
                                           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['tax_included'] = 'tax_included'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['prices'] = 'prices'
  @_hash
end

.nullablesObject

An array for nullable fields



41
42
43
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 41

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
37
38
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 34

def self.optionals
  %w[
    tax_included
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 88

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.pricing_scheme,
                            ->(val) { PricingScheme.validate(val) }) and
        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['pricing_scheme'],
                          ->(val) { PricingScheme.validate(val) }) and
      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.



120
121
122
123
124
125
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 120

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} tax_included: #{@tax_included.inspect}, pricing_scheme:"\
  " #{@pricing_scheme.inspect}, prices: #{@prices.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



113
114
115
116
117
# File 'lib/advanced_billing/models/scheduled_renewal_component_custom_price.rb', line 113

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} tax_included: #{@tax_included}, pricing_scheme: #{@pricing_scheme}, prices:"\
  " #{@prices}, additional_properties: #{get_additional_properties}>"
end