Class: AdvancedBilling::OverrideSubscription

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

Overview

OverrideSubscription Model.

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(activated_at: SKIP, canceled_at: SKIP, cancellation_message: SKIP, expires_at: SKIP, current_period_starts_at: SKIP, additional_properties: {}) ⇒ OverrideSubscription

Returns a new instance of OverrideSubscription.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/advanced_billing/models/override_subscription.rb', line 72

def initialize(activated_at: SKIP, canceled_at: SKIP,
               cancellation_message: SKIP, expires_at: SKIP,
               current_period_starts_at: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @activated_at = activated_at unless activated_at == SKIP
  @canceled_at = canceled_at unless canceled_at == SKIP
  @cancellation_message = cancellation_message unless cancellation_message == SKIP
  @expires_at = expires_at unless expires_at == SKIP
  @current_period_starts_at = current_period_starts_at unless current_period_starts_at == SKIP
end

Instance Attribute Details

#activated_atDateTime

Can be used to record an external signup date. Chargify uses this field to record when a subscription first goes active (either at signup or at trial end). Only ISO8601 format is supported.

Returns:

  • (DateTime)


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

def activated_at
  @activated_at
end

#canceled_atDateTime

Can be used to record an external cancellation date. Chargify sets this field automatically when a subscription is canceled, whether by request or via dunning. Only ISO8601 format is supported.

Returns:

  • (DateTime)


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

def canceled_at
  @canceled_at
end

#cancellation_messageString

Can be used to record a reason for the original cancellation.

Returns:

  • (String)


27
28
29
# File 'lib/advanced_billing/models/override_subscription.rb', line 27

def cancellation_message
  @cancellation_message
end

#current_period_starts_atDateTime

Can only be used when a subscription is unbilled, which happens when a future initial billing date is passed at subscription creation. The value passed must be before the current date and time. Allows you to set when the period started so mid period component allocations have the correct proration. Only ISO8601 format is supported.

Returns:

  • (DateTime)


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

def current_period_starts_at
  @current_period_starts_at
end

#expires_atDateTime

Can be used to record an external expiration date. Chargify sets this field automatically when a subscription expires (ceases billing) after a prescribed amount of time. Only ISO8601 format is supported. This field is not supported when Multi-frequency is enabled for the Site. To change the Term End of a Subscription, use the Update Subscription endpoint.

Returns:

  • (DateTime)


35
36
37
# File 'lib/advanced_billing/models/override_subscription.rb', line 35

def expires_at
  @expires_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



88
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
118
119
120
121
122
123
124
125
# File 'lib/advanced_billing/models/override_subscription.rb', line 88

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  activated_at = if hash.key?('activated_at')
                   (DateTimeHelper.from_rfc3339(hash['activated_at']) if hash['activated_at'])
                 else
                   SKIP
                 end
  canceled_at = if hash.key?('canceled_at')
                  (DateTimeHelper.from_rfc3339(hash['canceled_at']) if hash['canceled_at'])
                else
                  SKIP
                end
  cancellation_message =
    hash.key?('cancellation_message') ? hash['cancellation_message'] : SKIP
  expires_at = if hash.key?('expires_at')
                 (DateTimeHelper.from_rfc3339(hash['expires_at']) if hash['expires_at'])
               else
                 SKIP
               end
  current_period_starts_at = if hash.key?('current_period_starts_at')
                               (DateTimeHelper.from_rfc3339(hash['current_period_starts_at']) if hash['current_period_starts_at'])
                             else
                               SKIP
                             end

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

  # Create object from extracted values.
  OverrideSubscription.new(activated_at: activated_at,
                           canceled_at: canceled_at,
                           cancellation_message: cancellation_message,
                           expires_at: expires_at,
                           current_period_starts_at: current_period_starts_at,
                           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



46
47
48
49
50
51
52
53
54
# File 'lib/advanced_billing/models/override_subscription.rb', line 46

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['activated_at'] = 'activated_at'
  @_hash['canceled_at'] = 'canceled_at'
  @_hash['cancellation_message'] = 'cancellation_message'
  @_hash['expires_at'] = 'expires_at'
  @_hash['current_period_starts_at'] = 'current_period_starts_at'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    activated_at
    canceled_at
    cancellation_message
    expires_at
    current_period_starts_at
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



153
154
155
156
157
158
159
160
# File 'lib/advanced_billing/models/override_subscription.rb', line 153

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} activated_at: #{@activated_at.inspect}, canceled_at:"\
  " #{@canceled_at.inspect}, cancellation_message: #{@cancellation_message.inspect},"\
  " expires_at: #{@expires_at.inspect}, current_period_starts_at:"\
  " #{@current_period_starts_at.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_custom_activated_atObject



127
128
129
# File 'lib/advanced_billing/models/override_subscription.rb', line 127

def to_custom_activated_at
  DateTimeHelper.to_rfc3339(activated_at)
end

#to_custom_canceled_atObject



131
132
133
# File 'lib/advanced_billing/models/override_subscription.rb', line 131

def to_custom_canceled_at
  DateTimeHelper.to_rfc3339(canceled_at)
end

#to_custom_current_period_starts_atObject



139
140
141
# File 'lib/advanced_billing/models/override_subscription.rb', line 139

def to_custom_current_period_starts_at
  DateTimeHelper.to_rfc3339(current_period_starts_at)
end

#to_custom_expires_atObject



135
136
137
# File 'lib/advanced_billing/models/override_subscription.rb', line 135

def to_custom_expires_at
  DateTimeHelper.to_rfc3339(expires_at)
end

#to_sObject

Provides a human-readable string representation of the object.



144
145
146
147
148
149
150
# File 'lib/advanced_billing/models/override_subscription.rb', line 144

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} activated_at: #{@activated_at}, canceled_at: #{@canceled_at},"\
  " cancellation_message: #{@cancellation_message}, expires_at: #{@expires_at},"\
  " current_period_starts_at: #{@current_period_starts_at}, additional_properties:"\
  " #{get_additional_properties}>"
end