Class: ApiReference::PlanPhaseTieredPercentageDiscountAdjustment

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb

Overview

PlanPhaseTieredPercentageDiscountAdjustment Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id:, is_invoice_level:, filters:, applies_to_price_ids:, reason:, replaces_adjustment_id:, tiers:, plan_phase_order:, additional_properties: nil) ⇒ PlanPhaseTieredPercentageDiscountAdjustment

Returns a new instance of PlanPhaseTieredPercentageDiscountAdjustment.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 82

def initialize(id:, is_invoice_level:, filters:, applies_to_price_ids:,
               reason:, replaces_adjustment_id:, tiers:, plan_phase_order:,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @id = id
  @is_invoice_level = is_invoice_level
  @filters = filters
  @applies_to_price_ids = applies_to_price_ids
  @reason = reason
  @replaces_adjustment_id = replaces_adjustment_id
  @adjustment_type = 'tiered_percentage_discount'
  @tiers = tiers
  @plan_phase_order = plan_phase_order
  @additional_properties = additional_properties
end

Instance Attribute Details

#adjustment_typeString (readonly)

The adjustment id this adjustment replaces. This adjustment will take the place of the replaced adjustment in plan version migrations.

Returns:

  • (String)


41
42
43
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 41

def adjustment_type
  @adjustment_type
end

#applies_to_price_idsArray[String]

The price IDs that this adjustment applies to.

Returns:

  • (Array[String])


27
28
29
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 27

def applies_to_price_ids
  @applies_to_price_ids
end

#filtersArray[PriceFilter]

The filters that determine which prices to apply this adjustment to.

Returns:



23
24
25
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 23

def filters
  @filters
end

#idString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 14

def id
  @id
end

#is_invoice_levelTrueClass | FalseClass

True for adjustments that apply to an entire invoice, false for adjustments that apply to only one price.

Returns:

  • (TrueClass | FalseClass)


19
20
21
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 19

def is_invoice_level
  @is_invoice_level
end

#plan_phase_orderInteger

The plan phase in which this adjustment is active.

Returns:

  • (Integer)


51
52
53
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 51

def plan_phase_order
  @plan_phase_order
end

#reasonString

The reason for the adjustment.

Returns:

  • (String)


31
32
33
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 31

def reason
  @reason
end

#replaces_adjustment_idString

The adjustment id this adjustment replaces. This adjustment will take the place of the replaced adjustment in plan version migrations.

Returns:

  • (String)


36
37
38
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 36

def replaces_adjustment_id
  @replaces_adjustment_id
end

#tiersArray[PercentageTier]

The ordered, contiguous bands of cumulative eligible spend, each discounted at its own percentage (progressive fill-a-tier), applied to the prices this adjustment covers in a given billing period.

Returns:



47
48
49
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 47

def tiers
  @tiers
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



101
102
103
104
105
106
107
108
109
110
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 101

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  is_invoice_level =
    hash.key?('is_invoice_level') ? hash['is_invoice_level'] : nil
  # Parameter is an array, so we need to iterate through it
  filters = nil
  unless hash['filters'].nil?
    filters = []
    hash['filters'].each do |structure|
      filters << (PriceFilter.from_hash(structure) if structure)
    end
  end

  filters = nil unless hash.key?('filters')
  applies_to_price_ids =
    hash.key?('applies_to_price_ids') ? hash['applies_to_price_ids'] : nil
  reason = hash.key?('reason') ? hash['reason'] : nil
  replaces_adjustment_id =
    hash.key?('replaces_adjustment_id') ? hash['replaces_adjustment_id'] : nil
  # Parameter is an array, so we need to iterate through it
  tiers = nil
  unless hash['tiers'].nil?
    tiers = []
    hash['tiers'].each do |structure|
      tiers << (PercentageTier.from_hash(structure) if structure)
    end
  end

  tiers = nil unless hash.key?('tiers')
  plan_phase_order =
    hash.key?('plan_phase_order') ? hash['plan_phase_order'] : nil

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  PlanPhaseTieredPercentageDiscountAdjustment.new(id: id,
                                                  is_invoice_level: is_invoice_level,
                                                  filters: filters,
                                                  applies_to_price_ids: applies_to_price_ids,
                                                  reason: reason,
                                                  replaces_adjustment_id: replaces_adjustment_id,
                                                  tiers: tiers,
                                                  plan_phase_order: plan_phase_order,
                                                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 54

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['is_invoice_level'] = 'is_invoice_level'
  @_hash['filters'] = 'filters'
  @_hash['applies_to_price_ids'] = 'applies_to_price_ids'
  @_hash['reason'] = 'reason'
  @_hash['replaces_adjustment_id'] = 'replaces_adjustment_id'
  @_hash['adjustment_type'] = 'adjustment_type'
  @_hash['tiers'] = 'tiers'
  @_hash['plan_phase_order'] = 'plan_phase_order'
  @_hash
end

.nullablesObject

An array for nullable fields



74
75
76
77
78
79
80
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 74

def self.nullables
  %w[
    reason
    replaces_adjustment_id
    plan_phase_order
  ]
end

.optionalsObject

An array for optional fields



69
70
71
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 69

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 157

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.is_invoice_level,
                              ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
        APIHelper.valid_type?(value.filters,
                              ->(val) { PriceFilter.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) and
        APIHelper.valid_type?(value.applies_to_price_ids,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.reason,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.replaces_adjustment_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.adjustment_type,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.tiers,
                              ->(val) { PercentageTier.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) and
        APIHelper.valid_type?(value.plan_phase_order,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['is_invoice_level'],
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
      APIHelper.valid_type?(value['filters'],
                            ->(val) { PriceFilter.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
      APIHelper.valid_type?(value['applies_to_price_ids'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['reason'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['replaces_adjustment_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['adjustment_type'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['tiers'],
                            ->(val) { PercentageTier.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
      APIHelper.valid_type?(value['plan_phase_order'],
                            ->(val) { val.instance_of? Integer })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



224
225
226
227
228
229
230
231
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 224

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, is_invoice_level: #{@is_invoice_level.inspect},"\
  " filters: #{@filters.inspect}, applies_to_price_ids: #{@applies_to_price_ids.inspect},"\
  " reason: #{@reason.inspect}, replaces_adjustment_id: #{@replaces_adjustment_id.inspect},"\
  " adjustment_type: #{@adjustment_type.inspect}, tiers: #{@tiers.inspect}, plan_phase_order:"\
  " #{@plan_phase_order.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



214
215
216
217
218
219
220
221
# File 'lib/api_reference/models/plan_phase_tiered_percentage_discount_adjustment.rb', line 214

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, is_invoice_level: #{@is_invoice_level}, filters: #{@filters},"\
  " applies_to_price_ids: #{@applies_to_price_ids}, reason: #{@reason},"\
  " replaces_adjustment_id: #{@replaces_adjustment_id}, adjustment_type: #{@adjustment_type},"\
  " tiers: #{@tiers}, plan_phase_order: #{@plan_phase_order}, additional_properties:"\
  " #{@additional_properties}>"
end