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

#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, additional_properties: {}) ⇒ CreateOrUpdateProduct

Returns a new instance of CreateOrUpdateProduct.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 137

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,
               additional_properties: {})
  @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

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


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

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. i.e. an expiration_interval of ‘30’ coupled with an expiration_interval_unit of day would mean this product would expire after 30 days.

Returns:

  • (Integer)


72
73
74
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 72

def expiration_interval
  @expiration_interval
end

#expiration_interval_unitExpirationIntervalUnit

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



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

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. i.e. 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, please 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 the Avalara service to tax based on locale. This attribute has a max length of 10 characters.

Returns:

  • (String)


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

def tax_code
  @tax_code
end

#trial_intervalInteger

The numerical trial interval. i.e. 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_typeString

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

Returns:

  • (String)


66
67
68
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 66

def trial_type
  @trial_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



169
170
171
172
173
174
175
176
177
178
179
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 169

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

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(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,
                            additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 91

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
end

.nullablesObject

An array for nullable fields



130
131
132
133
134
135
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 130

def self.nullables
  %w[
    trial_interval_unit
    expiration_interval_unit
  ]
end

.optionalsObject

An array for optional fields



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/advanced_billing/models/create_or_update_product.rb', line 113

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