Class: AdvancedBilling::UpdateSubscription

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

Overview

UpdateSubscription Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(credit_card_attributes: SKIP, product_handle: SKIP, product_id: SKIP, product_change_delayed: SKIP, next_product_id: SKIP, next_product_price_point_id: SKIP, snap_day: SKIP, next_billing_at: SKIP, payment_collection_method: SKIP, receives_invoice_emails: SKIP, net_terms: SKIP, stored_credential_transaction_id: SKIP, reference: SKIP, custom_price: SKIP, components: SKIP, dunning_communication_delay_enabled: SKIP, dunning_communication_delay_time_zone: SKIP, product_price_point_id: SKIP, product_price_point_handle: SKIP, additional_properties: {}) ⇒ UpdateSubscription

Returns a new instance of UpdateSubscription.



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/advanced_billing/models/update_subscription.rb', line 162

def initialize(credit_card_attributes: SKIP, product_handle: SKIP,
               product_id: SKIP, product_change_delayed: SKIP,
               next_product_id: SKIP, next_product_price_point_id: SKIP,
               snap_day: SKIP, next_billing_at: SKIP,
               payment_collection_method: SKIP,
               receives_invoice_emails: SKIP, net_terms: SKIP,
               stored_credential_transaction_id: SKIP, reference: SKIP,
               custom_price: SKIP, components: SKIP,
               dunning_communication_delay_enabled: SKIP,
               dunning_communication_delay_time_zone: SKIP,
               product_price_point_id: SKIP,
               product_price_point_handle: SKIP, additional_properties: {})
  @credit_card_attributes = credit_card_attributes unless credit_card_attributes == SKIP
  @product_handle = product_handle unless product_handle == SKIP
  @product_id = product_id unless product_id == SKIP
  @product_change_delayed = product_change_delayed unless product_change_delayed == SKIP
  @next_product_id = next_product_id unless next_product_id == SKIP
  unless next_product_price_point_id == SKIP
    @next_product_price_point_id =
      next_product_price_point_id
  end
  @snap_day = snap_day unless snap_day == SKIP
  @next_billing_at = next_billing_at unless next_billing_at == SKIP
  unless payment_collection_method == SKIP
    @payment_collection_method =
      payment_collection_method
  end
  @receives_invoice_emails = receives_invoice_emails unless receives_invoice_emails == SKIP
  @net_terms = net_terms unless net_terms == SKIP
  unless stored_credential_transaction_id == SKIP
    @stored_credential_transaction_id =
      stored_credential_transaction_id
  end
  @reference = reference unless reference == SKIP
  @custom_price = custom_price unless custom_price == SKIP
  @components = components unless components == SKIP
  unless dunning_communication_delay_enabled == SKIP
    @dunning_communication_delay_enabled =
      dunning_communication_delay_enabled
  end
  unless dunning_communication_delay_time_zone == SKIP
    @dunning_communication_delay_time_zone =
      dunning_communication_delay_time_zone
  end
  @product_price_point_id = product_price_point_id unless product_price_point_id == SKIP
  unless product_price_point_handle == SKIP
    @product_price_point_handle =
      product_price_point_handle
  end

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

Instance Attribute Details

#componentsArray[UpdateSubscriptionComponent]

(Optional) An array of component ids and custom prices to be added to the subscription.

Returns:



81
82
83
# File 'lib/advanced_billing/models/update_subscription.rb', line 81

def components
  @components
end

#credit_card_attributesCreditCardAttributes

TODO: Write general description for this method



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

def credit_card_attributes
  @credit_card_attributes
end

#custom_priceSubscriptionCustomPrice

(Optional) Used in place of ‘product_price_point_id` to define a custom price point unique to the subscription



76
77
78
# File 'lib/advanced_billing/models/update_subscription.rb', line 76

def custom_price
  @custom_price
end

#dunning_communication_delay_enabledTrueClass | FalseClass

Enable Communication Delay feature, making sure no communication (email or SMS) is sent to the Customer between 9PM and 8AM in time zone set by the ‘dunning_communication_delay_time_zone` attribute.

Returns:

  • (TrueClass | FalseClass)


87
88
89
# File 'lib/advanced_billing/models/update_subscription.rb', line 87

def dunning_communication_delay_enabled
  @dunning_communication_delay_enabled
end

#dunning_communication_delay_time_zoneString

Time zone for the Dunning Communication Delay feature.

Returns:

  • (String)


91
92
93
# File 'lib/advanced_billing/models/update_subscription.rb', line 91

def dunning_communication_delay_time_zone
  @dunning_communication_delay_time_zone
end

#net_termsObject

Use for subscriptions with product eligible for calendar billing only. Value can be 1-28 or ‘end’.

