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 = false, 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 = false, dunning_communication_delay_time_zone = SKIP) ⇒ UpdateSubscription

Returns a new instance of UpdateSubscription.



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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/advanced_billing/models/update_subscription.rb', line 149

def initialize(credit_card_attributes = SKIP, product_handle = SKIP,
               product_id = SKIP, product_change_delayed = false,
               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 = false,
               dunning_communication_delay_time_zone = SKIP)
  @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
end

Instance Attribute Details

#componentsArray[UpdateSubscriptionComponent]

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

Returns:



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

def components
  @components
end

#credit_card_attributesCreditCardAttributes

TODO: Write general description for this method



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

def credit_card_attributes
  @credit_card_attributes
end

#custom_priceCustomPriceUsedForSubscriptionCreateUpdate

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



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

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)


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

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)


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

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)


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

def net_terms
  @net_terms
end

#next_billing_atString

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

Returns:

  • (String)


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

def next_billing_at
  @next_billing_at
end

#next_product_idString

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

Returns:

  • (String)


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

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)


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

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)


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

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)


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

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)


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

def product_handle
  @product_handle
end

#product_idInteger

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

Returns:

  • (Integer)


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

def product_id
  @product_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)


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

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)


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

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)


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

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)


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

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.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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
# File 'lib/advanced_billing/models/update_subscription.rb', line 194

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['product_change_delayed'] ||= false
  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 =
    hash.key?('next_billing_at') ? hash['next_billing_at'] : SKIP
  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 = CustomPriceUsedForSubscriptionCreateUpdate.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['dunning_communication_delay_enabled'] ||= false
  dunning_communication_delay_time_zone =
    hash.key?('dunning_communication_delay_time_zone') ? hash['dunning_communication_delay_time_zone'] : SKIP

  # Create object from extracted values.
  UpdateSubscription.new(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)
end

.namesObject

A mapping from model property names to API property names.



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

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
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    dunning_communication_delay_enabled
    dunning_communication_delay_time_zone
  ]
end

.optionalsObject

An array for optional fields



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/advanced_billing/models/update_subscription.rb', line 119

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
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



262
263
264
265
266
267
268
# File 'lib/advanced_billing/models/update_subscription.rb', line 262

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

  return false unless value.instance_of? Hash

  true
end