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

#to_hash, #to_json

Constructor Details

#initialize(quantity:, component_id: SKIP, memo: SKIP, proration_downgrade_scheme: SKIP, proration_upgrade_scheme: SKIP, accrue_charge: SKIP, downgrade_credit: SKIP, upgrade_charge: SKIP, initiate_dunning: SKIP, price_point_id: SKIP, billing_schedule: SKIP, additional_properties: {}) ⇒ CreateAllocation

Returns a new instance of CreateAllocation.



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

def initialize(quantity:, component_id: SKIP, memo: SKIP,
               proration_downgrade_scheme: SKIP,
               proration_upgrade_scheme: SKIP, accrue_charge: SKIP,
               downgrade_credit: SKIP, upgrade_charge: SKIP,
               initiate_dunning: SKIP, price_point_id: SKIP,
               billing_schedule: SKIP, additional_properties: {})
  @quantity = quantity
  @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
  @accrue_charge = accrue_charge unless accrue_charge == SKIP
  @downgrade_credit = downgrade_credit unless downgrade_credit == SKIP
  @upgrade_charge = upgrade_charge unless upgrade_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

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
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. Defaults to the site setting if one is not provided.

Returns:

  • (TrueClass | FalseClass)


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

def accrue_charge
  @accrue_charge
end

#billing_scheduleBillingSchedule

This attribute is particularly useful when you need to align billing events for different components on distinct schedules within a subscription. Please note this only works for site with Multifrequency enabled

Returns:



74
75
76
# File 'lib/advanced_billing/models/create_allocation.rb', line 74

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)


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

def component_id
  @component_id
end

#downgrade_creditCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Available values: ‘full`, `prorated`, `none`.

Returns:



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

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)


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

def initiate_dunning
  @initiate_dunning
end

#memoString

A memo to record along with the allocation

Returns:

  • (String)


26
27
28
# File 'lib/advanced_billing/models/create_allocation.rb', line 26

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


67
68
69
# File 'lib/advanced_billing/models/create_allocation.rb', line 67

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)


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

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)


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

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_chargeCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Available values: ‘full`, `prorated`, `none`.

Returns:



54
55
56
# File 'lib/advanced_billing/models/create_allocation.rb', line 54

def upgrade_charge
  @upgrade_charge
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  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
  accrue_charge = hash.key?('accrue_charge') ? hash['accrue_charge'] : SKIP
  downgrade_credit =
    hash.key?('downgrade_credit') ? hash['downgrade_credit'] : SKIP
  upgrade_charge =
    hash.key?('upgrade_charge') ? hash['upgrade_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']

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

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

.namesObject

A mapping from model property names to API property names.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/advanced_billing/models/create_allocation.rb', line 77

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

.nullablesObject

An array for nullable fields



110
111
112
113
114
115
116
# File 'lib/advanced_billing/models/create_allocation.rb', line 110

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

.optionalsObject

An array for optional fields



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/advanced_billing/models/create_allocation.rb', line 94

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

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



190
191
192
193
194
195
196
197
198
199
200
# File 'lib/advanced_billing/models/create_allocation.rb', line 190

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