Class: AdvancedBilling::CreatePrepaidUsageComponentPricePoint

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

Overview

CreatePrepaidUsageComponentPricePoint 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(name:, pricing_scheme:, prices:, overage_pricing:, handle: SKIP, use_site_exchange_rate: true, rollover_prepaid_remainder: SKIP, renew_prepaid_allocation: SKIP, expiration_interval: SKIP, expiration_interval_unit: SKIP, additional_properties: {}) ⇒ CreatePrepaidUsageComponentPricePoint

Returns a new instance of CreatePrepaidUsageComponentPricePoint.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 100

def initialize(name:, pricing_scheme:, prices:, overage_pricing:,
               handle: SKIP, use_site_exchange_rate: true,
               rollover_prepaid_remainder: SKIP,
               renew_prepaid_allocation: SKIP, expiration_interval: SKIP,
               expiration_interval_unit: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @name = name
  @handle = handle unless handle == SKIP
  @pricing_scheme = pricing_scheme
  @prices = prices
  @overage_pricing = overage_pricing
  @use_site_exchange_rate = use_site_exchange_rate unless use_site_exchange_rate == SKIP
  unless rollover_prepaid_remainder == SKIP
    @rollover_prepaid_remainder =
      rollover_prepaid_remainder
  end
  @renew_prepaid_allocation = renew_prepaid_allocation unless renew_prepaid_allocation == SKIP
  @expiration_interval = expiration_interval unless expiration_interval == SKIP
  @expiration_interval_unit = expiration_interval_unit unless expiration_interval_unit == SKIP
end

Instance Attribute Details

#expiration_intervalFloat

(only for prepaid usage components where rollover_prepaid_remainder is true) The number of ‘expiration_interval_unit`s after which rollover amounts should expire

Returns:

  • (Float)


57
58
59
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 57

def expiration_interval
  @expiration_interval
end

#expiration_interval_unitExpirationIntervalUnit

(only for prepaid usage components where rollover_prepaid_remainder is true) A string representing the expiration interval unit for this component, either month or day



63
64
65
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 63

def expiration_interval_unit
  @expiration_interval_unit
end

#handleString

TODO: Write general description for this method

Returns:

  • (String)


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

def handle
  @handle
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def name
  @name
end

#overage_pricingOveragePricing

The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.

Returns:



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

def overage_pricing
  @overage_pricing
end

#pricesArray[Price]

The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.

Returns:



30
31
32
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 30

def prices
  @prices
end

#pricing_schemePricingScheme

The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.

Returns:



24
25
26
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 24

def pricing_scheme
  @pricing_scheme
end

#renew_prepaid_allocationTrueClass | FalseClass

(only for prepaid usage components) Boolean which controls whether or not the allocated quantity should be renewed at the beginning of each period

Returns:

  • (TrueClass | FalseClass)


51
52
53
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 51

def renew_prepaid_allocation
  @renew_prepaid_allocation
end

#rollover_prepaid_remainderTrueClass | FalseClass

(only for prepaid usage components) Boolean which controls whether or not remaining units should be rolled over to the next period

Returns:

  • (TrueClass | FalseClass)


46
47
48
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 46

def rollover_prepaid_remainder
  @rollover_prepaid_remainder
end

#use_site_exchange_rateTrueClass | FalseClass

Whether to use the site level exchange rate or define your own prices for each currency if you have multiple currencies defined on the site.

Returns:

  • (TrueClass | FalseClass)


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

def use_site_exchange_rate
  @use_site_exchange_rate
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 126

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  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')
  overage_pricing = OveragePricing.from_hash(hash['overage_pricing']) if
    hash['overage_pricing']
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  use_site_exchange_rate = hash['use_site_exchange_rate'] ||= true
  rollover_prepaid_remainder =
    hash.key?('rollover_prepaid_remainder') ? hash['rollover_prepaid_remainder'] : SKIP
  renew_prepaid_allocation =
    hash.key?('renew_prepaid_allocation') ? hash['renew_prepaid_allocation'] : SKIP
  expiration_interval =
    hash.key?('expiration_interval') ? hash['expiration_interval'] : SKIP
  expiration_interval_unit =
    hash.key?('expiration_interval_unit') ? hash['expiration_interval_unit'] : SKIP

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

  # Create object from extracted values.
  CreatePrepaidUsageComponentPricePoint.new(name: name,
                                            pricing_scheme: pricing_scheme,
                                            prices: prices,
                                            overage_pricing: overage_pricing,
                                            handle: handle,
                                            use_site_exchange_rate: use_site_exchange_rate,
                                            rollover_prepaid_remainder: rollover_prepaid_remainder,
                                            renew_prepaid_allocation: renew_prepaid_allocation,
                                            expiration_interval: expiration_interval,
                                            expiration_interval_unit: expiration_interval_unit,
                                            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 66

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['prices'] = 'prices'
  @_hash['overage_pricing'] = 'overage_pricing'
  @_hash['use_site_exchange_rate'] = 'use_site_exchange_rate'
  @_hash['rollover_prepaid_remainder'] = 'rollover_prepaid_remainder'
  @_hash['renew_prepaid_allocation'] = 'renew_prepaid_allocation'
  @_hash['expiration_interval'] = 'expiration_interval'
  @_hash['expiration_interval_unit'] = 'expiration_interval_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



94
95
96
97
98
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 94

def self.nullables
  %w[
    expiration_interval_unit
  ]
end

.optionalsObject

An array for optional fields



82
83
84
85
86
87
88
89
90
91
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 82

def self.optionals
  %w[
    handle
    use_site_exchange_rate
    rollover_prepaid_remainder
    renew_prepaid_allocation
    expiration_interval
    expiration_interval_unit
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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
# File 'lib/advanced_billing/models/create_prepaid_usage_component_price_point.rb', line 175

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.name,
                            ->(val) { val.instance_of? String }) and
        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) and
        APIHelper.valid_type?(value.overage_pricing,
                              ->(val) { OveragePricing.validate(val) },
                              is_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['name'],
                          ->(val) { val.instance_of? String }) and
      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) and
      APIHelper.valid_type?(value['overage_pricing'],
                            ->(val) { OveragePricing.validate(val) },
                            is_model_hash: true)
  )
end