Returns:

  • (Object)


61
62
63
# File 'lib/advanced_billing/models/update_subscription.rb', line 61

def net_terms
  @net_terms
end

#next_billing_atDateTime

Use for subscriptions with product eligible for calendar billing only. Value can be 1-28 or ‘end’.

Returns:

  • (DateTime)


46
47
48
# File 'lib/advanced_billing/models/update_subscription.rb', line 46

def next_billing_at
  @next_billing_at
end

#next_product_idString

Set to an empty string to cancel a delayed product change.

Returns:

  • (String)


32
33
34
# File 'lib/advanced_billing/models/update_subscription.rb', line 32

def next_product_id
  @next_product_id
end

#next_product_price_point_idString

Set to an empty string to cancel a delayed product change.

Returns:

  • (String)


36
37
38
# File 'lib/advanced_billing/models/update_subscription.rb', line 36

def next_product_price_point_id
  @next_product_price_point_id
end

#payment_collection_methodString

Use for subscriptions with product eligible for calendar billing only. Value can be 1-28 or ‘end’.

Returns:

  • (String)


51
52
53
# File 'lib/advanced_billing/models/update_subscription.rb', line 51

def payment_collection_method
  @payment_collection_method
end

#product_change_delayedTrueClass | FalseClass

Set to the id of a different product to change the subscription’s product

Returns:

  • (TrueClass | FalseClass)


28
29
30
# File 'lib/advanced_billing/models/update_subscription.rb', line 28

def product_change_delayed
  @product_change_delayed
end

#product_handleString

Set to the handle of a different product to change the subscription’s product

Returns:

  • (String)


20
21
22
# File 'lib/advanced_billing/models/update_subscription.rb', line 20

def product_handle
  @product_handle
end

#product_idInteger

Set to the id of a different product to change the subscription’s product

Returns:

  • (Integer)


24
25
26
# File 'lib/advanced_billing/models/update_subscription.rb', line 24

def product_id
  @product_id
end

#product_price_point_handleString

Set to change the current product’s price point.

Returns:

  • (String)


99
100
101
# File 'lib/advanced_billing/models/update_subscription.rb', line 99

def product_price_point_handle
  @product_price_point_handle
end

#product_price_point_idInteger

Set to change the current product’s price point.

Returns:

  • (Integer)


95
96
97
# File 'lib/advanced_billing/models/update_subscription.rb', line 95

def product_price_point_id
  @product_price_point_id
end

#receives_invoice_emailsTrueClass | FalseClass

Use for subscriptions with product eligible for calendar billing only. Value can be 1-28 or ‘end’.

Returns:

  • (TrueClass | FalseClass)


56
57
58
# File 'lib/advanced_billing/models/update_subscription.rb', line 56

def receives_invoice_emails
  @receives_invoice_emails
end

#referenceString

Use for subscriptions with product eligible for calendar billing only. Value can be 1-28 or ‘end’.

Returns:

  • (String)


71
72
73
# File 'lib/advanced_billing/models/update_subscription.rb', line 71

def reference
  @reference
end

#snap_dayObject

Use for subscriptions with product eligible for calendar billing only. Value can be 1-28 or ‘end’.

Returns:

  • (Object)


41
42
43
# File 'lib/advanced_billing/models/update_subscription.rb', line 41

def snap_day
  @snap_day
end

#stored_credential_transaction_idInteger

Use for subscriptions with product eligible for calendar billing only. Value can be 1-28 or ‘end’.

Returns:

  • (Integer)


66
67
68
# File 'lib/advanced_billing/models/update_subscription.rb', line 66

