Class: ApiReference::NewAmountDiscount

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

Overview

NewAmountDiscount 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(amount_discount:, applies_to_price_ids: SKIP, applies_to_item_ids: SKIP, applies_to_all: SKIP, filters: SKIP, currency: SKIP, price_type: SKIP, is_invoice_level: true, additional_properties: nil) ⇒ NewAmountDiscount

Returns a new instance of NewAmountDiscount.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/api_reference/models/new_amount_discount.rb', line 94

def initialize(amount_discount:, applies_to_price_ids: SKIP,
               applies_to_item_ids: SKIP, applies_to_all: SKIP,
               filters: SKIP, currency: SKIP, price_type: SKIP,
               is_invoice_level: true, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @applies_to_price_ids = applies_to_price_ids unless applies_to_price_ids == SKIP
  @applies_to_item_ids = applies_to_item_ids unless applies_to_item_ids == SKIP
  @applies_to_all = applies_to_all unless applies_to_all == SKIP
  @filters = filters unless filters == SKIP
  @currency = currency unless currency == SKIP
  @price_type = price_type unless price_type == SKIP
  @is_invoice_level = is_invoice_level unless is_invoice_level == SKIP
  @adjustment_type = 'amount_discount'
  @amount_discount = amount_discount
  @additional_properties = additional_properties
end

Instance Attribute Details

#adjustment_typeString (readonly)

When false, this adjustment will be applied to a single price. Otherwise, it will be applied at the invoice level, possibly to multiple prices.

Returns:

  • (String)


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

def adjustment_type
  @adjustment_type
end

#amount_discountString

When false, this adjustment will be applied to a single price. Otherwise, it will be applied at the invoice level, possibly to multiple prices.

Returns:

  • (String)


52
53
54
# File 'lib/api_reference/models/new_amount_discount.rb', line 52

def amount_discount
  @amount_discount
end

#applies_to_allTrueClass | FalseClass

If set, the adjustment will apply to every price on the subscription.

Returns:

  • (TrueClass | FalseClass)


22
23
24
# File 'lib/api_reference/models/new_amount_discount.rb', line 22

def applies_to_all
  @applies_to_all
end

#applies_to_item_idsArray[String]

The set of item IDs to which this adjustment applies.

Returns:

  • (Array[String])


18
19
20
# File 'lib/api_reference/models/new_amount_discount.rb', line 18

def applies_to_item_ids
  @applies_to_item_ids
end

#applies_to_price_idsArray[String]

The set of price IDs to which this adjustment applies.

Returns:

  • (Array[String])


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

def applies_to_price_ids
  @applies_to_price_ids
end

#currencyString

If set, only prices in the specified currency will have the adjustment applied.

Returns:

  • (String)


32
33
34
# File 'lib/api_reference/models/new_amount_discount.rb', line 32

def currency
  @currency
end

#filtersArray[PriceFilter]

A list of filters that determine which prices this adjustment will apply to.

Returns:



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

def filters
  @filters
end

#is_invoice_levelTrueClass | FalseClass

When false, this adjustment will be applied to a single price. Otherwise, it will be applied at the invoice level, possibly to multiple prices.

Returns:

  • (TrueClass | FalseClass)


42
43
44
# File 'lib/api_reference/models/new_amount_discount.rb', line 42

def is_invoice_level
  @is_invoice_level
end

#price_typePriceType

If set, only prices of the specified type will have the adjustment applied.

Returns:



37
38
39
# File 'lib/api_reference/models/new_amount_discount.rb', line 37

def price_type
  @price_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
154
155
156
157
# File 'lib/api_reference/models/new_amount_discount.rb', line 114

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount_discount =
    hash.key?('amount_discount') ? hash['amount_discount'] : nil
  applies_to_price_ids =
    hash.key?('applies_to_price_ids') ? hash['applies_to_price_ids'] : SKIP
  applies_to_item_ids =
    hash.key?('applies_to_item_ids') ? hash['applies_to_item_ids'] : SKIP
  applies_to_all =
    hash.key?('applies_to_all') ? hash['applies_to_all'] : SKIP
  # 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 = SKIP unless hash.key?('filters')
  currency = hash.key?('currency') ? hash['currency'] : SKIP
  price_type = hash.key?('price_type') ? hash['price_type'] : SKIP
  is_invoice_level = hash['is_invoice_level'] ||= true

  # 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.
  NewAmountDiscount.new(amount_discount: amount_discount,
                        applies_to_price_ids: applies_to_price_ids,
                        applies_to_item_ids: applies_to_item_ids,
                        applies_to_all: applies_to_all,
                        filters: filters,
                        currency: currency,
                        price_type: price_type,
                        is_invoice_level: is_invoice_level,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['applies_to_price_ids'] = 'applies_to_price_ids'
  @_hash['applies_to_item_ids'] = 'applies_to_item_ids'
  @_hash['applies_to_all'] = 'applies_to_all'
  @_hash['filters'] = 'filters'
  @_hash['currency'] = 'currency'
  @_hash['price_type'] = 'price_type'
  @_hash['is_invoice_level'] = 'is_invoice_level'
  @_hash['adjustment_type'] = 'adjustment_type'
  @_hash['amount_discount'] = 'amount_discount'
  @_hash
end

.nullablesObject

An array for nullable fields



83
84
85
86
87
88
89
90
91
92
# File 'lib/api_reference/models/new_amount_discount.rb', line 83

def self.nullables
  %w[
    applies_to_price_ids
    applies_to_item_ids
    applies_to_all
    filters
    currency
    price_type
  ]
end

.optionalsObject

An array for optional fields



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/api_reference/models/new_amount_discount.rb', line 70

def self.optionals
  %w[
    applies_to_price_ids
    applies_to_item_ids
    applies_to_all
    filters
    currency
    price_type
    is_invoice_level
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/api_reference/models/new_amount_discount.rb', line 161

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.adjustment_type,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.amount_discount,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['adjustment_type'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['amount_discount'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



192
193
194
195
196
197
198
199
200
# File 'lib/api_reference/models/new_amount_discount.rb', line 192

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} applies_to_price_ids: #{@applies_to_price_ids.inspect},"\
  " applies_to_item_ids: #{@applies_to_item_ids.inspect}, applies_to_all:"\
  " #{@applies_to_all.inspect}, filters: #{@filters.inspect}, currency: #{@currency.inspect},"\
  " price_type: #{@price_type.inspect}, is_invoice_level: #{@is_invoice_level.inspect},"\
  " adjustment_type: #{@adjustment_type.inspect}, amount_discount:"\
  " #{@amount_discount.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



182
183
184
185
186
187
188
189
# File 'lib/api_reference/models/new_amount_discount.rb', line 182

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} applies_to_price_ids: #{@applies_to_price_ids}, applies_to_item_ids:"\
  " #{@applies_to_item_ids}, applies_to_all: #{@applies_to_all}, filters: #{@filters},"\
  " currency: #{@currency}, price_type: #{@price_type}, is_invoice_level:"\
  " #{@is_invoice_level}, adjustment_type: #{@adjustment_type}, amount_discount:"\
  " #{@amount_discount}, additional_properties: #{@additional_properties}>"
end