Class: AdvancedBilling::ComponentPricePoint

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

Overview

ComponentPricePoint Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id: SKIP, type: SKIP, default: SKIP, name: SKIP, pricing_scheme: SKIP, component_id: SKIP, handle: SKIP, archived_at: SKIP, created_at: SKIP, updated_at: SKIP, prices: SKIP, use_site_exchange_rate: SKIP, subscription_id: SKIP, tax_included: SKIP, interval: SKIP, interval_unit: SKIP, currency_prices: SKIP, additional_properties: {}) ⇒ ComponentPricePoint

Returns a new instance of ComponentPricePoint.



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

def initialize(id: SKIP, type: SKIP, default: SKIP, name: SKIP,
               pricing_scheme: SKIP, component_id: SKIP, handle: SKIP,
               archived_at: SKIP, created_at: SKIP, updated_at: SKIP,
               prices: SKIP, use_site_exchange_rate: SKIP,
               subscription_id: SKIP, tax_included: SKIP, interval: SKIP,
               interval_unit: SKIP, currency_prices: SKIP,
               additional_properties: {})
  @id = id unless id == SKIP
  @type = type unless type == SKIP
  @default = default unless default == SKIP
  @name = name unless name == SKIP
  @pricing_scheme = pricing_scheme unless pricing_scheme == SKIP
  @component_id = component_id unless component_id == SKIP
  @handle = handle unless handle == SKIP
  @archived_at = archived_at unless archived_at == SKIP
  @created_at = created_at unless created_at == SKIP
  @updated_at = updated_at unless updated_at == SKIP
  @prices = prices unless prices == SKIP
  @use_site_exchange_rate = use_site_exchange_rate unless use_site_exchange_rate == SKIP
  @subscription_id = subscription_id unless subscription_id == SKIP
  @tax_included = tax_included unless tax_included == SKIP
  @interval = interval unless interval == SKIP
  @interval_unit = interval_unit unless interval_unit == SKIP
  @currency_prices = currency_prices unless currency_prices == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#archived_atDateTime

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

Returns:

  • (DateTime)


56
57
58
# File 'lib/advanced_billing/models/component_price_point.rb', line 56

def archived_at
  @archived_at
end

#component_idInteger

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

Returns:

  • (Integer)


44
45
46
# File 'lib/advanced_billing/models/component_price_point.rb', line 44

def component_id
  @component_id
end

#created_atDateTime

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

Returns:

  • (DateTime)


62
63
64
# File 'lib/advanced_billing/models/component_price_point.rb', line 62

def created_at
  @created_at
end

#currency_pricesArray[ComponentCurrencyPrice]

An array of currency pricing data is available when multiple currencies are defined for the site. It varies based on the use_site_exchange_rate setting for the price point. This parameter is present only in the response of read endpoints, after including the appropriate query parameter.

Returns:



111
112
113
# File 'lib/advanced_billing/models/component_price_point.rb', line 111

def currency_prices
  @currency_prices
end

#defaultTrueClass | FalseClass

Note: Refer to type attribute instead

Returns:

  • (TrueClass | FalseClass)


28
29
30
# File 'lib/advanced_billing/models/component_price_point.rb', line 28

def default
  @default
end

#handleString

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

Returns:

  • (String)


50
51
52
# File 'lib/advanced_billing/models/component_price_point.rb', line 50

def handle
  @handle
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


15
16
17
# File 'lib/advanced_billing/models/component_price_point.rb', line 15

def id
  @id
end

#intervalInteger

The numerical interval. i.e. an interval of ‘30’ coupled with an interval_unit of day would mean this component price point would renew every 30 days. This property is only available for sites with Multifrequency enabled.

Returns:

  • (Integer)


97
98
99
# File 'lib/advanced_billing/models/component_price_point.rb', line 97

def interval
  @interval
end

#interval_unitIntervalUnit

A string representing the interval unit for this component price point, either month or day. This property is only available for sites with Multifrequency enabled.

Returns:



103
104
105
# File 'lib/advanced_billing/models/component_price_point.rb', line 103

def interval_unit
  @interval_unit
end

#nameString

Note: Refer to type attribute instead

Returns:

  • (String)


32
33
34
# File 'lib/advanced_billing/models/component_price_point.rb', line 32

def name
  @name
end

#pricesArray[ComponentPrice]

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

Returns:



74
75
76
# File 'lib/advanced_billing/models/component_price_point.rb', line 74

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:



38
39
40
# File 'lib/advanced_billing/models/component_price_point.rb', line 38

def pricing_scheme
  @pricing_scheme
end

#subscription_idInteger

(only used for Custom Pricing - ie. when the price point’s type is ‘custom`) The id of the subscription that the custom price point is for.

Returns:

  • (Integer)


85
86
87
# File 'lib/advanced_billing/models/component_price_point.rb', line 85

def subscription_id
  @subscription_id
end

#tax_includedTrueClass | FalseClass

(only used for Custom Pricing - ie. when the price point’s type is ‘custom`) The id of the subscription that the custom price point is for.

