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

#check_for_conflict, #get_additional_properties, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #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, initial_billing_at: SKIP, defer_signup: false, next_billing_at: SKIP, expires_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.



214
215
216
217
218
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
# File 'lib/advanced_billing/models/update_subscription.rb', line 214

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, initial_billing_at: SKIP,
               defer_signup: false, next_billing_at: SKIP, expires_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: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @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
  @initial_billing_at = initial_billing_at unless initial_billing_at == SKIP
  @defer_signup =  unless  == SKIP
  @next_billing_at = next_billing_at unless next_billing_at == SKIP
  @expires_at = expires_at unless expires_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
end

Instance Attribute Details

#componentsArray[UpdateSubscriptionComponent]

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

Returns:



128
129
130
# File 'lib/advanced_billing/models/update_subscription.rb', line 128

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



123
124
125
# File 'lib/advanced_billing/models/update_subscription.rb', line 123

def custom_price
  @custom_price
end

#defer_signupTrueClass | FalseClass

(Optional) Set this attribute to true to move the subscription from Awaiting Signup, to Awaiting Signup Date. Use this when you want to update a subscription that has an unknown initial billing date. When the first billing date is known, update a subscription to set the ‘initial_billing_at` date. The subscription moves to the awaiting signup with a scheduled initial billing date. You can omit the initial_billing_at date to activate the subscription immediately. See [Subscription States](maxio-chargify.zendesk.com/hc/en-us/articles/5404222005773 -Subscription-States) for more information.

Returns:

  • (TrueClass | FalseClass)


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

def 
  @defer_signup
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)


134
135
136
# File 'lib/advanced_billing/models/update_subscription.rb', line 134

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)


138
139
140
# File 'lib/advanced_billing/models/update_subscription.rb', line 138

def dunning_communication_delay_time_zone
  @dunning_communication_delay_time_zone
end

#expires_atDateTime

Timestamp giving the expiration date of this subscription (if any). You may manually change the expiration date at any point during a subscription period.

Returns:

  • (DateTime)


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

def expires_at
  @expires_at
end

#initial_billing_atDateTime

(Optional) Set this attribute to a future date/time to update a subscription in the Awaiting Signup Date state, to Awaiting Signup. In the Awaiting Signup state, a subscription behaves like any other. It can be canceled, allocated to, or have its billing date changed. etc. When the ‘initial_billing_at` date hits, the subscription will transition to the expected state. If the product has a trial, the subscription will enter a trial, otherwise it will go active. Setup fees will be respected either before or after the trial, as configured on the price point. If the payment is due at the initial_billing_at and it fails the subscription will be immediately canceled. You can omit the initial_billing_at date to activate the subscription immediately. See the [subscription import](maxio.zendesk.com/hc/en-us/articles/24251489107213-Advance d-Billing-Subscription-Imports#date-format) documentation for more information about Date/Time formats.

Returns:

  • (DateTime)


58
59
60
# File 'lib/advanced_billing/models/update_subscription.rb', line 58

def initial_billing_at
  @initial_billing_at
end

#net_termsObject

Timestamp giving the expiration date of this subscription (if any). You may manually change the expiration date at any point during a subscription period.

Returns:

  • (Object)


106
107
108
# File 'lib/advanced_billing/models/update_subscription.rb', line 106

def net_terms
  @net_terms
end

#next_billing_atDateTime

(Optional) Set this attribute to true to move the subscription from Awaiting Signup, to Awaiting Signup Date. Use this when you want to update a subscription that has an unknown initial billing date. When the first billing date is known, update a subscription to set the ‘initial_billing_at` date. The subscription moves to the awaiting signup with a scheduled initial billing date. You can omit the initial_billing_at date to activate the subscription immediately. See [Subscription States](maxio-chargify.zendesk.com/hc/en-us/articles/5404222005773 -Subscription-States) for more information.

Returns:

  • (DateTime)


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

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

Timestamp giving the expiration date of this subscription (if any). You may manually change the expiration date at any point during a subscription period.

Returns:

  • (String)


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

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)


146
147
148
# File 'lib/advanced_billing/models/update_subscription.rb', line 146

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)


142
143
144
# File 'lib/advanced_billing/models/update_subscription.rb', line 142

def product_price_point_id
  @product_price_point_id
end

#receives_invoice_emailsTrueClass | FalseClass

Timestamp giving the expiration date of this subscription (if any). You may manually change the expiration date at any point during a subscription period.

Returns:

  • (TrueClass | FalseClass)


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

def receives_invoice_emails
  @receives_invoice_emails
end

#referenceString

Timestamp giving the expiration date of this subscription (if any). You may manually change the expiration date at any point during a subscription period.

Returns:

  • (String)


118
119
120
# File 'lib/advanced_billing/models/update_subscription.rb', line 118

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

Timestamp giving the expiration date of this subscription (if any). You may manually change the expiration date at any point during a subscription period.

Returns:

  • (Integer)


112
113
114
# File 'lib/advanced_billing/models/update_subscription.rb', line 112

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.



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/advanced_billing/models/update_subscription.rb', line 275

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
  initial_billing_at = if hash.key?('initial_billing_at')
                         (DateTimeHelper.from_rfc3339(hash['initial_billing_at']) if hash['initial_billing_at'])
                       else
                         SKIP
                       end
   = hash['defer_signup'] ||= false
  next_billing_at = if hash.key?('next_billing_at')
                      (DateTimeHelper.from_rfc3339(hash['next_billing_at']) if hash['next_billing_at'])
                    else
                      SKIP
                    end
  expires_at = if hash.key?('expires_at')
                 (DateTimeHelper.from_rfc3339(hash['expires_at']) if hash['expires_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.
  additional_properties = hash.reject { |k, _| names.value?(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,
                         initial_billing_at: initial_billing_at,
                         defer_signup: ,
                         next_billing_at: next_billing_at,
                         expires_at: expires_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: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/advanced_billing/models/update_subscription.rb', line 149

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['initial_billing_at'] = 'initial_billing_at'
  @_hash['defer_signup'] = 'defer_signup'
  @_hash['next_billing_at'] = 'next_billing_at'
  @_hash['expires_at'] = 'expires_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



208
209
210
211
212
# File 'lib/advanced_billing/models/update_subscription.rb', line 208

def self.nullables
  %w[
    dunning_communication_delay_time_zone
  ]
end

.optionalsObject

An array for optional fields



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
# File 'lib/advanced_billing/models/update_subscription.rb', line 180

def self.optionals
  %w[
    credit_card_attributes
    product_handle
    product_id
    product_change_delayed
    next_product_id
    next_product_price_point_id
    snap_day
    initial_billing_at
    defer_signup
    next_billing_at
    expires_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:



383
384
385
386
387
388
389
# File 'lib/advanced_billing/models/update_subscription.rb', line 383

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

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/advanced_billing/models/update_subscription.rb', line 411

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} credit_card_attributes: #{@credit_card_attributes.inspect}, product_handle:"\
  " #{@product_handle.inspect}, product_id: #{@product_id.inspect}, product_change_delayed:"\
  " #{@product_change_delayed.inspect}, next_product_id: #{@next_product_id.inspect},"\
  " next_product_price_point_id: #{@next_product_price_point_id.inspect}, snap_day:"\
  " #{@snap_day.inspect}, initial_billing_at: #{@initial_billing_at.inspect}, defer_signup:"\
  " #{@defer_signup.inspect}, next_billing_at: #{@next_billing_at.inspect}, expires_at:"\
  " #{@expires_at.inspect}, payment_collection_method: #{@payment_collection_method.inspect},"\
  " receives_invoice_emails: #{@receives_invoice_emails.inspect}, net_terms:"\
  " #{@net_terms.inspect}, stored_credential_transaction_id:"\
  " #{@stored_credential_transaction_id.inspect}, reference: #{@reference.inspect},"\
  " custom_price: #{@custom_price.inspect}, components: #{@components.inspect},"\
  " dunning_communication_delay_enabled: #{@dunning_communication_delay_enabled.inspect},"\
  " dunning_communication_delay_time_zone: #{@dunning_communication_delay_time_zone.inspect},"\
  " product_price_point_id: #{@product_price_point_id.inspect}, product_price_point_handle:"\
  " #{@product_price_point_handle.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_custom_expires_atObject



377
378
379
# File 'lib/advanced_billing/models/update_subscription.rb', line 377

def to_custom_expires_at
  DateTimeHelper.to_rfc3339(expires_at)
end

#to_custom_initial_billing_atObject



369
370
371
# File 'lib/advanced_billing/models/update_subscription.rb', line 369

def to_custom_initial_billing_at
  DateTimeHelper.to_rfc3339(initial_billing_at)
end

#to_custom_next_billing_atObject



373
374
375
# File 'lib/advanced_billing/models/update_subscription.rb', line 373

def to_custom_next_billing_at
  DateTimeHelper.to_rfc3339(next_billing_at)
end

#to_sObject

Provides a human-readable string representation of the object.



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/advanced_billing/models/update_subscription.rb', line 392

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} 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},"\
  " initial_billing_at: #{@initial_billing_at}, defer_signup: #{@defer_signup},"\
  " next_billing_at: #{@next_billing_at}, expires_at: #{@expires_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: #{get_additional_properties}>"
end