Class: AdvancedBilling::CreateAllocation

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

Overview

CreateAllocation 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(quantity:, decimal_quantity: SKIP, previous_quantity: SKIP, decimal_previous_quantity: SKIP, component_id: SKIP, memo: SKIP, proration_downgrade_scheme: SKIP, proration_upgrade_scheme: SKIP, downgrade_credit: SKIP, upgrade_charge: SKIP, accrue_charge: SKIP, initiate_dunning: SKIP, price_point_id: SKIP, billing_schedule: SKIP, custom_price: SKIP, additional_properties: {}) ⇒ CreateAllocation

Returns a new instance of CreateAllocation.



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

def initialize(quantity:, decimal_quantity: SKIP, previous_quantity: SKIP,
               decimal_previous_quantity: SKIP, component_id: SKIP,
               memo: SKIP, proration_downgrade_scheme: SKIP,
               proration_upgrade_scheme: SKIP, downgrade_credit: SKIP,
               upgrade_charge: SKIP, accrue_charge: SKIP,
               initiate_dunning: SKIP, price_point_id: SKIP,
               billing_schedule: SKIP, custom_price: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @quantity = quantity
  @decimal_quantity = decimal_quantity unless decimal_quantity == SKIP
  @previous_quantity = previous_quantity unless previous_quantity == SKIP
  unless decimal_previous_quantity == SKIP
    @decimal_previous_quantity =
      decimal_previous_quantity
  end
  @component_id = component_id unless component_id == SKIP
  @memo = memo unless memo == SKIP
  unless proration_downgrade_scheme == SKIP
    @proration_downgrade_scheme =
      proration_downgrade_scheme
  end
  @proration_upgrade_scheme = proration_upgrade_scheme unless proration_upgrade_scheme == SKIP
  @downgrade_credit = downgrade_credit unless downgrade_credit == SKIP
  @upgrade_charge = upgrade_charge unless upgrade_charge == SKIP
  @accrue_charge = accrue_charge unless accrue_charge == SKIP
  @initiate_dunning = initiate_dunning unless initiate_dunning == SKIP
  @price_point_id = price_point_id unless price_point_id == SKIP
  @billing_schedule = billing_schedule unless billing_schedule == SKIP
  @custom_price = custom_price unless custom_price == SKIP
end

Instance Attribute Details

#accrue_chargeTrueClass | FalseClass

“If the change in cost is an upgrade, this determines if the charge should accrue to the next renewal or if capture should be attempted immediately. ‘true` - Attempt to charge the customer at the next renewal.

‘false` - Attempt to charge the customer right away. If it fails, the charge will be accrued until the next renewal. Defaults to the site setting if unspecified in the request.

Returns:

  • (TrueClass | FalseClass)


78
79
80
# File 'lib/advanced_billing/models/create_allocation.rb', line 78

def accrue_charge
  @accrue_charge
end

#billing_scheduleBillingSchedule

Billing schedule settings for component allocations or usages on multi-frequency subscriptions. Use this to start a component’s billing period on a custom date instead of aligning with the product charge schedule.

Returns:



98
99
100
# File 'lib/advanced_billing/models/create_allocation.rb', line 98

def billing_schedule
  @billing_schedule
end

#component_idInteger

(required for the multiple allocations endpoint) The id associated with the component for which the allocation is being made.

Returns:

  • (Integer)


38
39
40
# File 'lib/advanced_billing/models/create_allocation.rb', line 38

def component_id
  @component_id
end

#custom_priceComponentCustomPrice

Create or update custom pricing unique to the subscription. Used in place of ‘price_point_id`.



103
104
105
# File 'lib/advanced_billing/models/create_allocation.rb', line 103

def custom_price
  @custom_price
end

#decimal_previous_quantityString

Decimal representation of ‘previous_quantity`. Only valid when decimal allocations are enabled for the component.

Returns:

  • (String)


33
34
35
# File 'lib/advanced_billing/models/create_allocation.rb', line 33

def decimal_previous_quantity
  @decimal_previous_quantity
end

#decimal_quantityString

Decimal representation of the allocated quantity. Only valid when decimal allocations are enabled for the component.

Returns:

  • (String)


22
23
24
# File 'lib/advanced_billing/models/create_allocation.rb', line 22

def decimal_quantity
  @decimal_quantity
end

#downgrade_creditDowngradeCreditCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Values are: ‘full` - A full price credit is added for the amount owed. `prorated` - A prorated credit is added for the amount owed. `none` - No charge is added.



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

def downgrade_credit
  @downgrade_credit
end

#initiate_dunningTrueClass | FalseClass

If set to true, if the immediate component payment fails, initiate dunning for the subscription. Otherwise, leave the charges on the subscription to pay for at renewal. Defaults to false.

Returns:

  • (TrueClass | FalseClass)


85
86
87
# File 'lib/advanced_billing/models/create_allocation.rb', line 85

def initiate_dunning
  @initiate_dunning
end

#memoString

A memo to record along with the allocation.

Returns:

  • (String)


42
43
44
# File 'lib/advanced_billing/models/create_allocation.rb', line 42

def memo
  @memo
end

#previous_quantityFloat

The quantity that was in effect before this allocation. Responses always include this value; it may be supplied on preview requests to ensure the expected change is evaluated.

Returns:

  • (Float)


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

def previous_quantity
  @previous_quantity
end

#price_point_idObject

Price point that the allocation should be charged at. Accepts either the price point’s id (integer) or handle (string). When not specified, the default price point will be used.

Returns:

  • (Object)


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

def price_point_id
  @price_point_id
end

#proration_downgrade_schemeString

The scheme used if the proration is a downgrade. Defaults to the site setting if one is not provided.

Returns:

  • (String)


47
48
49
# File 'lib/advanced_billing/models/create_allocation.rb', line 47

def proration_downgrade_scheme
  @proration_downgrade_scheme
end

#proration_upgrade_schemeString

The scheme used if the proration is an upgrade. Defaults to the site setting if one is not provided.

Returns:

  • (String)


52
53
54
# File 'lib/advanced_billing/models/create_allocation.rb', line 52

def proration_upgrade_scheme
  @proration_upgrade_scheme
end

#quantityFloat

The allocated quantity to which to set the line-items allocated quantity. By default, this is an integer. If decimal allocations are enabled for the component, it will be a decimal number. For On/Off components, use 1for on and 0 for off.

Returns:

  • (Float)


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

def quantity
  @quantity
end

#upgrade_chargeUpgradeChargeCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Values are: ‘full` - A charge is added for the full price of the component. `prorated` - A charge is added for the prorated price of the component change. `none` - No charge is added.



69
70
71
# File 'lib/advanced_billing/models/create_allocation.rb', line 69

def upgrade_charge
  @upgrade_charge
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  decimal_quantity =
    hash.key?('decimal_quantity') ? hash['decimal_quantity'] : SKIP
  previous_quantity =
    hash.key?('previous_quantity') ? hash['previous_quantity'] : SKIP
  decimal_previous_quantity =
    hash.key?('decimal_previous_quantity') ? hash['decimal_previous_quantity'] : SKIP
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  proration_downgrade_scheme =
    hash.key?('proration_downgrade_scheme') ? hash['proration_downgrade_scheme'] : SKIP
  proration_upgrade_scheme =
    hash.key?('proration_upgrade_scheme') ? hash['proration_upgrade_scheme'] : SKIP
  downgrade_credit =
    hash.key?('downgrade_credit') ? hash['downgrade_credit'] : SKIP
  upgrade_charge =
    hash.key?('upgrade_charge') ? hash['upgrade_charge'] : SKIP
  accrue_charge = hash.key?('accrue_charge') ? hash['accrue_charge'] : SKIP
  initiate_dunning =
    hash.key?('initiate_dunning') ? hash['initiate_dunning'] : SKIP
  price_point_id = hash.key?('price_point_id') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateAllocationPricePointId), hash['price_point_id']
  ) : SKIP
  billing_schedule = BillingSchedule.from_hash(hash['billing_schedule']) if
    hash['billing_schedule']
  custom_price = ComponentCustomPrice.from_hash(hash['custom_price']) if hash['custom_price']

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

  # Create object from extracted values.
  CreateAllocation.new(quantity: quantity,
                       decimal_quantity: decimal_quantity,
                       previous_quantity: previous_quantity,
                       decimal_previous_quantity: decimal_previous_quantity,
                       component_id: component_id,
                       memo: memo,
                       proration_downgrade_scheme: proration_downgrade_scheme,
                       proration_upgrade_scheme: proration_upgrade_scheme,
                       downgrade_credit: downgrade_credit,
                       upgrade_charge: upgrade_charge,
                       accrue_charge: accrue_charge,
                       initiate_dunning: initiate_dunning,
                       price_point_id: price_point_id,
                       billing_schedule: billing_schedule,
                       custom_price: custom_price,
                       additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/advanced_billing/models/create_allocation.rb', line 106

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['quantity'] = 'quantity'
  @_hash['decimal_quantity'] = 'decimal_quantity'
  @_hash['previous_quantity'] = 'previous_quantity'
  @_hash['decimal_previous_quantity'] = 'decimal_previous_quantity'
  @_hash['component_id'] = 'component_id'
  @_hash['memo'] = 'memo'
  @_hash['proration_downgrade_scheme'] = 'proration_downgrade_scheme'
  @_hash['proration_upgrade_scheme'] = 'proration_upgrade_scheme'
  @_hash['downgrade_credit'] = 'downgrade_credit'
  @_hash['upgrade_charge'] = 'upgrade_charge'
  @_hash['accrue_charge'] = 'accrue_charge'
  @_hash['initiate_dunning'] = 'initiate_dunning'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['billing_schedule'] = 'billing_schedule'
  @_hash['custom_price'] = 'custom_price'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    downgrade_credit
    upgrade_charge
    price_point_id
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    decimal_quantity
    previous_quantity
    decimal_previous_quantity
    component_id
    memo
    proration_downgrade_scheme
    proration_upgrade_scheme
    downgrade_credit
    upgrade_charge
    accrue_charge
    initiate_dunning
    price_point_id
    billing_schedule
    custom_price
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



247
248
249
250
251
252
253
254
255
256
257
# File 'lib/advanced_billing/models/create_allocation.rb', line 247

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.quantity,
                                 ->(val) { val.instance_of? Float })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['quantity'],
                        ->(val) { val.instance_of? Float })
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/advanced_billing/models/create_allocation.rb', line 274

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} quantity: #{@quantity.inspect}, decimal_quantity:"\
  " #{@decimal_quantity.inspect}, previous_quantity: #{@previous_quantity.inspect},"\
  " decimal_previous_quantity: #{@decimal_previous_quantity.inspect}, component_id:"\
  " #{@component_id.inspect}, memo: #{@memo.inspect}, proration_downgrade_scheme:"\
  " #{@proration_downgrade_scheme.inspect}, proration_upgrade_scheme:"\
  " #{@proration_upgrade_scheme.inspect}, downgrade_credit: #{@downgrade_credit.inspect},"\
  " upgrade_charge: #{@upgrade_charge.inspect}, accrue_charge: #{@accrue_charge.inspect},"\
  " initiate_dunning: #{@initiate_dunning.inspect}, price_point_id:"\
  " #{@price_point_id.inspect}, billing_schedule: #{@billing_schedule.inspect}, custom_price:"\
  " #{@custom_price.inspect}, additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/advanced_billing/models/create_allocation.rb', line 260

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} quantity: #{@quantity}, decimal_quantity: #{@decimal_quantity},"\
  " previous_quantity: #{@previous_quantity}, decimal_previous_quantity:"\
  " #{@decimal_previous_quantity}, component_id: #{@component_id}, memo: #{@memo},"\
  " proration_downgrade_scheme: #{@proration_downgrade_scheme}, proration_upgrade_scheme:"\
  " #{@proration_upgrade_scheme}, downgrade_credit: #{@downgrade_credit}, upgrade_charge:"\
  " #{@upgrade_charge}, accrue_charge: #{@accrue_charge}, initiate_dunning:"\
  " #{@initiate_dunning}, price_point_id: #{@price_point_id}, billing_schedule:"\
  " #{@billing_schedule}, custom_price: #{@custom_price}, additional_properties:"\
  " #{get_additional_properties}>"
end