Returns:

  • (TrueClass | FalseClass)


90
91
92
# File 'lib/advanced_billing/models/component_price_point.rb', line 90

def tax_included
  @tax_included
end

#typePricePointType

Price point type. We expose the following types:

  1. default: a price point that is marked as a default price for a

certain product.

  1. custom: a custom price point.

  2. catalog: a price point that is not marked as a default price

for a certain product and is not a custom one.

Returns:



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

def type
  @type
end

#updated_atDateTime

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

Returns:

  • (DateTime)


68
69
70
# File 'lib/advanced_billing/models/component_price_point.rb', line 68

def updated_at
  @updated_at
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. Defaults to true during creation.

Returns:

  • (TrueClass | FalseClass)


80
81
82
# File 'lib/advanced_billing/models/component_price_point.rb', line 80

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.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/advanced_billing/models/component_price_point.rb', line 201

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  type = hash.key?('type') ? hash['type'] : SKIP
  default = hash.key?('default') ? hash['default'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  pricing_scheme =
    hash.key?('pricing_scheme') ? hash['pricing_scheme'] : SKIP
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  archived_at = if hash.key?('archived_at')
                  (DateTimeHelper.from_rfc3339(hash['archived_at']) if hash['archived_at'])
                else
                  SKIP
                end
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               else
                 SKIP
               end
  # Parameter is an array, so we need to iterate through it
  prices = nil
  unless hash['prices'].nil?
    prices = []
    hash['prices'].each do |structure|
      prices << (ComponentPrice.from_hash(structure) if structure)
    end
  end

  prices = SKIP unless hash.key?('prices')
  use_site_exchange_rate =
    hash.key?('use_site_exchange_rate') ? hash['use_site_exchange_rate'] : SKIP
  subscription_id =
    hash.key?('subscription_id') ? hash['subscription_id'] : SKIP
  tax_included = hash.key?('tax_included') ? hash['tax_included'] : SKIP
  interval = hash.key?('interval') ? hash['interval'] : SKIP
  interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : SKIP
  # Parameter is an array, so we need to iterate through it
  currency_prices = nil
  unless hash['currency_prices'].nil?
    currency_prices = []
    hash['currency_prices'].each do |structure|
      currency_prices << (ComponentCurrencyPrice.from_hash(structure) if structure)
    end
  end

  currency_prices = SKIP unless hash.key?('currency_prices')

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  ComponentPricePoint.new(id: id,
                          type: type,
                          default: default,
                          name: name,
                          pricing_scheme: pricing_scheme,
                          component_id: component_id,
                          handle: handle,
                          archived_at: archived_at,
                          created_at: created_at,
                          updated_at: updated_at,
                          prices: prices,
                          use_site_exchange_rate: use_site_exchange_rate,
                          subscription_id: subscription_id,
                          tax_included: tax_included,
                          interval: interval,
                          interval_unit: interval_unit,
                          currency_prices: currency_prices,
                          additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/advanced_billing/models/component_price_point.rb', line 114

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['type'] = 'type'
  @_hash['default'] = 'default'
  @_hash['name'] = 'name'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['component_id'] = 'component_id'
  @_hash['handle'] = 'handle'
  @_hash['archived_at'] = 'archived_at'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['prices'] = 'prices'
  @_hash['use_site_exchange_rate'] = 'use_site_exchange_rate'
  @_hash['subscription_id'] = 'subscription_id'
  @_hash['tax_included'] = 'tax_included'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash['currency_prices'] = 'currency_prices'
  @_hash
end

.nullablesObject

An array for nullable fields



160
161
162
163
164
165
166
167
# File 'lib/advanced_billing/models/component_price_point.rb', line 160

def self.nullables
  %w[
    handle
    archived_at
    interval
    interval_unit
  ]
end

.optionalsObject

An array for optional fields



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/advanced_billing/models/component_price_point.rb', line 137

def self.optionals
  %w[
    id
    type
    default
    name
    pricing_scheme
    component_id
    handle
    archived_at
    created_at
    updated_at
    prices
    use_site_exchange_rate
    subscription_id
    tax_included
    interval
    interval_unit
    currency_prices
  ]
end

Instance Method Details

#to_custom_archived_atObject



280
281
282
# File 'lib/advanced_billing/models/component_price_point.rb', line 280

def to_custom_archived_at
  DateTimeHelper.to_rfc3339(archived_at)
end

#to_custom_created_atObject



284
285
286
# File 'lib/advanced_billing/models/component_price_point.rb', line 284

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



288
289
290
# File 'lib/advanced_billing/models/component_price_point.rb', line 288

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end