Class: ApiReference::MonetaryPercentageDiscountAdjustment

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

Overview

MonetaryPercentageDiscountAdjustment 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:, percentage_discount:, amount:, additional_properties: nil) ⇒ MonetaryPercentageDiscountAdjustment

Returns a new instance of MonetaryPercentageDiscountAdjustment.



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

def initialize(id:, is_invoice_level:, filters:, applies_to_price_ids:,
               reason:, replaces_adjustment_id:, percentage_discount:,
               amount:, 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 = 'percentage_discount'
  @percentage_discount = percentage_discount
  @amount = amount
  @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/monetary_percentage_discount_adjustment.rb', line 41

def adjustment_type
  @adjustment_type
end

#amountString

The value applied by an adjustment.

Returns:

  • (String)


50
51
52
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 50

def amount
  @amount
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/monetary_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/monetary_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/monetary_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/monetary_percentage_discount_adjustment.rb', line 19

def is_invoice_level
  @is_invoice_level
end

#percentage_discountFloat

The percentage (as a value between 0 and 1) by which to discount the price intervals this adjustment applies to in a given billing period.

Returns:

  • (Float)


46
47
48
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 46

def percentage_discount
  @percentage_discount
end

#reasonString

The reason for the adjustment.

Returns:

  • (String)


31
32
33
# File 'lib/api_reference/models/monetary_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/monetary_percentage_discount_adjustment.rb', line 36

def replaces_adjustment_id
  @replaces_adjustment_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



99
100
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
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 99

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
  percentage_discount =
    hash.key?('percentage_discount') ? hash['percentage_discount'] : nil
  amount = hash.key?('amount') ? hash['amount'] : 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.
  MonetaryPercentageDiscountAdjustment.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,
                                           percentage_discount: percentage_discount,
                                           amount: amount,
                                           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

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['percentage_discount'] = 'percentage_discount'
  @_hash['amount'] = 'amount'
  @_hash
end

.nullablesObject

An array for nullable fields



73
74
75
76
77
78
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 73

def self.nullables
  %w[
    reason
    replaces_adjustment_id
  ]
end

.optionalsObject

An array for optional fields



68
69
70
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 68

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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
188
189
190
191
192
193
194
195
196
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 146

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.percentage_discount,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.amount,
                              ->(val) { val.instance_of? String })
    )
  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['percentage_discount'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['amount'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



209
210
211
212
213
214
215
216
217
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 209

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}, percentage_discount:"\
  " #{@percentage_discount.inspect}, amount: #{@amount.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



199
200
201
202
203
204
205
206
# File 'lib/api_reference/models/monetary_percentage_discount_adjustment.rb', line 199

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},"\
  " percentage_discount: #{@percentage_discount}, amount: #{@amount}, additional_properties:"\
  " #{@additional_properties}>"
end