def stored_credential_transaction_id
  @stored_credential_transaction_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/advanced_billing/models/update_subscription.rb', line 219

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  credit_card_attributes = CreditCardAttributes.from_hash(hash['credit_card_attributes']) if
    hash['credit_card_attributes']
  product_handle =
    hash.key?('product_handle') ? hash['product_handle'] : SKIP
  product_id = hash.key?('product_id') ? hash['product_id'] : SKIP
  product_change_delayed =
    hash.key?('product_change_delayed') ? hash['product_change_delayed'] : SKIP
  next_product_id =
    hash.key?('next_product_id') ? hash['next_product_id'] : SKIP
  next_product_price_point_id =
    hash.key?('next_product_price_point_id') ? hash['next_product_price_point_id'] : SKIP
  snap_day = hash.key?('snap_day') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateSubscriptionSnapDay), hash['snap_day']
  ) : SKIP
  next_billing_at = if hash.key?('next_billing_at')
                      (DateTimeHelper.from_rfc3339(hash['next_billing_at']) if hash['next_billing_at'])
                    else
                      SKIP
                    end
  payment_collection_method =
    hash.key?('payment_collection_method') ? hash['payment_collection_method'] : SKIP
  receives_invoice_emails =
    hash.key?('receives_invoice_emails') ? hash['receives_invoice_emails'] : SKIP
  net_terms = hash.key?('net_terms') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateSubscriptionNetTerms), hash['net_terms']
  ) : SKIP
  stored_credential_transaction_id =
    hash.key?('stored_credential_transaction_id') ? hash['stored_credential_transaction_id'] : SKIP
  reference = hash.key?('reference') ? hash['reference'] : SKIP
  custom_price = SubscriptionCustomPrice.from_hash(hash['custom_price']) if
    hash['custom_price']
  # Parameter is an array, so we need to iterate through it
  components = nil
  unless hash['components'].nil?
    components = []
    hash['components'].each do |structure|
      components << (UpdateSubscriptionComponent.from_hash(structure) if structure)
    end
  end

  components = SKIP unless hash.key?('components')
  dunning_communication_delay_enabled =
    hash.key?('dunning_communication_delay_enabled') ? hash['dunning_communication_delay_enabled'] : SKIP
  dunning_communication_delay_time_zone =
    hash.key?('dunning_communication_delay_time_zone') ? hash['dunning_communication_delay_time_zone'] : SKIP
  product_price_point_id =
    hash.key?('product_price_point_id') ? hash['product_price_point_id'] : SKIP
  product_price_point_handle =
    hash.key?('product_price_point_handle') ? hash['product_price_point_handle'] : SKIP

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

  # Create object from extracted values.
  UpdateSubscription.new(credit_card_attributes: credit_card_attributes,
                         product_handle: product_handle,
                         product_id: product_id,
                         product_change_delayed: product_change_delayed,
                         next_product_id: next_product_id,
                         next_product_price_point_id: next_product_price_point_id,
                         snap_day: snap_day,
                         next_billing_at: next_billing_at,
                         payment_collection_method: payment_collection_method,
                         receives_invoice_emails: receives_invoice_emails,
                         net_terms: net_terms,
                         stored_credential_transaction_id: stored_credential_transaction_id,
                         reference: reference,
                         custom_price: custom_price,
                         components: components,
                         dunning_communication_delay_enabled: dunning_communication_delay_enabled,
                         dunning_communication_delay_time_zone: dunning_communication_delay_time_zone,
                         product_price_point_id: product_price_point_id,
                         product_price_point_handle: product_price_point_handle,
                         additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/advanced_billing/models/update_subscription.rb', line 102

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['credit_card_attributes'] = 'credit_card_attributes'
  @_hash['product_handle'] = 'product_handle'
  @_hash['product_id'] = 'product_id'
  @_hash['product_change_delayed'] = 'product_change_delayed'
  @_hash['next_product_id'] = 'next_product_id'
  @_hash['next_product_price_point_id'] = 'next_product_price_point_id'
  @_hash['snap_day'] = 'snap_day'
  @_hash['next_billing_at'] = 'next_billing_at'
  @_hash['payment_collection_method'] = 'payment_collection_method'
  @_hash['receives_invoice_emails'] = 'receives_invoice_emails'
  @_hash['net_terms'] = 'net_terms'
  @_hash['stored_credential_transaction_id'] =
    'stored_credential_transaction_id'
  @_hash['reference'] = 'reference'
  @_hash['custom_price'] = 'custom_price'
  @_hash['components'] = 'components'
  @_hash['dunning_communication_delay_enabled'] =
    'dunning_communication_delay_enabled'
  @_hash['dunning_communication_delay_time_zone'] =
    'dunning_communication_delay_time_zone'
  @_hash['product_price_point_id'] = 'product_price_point_id'
  @_hash['product_price_point_handle'] = 'product_price_point_handle'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    dunning_communication_delay_enabled
    dunning_communication_delay_time_zone
  ]
end

.optionalsObject

An array for optional fields



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/advanced_billing/models/update_subscription.rb', line 130

def self.optionals
  %w[
    credit_card_attributes
    product_handle
    product_id
    product_change_delayed
    next_product_id
    next_product_price_point_id
    snap_day
    next_billing_at
    payment_collection_method
    receives_invoice_emails
    net_terms
    stored_credential_transaction_id
    reference
    custom_price
    components
    dunning_communication_delay_enabled
    dunning_communication_delay_time_zone
    product_price_point_id
    product_price_point_handle
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



305
306
307
308
309
310
311
# File 'lib/advanced_billing/models/update_subscription.rb', line 305

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

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#to_custom_next_billing_atObject



299
300
301
# File 'lib/advanced_billing/models/update_subscription.rb', line 299

def to_custom_next_billing_at
  DateTimeHelper.to_rfc3339(next_billing_at)
end