Class: AdvancedBilling::CreateProductPricePoint

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

Overview

CreateProductPricePoint 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:, price_in_cents:, interval:, interval_unit:, handle: SKIP, trial_price_in_cents: SKIP, trial_interval: SKIP, trial_interval_unit: SKIP, trial_type: SKIP, initial_charge_in_cents: SKIP, initial_charge_after_trial: SKIP, expiration_interval: SKIP, expiration_interval_unit: SKIP, use_site_exchange_rate: true, additional_properties: {}) ⇒ CreateProductPricePoint

Returns a new instance of CreateProductPricePoint.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 122

def initialize(name:, price_in_cents:, interval:, interval_unit:,
               handle: SKIP, trial_price_in_cents: SKIP,
               trial_interval: SKIP, trial_interval_unit: SKIP,
               trial_type: SKIP, initial_charge_in_cents: SKIP,
               initial_charge_after_trial: SKIP, expiration_interval: SKIP,
               expiration_interval_unit: SKIP, use_site_exchange_rate: true,
               additional_properties: {})
  @name = name
  @handle = handle unless handle == 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
  @initial_charge_in_cents = initial_charge_in_cents unless initial_charge_in_cents == SKIP
  unless initial_charge_after_trial == SKIP
    @initial_charge_after_trial =
      initial_charge_after_trial
  end
  @expiration_interval = expiration_interval unless expiration_interval == SKIP
  @expiration_interval_unit = expiration_interval_unit unless expiration_interval_unit == SKIP
  @use_site_exchange_rate = use_site_exchange_rate unless use_site_exchange_rate == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#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 price point would expire after 30 days.

Returns:

  • (Integer)


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

def expiration_interval
  @expiration_interval
end

#expiration_interval_unitExpirationIntervalUnit

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



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

def expiration_interval_unit
  @expiration_interval_unit
end

#handleString

The product price point API handle

Returns:

  • (String)


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

def handle
  @handle
end

#initial_charge_after_trialTrueClass | FalseClass

The product price point initial charge, in integer cents

Returns:

  • (TrueClass | FalseClass)


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

def initial_charge_after_trial
  @initial_charge_after_trial
end

#initial_charge_in_centsInteger

The product price point initial charge, in integer cents

Returns:

  • (Integer)


57
58
59
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 57

def initial_charge_in_cents
  @initial_charge_in_cents
end

#intervalInteger

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

Returns:

  • (Integer)


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

def interval
  @interval
end

#interval_unitIntervalUnit

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

Returns:



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

def interval_unit
  @interval_unit
end

#nameString

The product price point name

Returns:

  • (String)


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

def name
  @name
end

#price_in_centsInteger

The product price point price, in integer cents

Returns:

  • (Integer)


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

def price_in_cents
  @price_in_cents
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 price point trial would last 30 days.

Returns:

  • (Integer)


43
44
45
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 43

def trial_interval
  @trial_interval
end

#trial_interval_unitIntervalUnit

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

Returns:



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

def trial_interval_unit
  @trial_interval_unit
end

#trial_price_in_centsInteger

The product price point trial price, in integer cents

Returns:

  • (Integer)


37
38
39
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 37

def trial_price_in_cents
  @trial_price_in_cents
end

#trial_typeString

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

Returns:

  • (String)


53
54
55
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 53

def trial_type
  @trial_type
end

#use_site_exchange_rateTrueClass | FalseClass

Whether or not to use the site’s exchange rate or define your own pricing when your site has multiple currencies defined.

Returns:

  • (TrueClass | FalseClass)


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

def use_site_exchange_rate
  @use_site_exchange_rate
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
192
193
194
195
196
197
198
199
200
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 154

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : 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
  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
  initial_charge_in_cents =
    hash.key?('initial_charge_in_cents') ? hash['initial_charge_in_cents'] : SKIP
  initial_charge_after_trial =
    hash.key?('initial_charge_after_trial') ? hash['initial_charge_after_trial'] : SKIP
  expiration_interval =
    hash.key?('expiration_interval') ? hash['expiration_interval'] : SKIP
  expiration_interval_unit =
    hash.key?('expiration_interval_unit') ? hash['expiration_interval_unit'] : SKIP
  use_site_exchange_rate = hash['use_site_exchange_rate'] ||= true

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

  # Create object from extracted values.
  CreateProductPricePoint.new(name: name,
                              price_in_cents: price_in_cents,
                              interval: interval,
                              interval_unit: interval_unit,
                              handle: handle,
                              trial_price_in_cents: trial_price_in_cents,
                              trial_interval: trial_interval,
                              trial_interval_unit: trial_interval_unit,
                              trial_type: trial_type,
                              initial_charge_in_cents: initial_charge_in_cents,
                              initial_charge_after_trial: initial_charge_after_trial,
                              expiration_interval: expiration_interval,
                              expiration_interval_unit: expiration_interval_unit,
                              use_site_exchange_rate: use_site_exchange_rate,
                              additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 80

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_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['initial_charge_in_cents'] = 'initial_charge_in_cents'
  @_hash['initial_charge_after_trial'] = 'initial_charge_after_trial'
  @_hash['expiration_interval'] = 'expiration_interval'
  @_hash['expiration_interval_unit'] = 'expiration_interval_unit'
  @_hash['use_site_exchange_rate'] = 'use_site_exchange_rate'
  @_hash
end

.nullablesObject

An array for nullable fields



116
117
118
119
120
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 116

def self.nullables
  %w[
    expiration_interval_unit
  ]
end

.optionalsObject

An array for optional fields



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/advanced_billing/models/create_product_price_point.rb', line 100

def self.optionals
  %w[
    handle
    trial_price_in_cents
    trial_interval
    trial_interval_unit
    trial_type
    initial_charge_in_cents
    initial_charge_after_trial
    expiration_interval
    expiration_interval_unit
    use_site_exchange_rate
  ]
end