Class: AdvancedBilling::SubscriptionProductChange

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

Overview

Event data for both subscription_product_change and subscription_product_change_scheduled. The price point and effective_at fields are only populated for scheduled changes.

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(previous_product_id:, new_product_id:, previous_product_price_point_id: SKIP, new_product_price_point_id: SKIP, effective_at: SKIP, additional_properties: {}) ⇒ SubscriptionProductChange

Returns a new instance of SubscriptionProductChange.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 66

def initialize(previous_product_id:, new_product_id:,
               previous_product_price_point_id: SKIP,
               new_product_price_point_id: SKIP, effective_at: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @previous_product_id = previous_product_id
  @new_product_id = new_product_id
  unless previous_product_price_point_id == SKIP
    @previous_product_price_point_id =
      previous_product_price_point_id
  end
  unless new_product_price_point_id == SKIP
    @new_product_price_point_id =
      new_product_price_point_id
  end
  @effective_at = effective_at unless effective_at == SKIP
end

Instance Attribute Details

#effective_atDateTime

When the scheduled product change takes effect (the subscription's next renewal). Only sent for subscription_product_change_scheduled.

Returns:

  • (DateTime)


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

def effective_at
  @effective_at
end

#new_product_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


21
22
23
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 21

def new_product_id
  @new_product_id
end

#new_product_price_point_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def new_product_price_point_id
  @new_product_price_point_id
end

#previous_product_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def previous_product_id
  @previous_product_id
end

#previous_product_price_point_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


25
26
27
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 25

def previous_product_price_point_id
  @previous_product_price_point_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 89

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  previous_product_id =
    hash.key?('previous_product_id') ? hash['previous_product_id'] : nil
  new_product_id =
    hash.key?('new_product_id') ? hash['new_product_id'] : nil
  previous_product_price_point_id =
    hash.key?('previous_product_price_point_id') ? hash['previous_product_price_point_id'] : SKIP
  new_product_price_point_id =
    hash.key?('new_product_price_point_id') ? hash['new_product_price_point_id'] : SKIP
  effective_at = if hash.key?('effective_at')
                   (DateTimeHelper.from_rfc3339(hash['effective_at']) if hash['effective_at'])
                 else
                   SKIP
                 end

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

  # Create object from extracted values.
  SubscriptionProductChange.new(previous_product_id: previous_product_id,
                                new_product_id: new_product_id,
                                previous_product_price_point_id: previous_product_price_point_id,
                                new_product_price_point_id: new_product_price_point_id,
                                effective_at: effective_at,
                                additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
46
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['previous_product_id'] = 'previous_product_id'
  @_hash['new_product_id'] = 'new_product_id'
  @_hash['previous_product_price_point_id'] =
    'previous_product_price_point_id'
  @_hash['new_product_price_point_id'] = 'new_product_price_point_id'
  @_hash['effective_at'] = 'effective_at'
  @_hash
end

.nullablesObject

An array for nullable fields



58
59
60
61
62
63
64
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 58

def self.nullables
  %w[
    previous_product_price_point_id
    new_product_price_point_id
    effective_at
  ]
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
55
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 49

def self.optionals
  %w[
    previous_product_price_point_id
    new_product_price_point_id
    effective_at
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 125

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.previous_product_id,
                            ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.new_product_id,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['previous_product_id'],
                          ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['new_product_id'],
                            ->(val) { val.instance_of? Integer })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



155
156
157
158
159
160
161
162
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 155

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} previous_product_id: #{@previous_product_id.inspect}, new_product_id:"\
  " #{@new_product_id.inspect}, previous_product_price_point_id:"\
  " #{@previous_product_price_point_id.inspect}, new_product_price_point_id:"\
  " #{@new_product_price_point_id.inspect}, effective_at: #{@effective_at.inspect},"\
  " additional_properties: #{get_additional_properties}>"
end

#to_custom_effective_atObject



119
120
121
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 119

def to_custom_effective_at
  DateTimeHelper.to_rfc3339(effective_at)
end

#to_sObject

Provides a human-readable string representation of the object.



146
147
148
149
150
151
152
# File 'lib/advanced_billing/models/subscription_product_change.rb', line 146

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} previous_product_id: #{@previous_product_id}, new_product_id:"\
  " #{@new_product_id}, previous_product_price_point_id: #{@previous_product_price_point_id},"\
  " new_product_price_point_id: #{@new_product_price_point_id}, effective_at:"\
  " #{@effective_at}, additional_properties: #{get_additional_properties}>"
end