Class: AdvancedBilling::SubscriptionGroupComponentCustomPrice

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

Overview

Used in place of ‘price_point_id` to define a custom price point unique to the subscription. You still need to provide `component_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, overage_pricing: SKIP, additional_properties: {}) ⇒ SubscriptionGroupComponentCustomPrice

Returns a new instance of SubscriptionGroupComponentCustomPrice.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 54

def initialize(pricing_scheme: SKIP, prices: SKIP, overage_pricing: SKIP,
               additional_properties: {})
  @pricing_scheme = pricing_scheme unless pricing_scheme == SKIP
  @prices = prices unless prices == SKIP
  @overage_pricing = overage_pricing unless overage_pricing == SKIP

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

Instance Attribute Details

#overage_pricingArray[ComponentCustomPrice]

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

Returns:



29
30
31
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 29

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:



23
24
25
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 23

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:



17
18
19
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 17

def pricing_scheme
  @pricing_scheme
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 67

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  pricing_scheme =
    hash.key?('pricing_scheme') ? 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')
  # Parameter is an array, so we need to iterate through it
  overage_pricing = nil
  unless hash['overage_pricing'].nil?
    overage_pricing = []
    hash['overage_pricing'].each do |structure|
      overage_pricing << (ComponentCustomPrice.from_hash(structure) if structure)
    end
  end

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

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

  # Create object from extracted values.
  SubscriptionGroupComponentCustomPrice.new(pricing_scheme: pricing_scheme,
                                            prices: prices,
                                            overage_pricing: overage_pricing,
                                            additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



32
33
34
35
36
37
38
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 32

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

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



41
42
43
44
45
46
47
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 41

def self.optionals
  %w[
    pricing_scheme
    prices
    overage_pricing
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



106
107
108
109
110
111
112
# File 'lib/advanced_billing/models/subscription_group_component_custom_price.rb', line 106

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

  return false unless value.instance_of? Hash

  true
end