Class: AdvancedBilling::CreateOrUpdateProduct

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

Overview

CreateOrUpdateProduct 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(name:, description:, price_in_cents:, interval:, interval_unit:, handle: SKIP, accounting_code: SKIP, require_credit_card: SKIP, trial_price_in_cents: SKIP, trial_interval: SKIP, trial_interval_unit: SKIP, trial_type: SKIP, expiration_interval: SKIP, expiration_interval_unit: SKIP, auto_create_signup_page: SKIP, tax_code: SKIP, unspsc_code: SKIP, additional_properties: {}) ⇒ CreateOrUpdateProduct

Returns a new instance of CreateOrUpdateProduct.



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

def initialize(name:, description:, price_in_cents:, interval:,
               interval_unit:, handle: SKIP, accounting_code: SKIP,
               require_credit_card: SKIP, trial_price_in_cents: SKIP,
               trial_interval: SKIP, trial_interval_unit: SKIP,
               trial_type: SKIP, expiration_interval: SKIP,
               expiration_interval_unit: SKIP,
               auto_create_signup_page: SKIP, tax_code: SKIP,
               unspsc_code: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @name = name
  @handle = handle unless handle == SKIP
  @description = description
  @accounting_code = accounting_code unless accounting_code == SKIP
  @require_credit_card = require_credit_card unless require_credit_card == SKIP
  @price_in_cents = price_in_cents
  @interval = interval
  @interval_unit = interval_unit
  @trial_price_in_cents = trial_price_in_cents unless trial_price_in_cents == SKIP
  @trial_interval = trial_interval unless trial_interval == SKIP
  @trial_interval_unit = trial_interval_unit unless trial_interval_unit == SKIP
  @trial_type = trial_type unless trial_type == SKIP
  @expiration_interval = expiration_interval unless expiration_interval == SKIP
  @expiration_interval_unit = expiration_interval_unit unless expiration_interval_unit == SKIP
  @auto_create_signup_page =  unless  == SKIP
  @tax_code = tax_code unless tax_code == SKIP
  @unspsc_code = unspsc_code unless unspsc_code == SKIP
end

Instance Attribute Details

#accounting_codeString

E.g. Internal ID or SKU Number

Returns:

  • (String)


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

def accounting_code
  @accounting_code
end

#auto_create_signup_pageTrueClass | FalseClass

A string representing the expiration interval unit for this product, either month, day or never

Returns:

  • (TrueClass | FalseClass)


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

def 
  @auto_create_signup_page
end

#descriptionString

The product description

Returns:

  • (String)


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

def description
  @description
end

#expiration_intervalInteger

The numerical expiration interval. e.g., an expiration_interval of ‘30’ coupled with an expiration_interval_unit of day would mean this product would expire after 30 days.

Returns:

  • (Integer)


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

def expiration_interval
  @expiration_interval
end

#expiration_interval_unitExpirationIntervalUnit

A string representing the expiration interval unit for this product, either month, day or never



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

def expiration_interval_unit
  @expiration_interval_unit
end

#handleString

The product API handle

Returns:

  • (String)


18
19
20
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 18

def handle
  @handle
end

#intervalInteger

The numerical interval. e.g., an interval of ‘30’ coupled with an interval_unit of day would mean this product would renew every 30 days.

Returns:

  • (Integer)


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

def interval
  @interval
end

#interval_unitIntervalUnit

A string representing the interval unit for this product, either month or day

Returns:



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

def interval_unit
  @interval_unit
end

#nameString

The product name

Returns:

  • (String)


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

def name
  @name
end

#price_in_centsInteger

The product price, in integer cents

Returns:

  • (Integer)


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

def price_in_cents
  @price_in_cents
end

#require_credit_cardTrueClass | FalseClass

Deprecated value that can be ignored unless you have legacy hosted pages. For Public Signup Page users, read this attribute from under the signup page.

Returns:

  • (TrueClass | FalseClass)


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

def require_credit_card
  @require_credit_card
end

#tax_codeString

A string representing the tax code related to the product type. This is especially important when using AvaTax to tax based on locale. This attribute has a max length of 25 characters.

Returns:

  • (String)


92
93
94
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 92

def tax_code
  @tax_code
end

#trial_intervalInteger

The numerical trial interval. e.g., an interval of ‘30’ coupled with a trial_interval_unit of day would mean this product trial would last 30 days.

Returns:

  • (Integer)


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

def trial_interval
  @trial_interval
end

#trial_interval_unitIntervalUnit

A string representing the trial interval unit for this product, either month or day

Returns:



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

def trial_interval_unit
  @trial_interval_unit
end

#trial_price_in_centsInteger

The product trial price, in integer cents

Returns:

  • (Integer)


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

def trial_price_in_cents
  @trial_price_in_cents
end

#trial_typeTrialType

Indicates how a trial is handled when the trial period ends and there is no credit card on file. For no_obligation, the subscription transitions to a Trial Ended state. Maxio will not send any emails or statements. For payment_expected, the subscription transitions to a Past Due state. Maxio will send normal dunning emails and statements according to your other settings.

Returns:



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

def trial_type
  @trial_type
end

#unspsc_codeString

(Optional) Custom UNSPSC commodity code for Level 3/CEDP payment data. When set, this value is sent as the commodity code on invoice line items for this product instead of the default derived from item_category.

Returns:

  • (String)


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

def unspsc_code
  @unspsc_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 184

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  price_in_cents =
    hash.key?('price_in_cents') ? hash['price_in_cents'] : nil
  interval = hash.key?('interval') ? hash['interval'] : nil
  interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : nil
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  accounting_code =
    hash.key?('accounting_code') ? hash['accounting_code'] : SKIP
  require_credit_card =
    hash.key?('require_credit_card') ? hash['require_credit_card'] : SKIP
  trial_price_in_cents =
    hash.key?('trial_price_in_cents') ? hash['trial_price_in_cents'] : SKIP
  trial_interval =
    hash.key?('trial_interval') ? hash['trial_interval'] : SKIP
  trial_interval_unit =
    hash.key?('trial_interval_unit') ? hash['trial_interval_unit'] : SKIP
  trial_type = hash.key?('trial_type') ? hash['trial_type'] : SKIP
  expiration_interval =
    hash.key?('expiration_interval') ? hash['expiration_interval'] : SKIP
  expiration_interval_unit =
    hash.key?('expiration_interval_unit') ? hash['expiration_interval_unit'] : SKIP
   =
    hash.key?('auto_create_signup_page') ? hash['auto_create_signup_page'] : SKIP
  tax_code = hash.key?('tax_code') ? hash['tax_code'] : SKIP
  unspsc_code = hash.key?('unspsc_code') ? hash['unspsc_code'] : SKIP

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

  # Create object from extracted values.
  CreateOrUpdateProduct.new(name: name,
                            description: description,
                            price_in_cents: price_in_cents,
                            interval: interval,
                            interval_unit: interval_unit,
                            handle: handle,
                            accounting_code: accounting_code,
                            require_credit_card: require_credit_card,
                            trial_price_in_cents: trial_price_in_cents,
                            trial_interval: trial_interval,
                            trial_interval_unit: trial_interval_unit,
                            trial_type: trial_type,
                            expiration_interval: expiration_interval,
                            expiration_interval_unit: expiration_interval_unit,
                            auto_create_signup_page: ,
                            tax_code: tax_code,
                            unspsc_code: unspsc_code,
                            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 101

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_hash['description'] = 'description'
  @_hash['accounting_code'] = 'accounting_code'
  @_hash['require_credit_card'] = 'require_credit_card'
  @_hash['price_in_cents'] = 'price_in_cents'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash['trial_price_in_cents'] = 'trial_price_in_cents'
  @_hash['trial_interval'] = 'trial_interval'
  @_hash['trial_interval_unit'] = 'trial_interval_unit'
  @_hash['trial_type'] = 'trial_type'
  @_hash['expiration_interval'] = 'expiration_interval'
  @_hash['expiration_interval_unit'] = 'expiration_interval_unit'
  @_hash['auto_create_signup_page'] = 'auto_create_signup_page'
  @_hash['tax_code'] = 'tax_code'
  @_hash['unspsc_code'] = 'unspsc_code'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    trial_interval_unit
    trial_type
    expiration_interval_unit
    unspsc_code
  ]
end

.optionalsObject

An array for optional fields



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 124

def self.optionals
  %w[
    handle
    accounting_code
    require_credit_card
    trial_price_in_cents
    trial_interval
    trial_interval_unit
    trial_type
    expiration_interval
    expiration_interval_unit
    auto_create_signup_page
    tax_code
    unspsc_code
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 254

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name.inspect}, handle: #{@handle.inspect}, description:"\
  " #{@description.inspect}, accounting_code: #{@accounting_code.inspect},"\
  " require_credit_card: #{@require_credit_card.inspect}, price_in_cents:"\
  " #{@price_in_cents.inspect}, interval: #{@interval.inspect}, interval_unit:"\
  " #{@interval_unit.inspect}, trial_price_in_cents: #{@trial_price_in_cents.inspect},"\
  " trial_interval: #{@trial_interval.inspect}, trial_interval_unit:"\
  " #{@trial_interval_unit.inspect}, trial_type: #{@trial_type.inspect}, expiration_interval:"\
  " #{@expiration_interval.inspect}, expiration_interval_unit:"\
  " #{@expiration_interval_unit.inspect}, auto_create_signup_page:"\
  " #{@auto_create_signup_page.inspect}, tax_code: #{@tax_code.inspect}, unspsc_code:"\
  " #{@unspsc_code.inspect}, additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 240

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, handle: #{@handle}, description: #{@description},"\
  " accounting_code: #{@accounting_code}, require_credit_card: #{@require_credit_card},"\
  " price_in_cents: #{@price_in_cents}, interval: #{@interval}, interval_unit:"\
  " #{@interval_unit}, trial_price_in_cents: #{@trial_price_in_cents}, trial_interval:"\
  " #{@trial_interval}, trial_interval_unit: #{@trial_interval_unit}, trial_type:"\
  " #{@trial_type}, expiration_interval: #{@expiration_interval}, expiration_interval_unit:"\
  " #{@expiration_interval_unit}, auto_create_signup_page: #{@auto_create_signup_page},"\
  " tax_code: #{@tax_code}, unspsc_code: #{@unspsc_code}, additional_properties:"\
  " #{get_additional_properties}>"
end