Class: AdvancedBilling::ComponentCustomPrice

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

Overview

Create or update custom pricing unique to the subscription. Used in place of ‘price_point_id`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(pricing_scheme = SKIP, prices = SKIP) ⇒ ComponentCustomPrice

Returns a new instance of ComponentCustomPrice.



42
43
44
45
# File 'lib/advanced_billing/models/component_custom_price.rb', line 42

def initialize(pricing_scheme = SKIP, prices = SKIP)
  @pricing_scheme = pricing_scheme unless pricing_scheme == SKIP
  @prices = prices unless prices == SKIP
end

Instance Attribute Details

#pricesArray[Price]

On/off components only need one price bracket starting at 1

Returns:



19
20
21
# File 'lib/advanced_billing/models/component_custom_price.rb', line 19

def prices
  @prices
end

#pricing_schemePricingScheme

Omit for On/Off components

Returns:



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

def pricing_scheme
  @pricing_scheme
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/advanced_billing/models/component_custom_price.rb', line 48

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  pricing_scheme = hash.key?('pricing_scheme') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:ComponentCustomPricePricingScheme), hash['pricing_scheme']
  ) : SKIP
  # 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 = SKIP unless hash.key?('prices')

  # Create object from extracted values.
  ComponentCustomPrice.new(pricing_scheme,
                           prices)
end

.namesObject

A mapping from model property names to API property names.



22
23
24
25
26
27
# File 'lib/advanced_billing/models/component_custom_price.rb', line 22

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['prices'] = 'prices'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



30
31
32
33
34
35
# File 'lib/advanced_billing/models/component_custom_price.rb', line 30

def self.optionals
  %w[
    pricing_scheme
    prices
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



73
74
75
76
77
78
79
# File 'lib/advanced_billing/models/component_custom_price.rb', line 73

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end