Class: AdvancedBilling::ScheduledRenewalProductPricePoint

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

Overview

Custom pricing for a product within a scheduled renewal.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #get_additional_properties, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(price_in_cents:, interval:, interval_unit:, name: SKIP, handle: SKIP, tax_included: SKIP, initial_charge_in_cents: SKIP, expiration_interval: SKIP, expiration_interval_unit: SKIP, additional_properties: {}) ⇒ ScheduledRenewalProductPricePoint

Returns a new instance of ScheduledRenewalProductPricePoint.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 86

def initialize(price_in_cents:, interval:, interval_unit:, name: SKIP,
               handle: SKIP, tax_included: SKIP,
               initial_charge_in_cents: 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 unless name == SKIP
  @handle = handle unless handle == SKIP
  @price_in_cents = price_in_cents
  @interval = interval
  @interval_unit = interval_unit
  @tax_included = tax_included unless tax_included == SKIP
  @initial_charge_in_cents = initial_charge_in_cents unless initial_charge_in_cents == 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_intervalInteger

The numerical expiration interval. i.e. an expiration_interval of ‘30’coupled with an expiration_interval_unit of day would mean this product price point would expire after 30 days.

Returns:

  • (Integer)


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

def expiration_interval
  @expiration_interval
end

#expiration_interval_unitExpirationIntervalUnit

A string representing the expiration interval unit for this product price point, either month, day or never



49
50
51
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 49

def expiration_interval_unit
  @expiration_interval_unit
end

#handleString

(Optional)

Returns:

  • (String)


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

def handle
  @handle
end

#initial_charge_in_centsInteger

The product price point initial charge, in integer cents.

Returns:

  • (Integer)


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

def initial_charge_in_cents
  @initial_charge_in_cents
end

#intervalObject

Required if using ‘custom_price` attribute.

Returns:

  • (Object)


26
27
28
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 26

def interval
  @interval
end

#interval_unitIntervalUnit

Required if using ‘custom_price` attribute.

Returns:



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

def interval_unit
  @interval_unit
end

#nameString

(Optional)

Returns:

  • (String)


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

def name
  @name
end

#price_in_centsObject

Required if using ‘custom_price` attribute.

Returns:

  • (Object)


22
23
24
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 22

def price_in_cents
  @price_in_cents
end

#tax_includedTrueClass | FalseClass

(Optional)

Returns:

  • (TrueClass | FalseClass)


34
35
36
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 34

def tax_included
  @tax_included
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



107
108
109
110
111
112
113
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
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 107

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  price_in_cents = hash.key?('price_in_cents') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:ScheduledRenewalProductPricePointPriceInCents), hash['price_in_cents']
  ) : nil
  interval = hash.key?('interval') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:ScheduledRenewalProductPricePointInterval), hash['interval']
  ) : nil
  interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : nil
  name = hash.key?('name') ? hash['name'] : SKIP
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  tax_included = hash.key?('tax_included') ? hash['tax_included'] : SKIP
  initial_charge_in_cents =
    hash.key?('initial_charge_in_cents') ? hash['initial_charge_in_cents'] : 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.
  ScheduledRenewalProductPricePoint.new(price_in_cents: price_in_cents,
                                        interval: interval,
                                        interval_unit: interval_unit,
                                        name: name,
                                        handle: handle,
                                        tax_included: tax_included,
                                        initial_charge_in_cents: initial_charge_in_cents,
                                        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.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_hash['price_in_cents'] = 'price_in_cents'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash['tax_included'] = 'tax_included'
  @_hash['initial_charge_in_cents'] = 'initial_charge_in_cents'
  @_hash['expiration_interval'] = 'expiration_interval'
  @_hash['expiration_interval_unit'] = 'expiration_interval_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



79
80
81
82
83
84
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 79

def self.nullables
  %w[
    interval_unit
    expiration_interval_unit
  ]
end

.optionalsObject

An array for optional fields



67
68
69
70
71
72
73
74
75
76
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 67

def self.optionals
  %w[
    name
    handle
    tax_included
    initial_charge_in_cents
    expiration_interval
    expiration_interval_unit
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 146

def self.validate(value)
  if value.instance_of? self
    return (
      UnionTypeLookUp.get(:ScheduledRenewalProductPricePointPriceInCents)
                     .validate(value.price_in_cents) and
        UnionTypeLookUp.get(:ScheduledRenewalProductPricePointInterval)
                       .validate(value.interval) and
        APIHelper.valid_type?(value.interval_unit,
                              ->(val) { IntervalUnit.validate(val) })
    )
  end

  return false unless value.instance_of? Hash

  (
    UnionTypeLookUp.get(:ScheduledRenewalProductPricePointPriceInCents)
                   .validate(value['price_in_cents']) and
      UnionTypeLookUp.get(:ScheduledRenewalProductPricePointInterval)
                     .validate(value['interval']) and
      APIHelper.valid_type?(value['interval_unit'],
                            ->(val) { IntervalUnit.validate(val) })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



181
182
183
184
185
186
187
188
189
190
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 181

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name.inspect}, handle: #{@handle.inspect}, price_in_cents:"\
  " #{@price_in_cents.inspect}, interval: #{@interval.inspect}, interval_unit:"\
  " #{@interval_unit.inspect}, tax_included: #{@tax_included.inspect},"\
  " initial_charge_in_cents: #{@initial_charge_in_cents.inspect}, expiration_interval:"\
  " #{@expiration_interval.inspect}, expiration_interval_unit:"\
  " #{@expiration_interval_unit.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



171
172
173
174
175
176
177
178
# File 'lib/advanced_billing/models/scheduled_renewal_product_price_point.rb', line 171

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, handle: #{@handle}, price_in_cents: #{@price_in_cents},"\
  " interval: #{@interval}, interval_unit: #{@interval_unit}, tax_included: #{@tax_included},"\
  " initial_charge_in_cents: #{@initial_charge_in_cents}, expiration_interval:"\
  " #{@expiration_interval}, expiration_interval_unit: #{@expiration_interval_unit},"\
  " additional_properties: #{get_additional_properties}>"
end