Class: ApiReference::Plan

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/plan.rb

Overview

The Plan resource represents a plan that can be subscribed to by a customer. Plans define the billing behavior of the subscription. You can see more about how to configure prices in the Price resource.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(metadata:, id:, name:, description:, maximum_amount:, minimum_amount:, created_at:, status:, maximum:, minimum:, discount:, product:, version:, trial_config:, plan_phases:, base_plan:, base_plan_id:, external_plan_id:, currency:, invoicing_currency:, net_terms:, default_invoice_memo:, prices:, adjustments:, additional_properties: nil) ⇒ Plan

Returns a new instance of Plan.



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/api_reference/models/plan.rb', line 222

def initialize(metadata:, id:, name:, description:, maximum_amount:,
               minimum_amount:, created_at:, status:, maximum:, minimum:,
               discount:, product:, version:, trial_config:, plan_phases:,
               base_plan:, base_plan_id:, external_plan_id:, currency:,
               invoicing_currency:, net_terms:, default_invoice_memo:,
               prices:, adjustments:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @metadata = 
  @id = id
  @name = name
  @description = description
  @maximum_amount = maximum_amount
  @minimum_amount = minimum_amount
  @created_at = created_at
  @status = status
  @maximum = maximum
  @minimum = minimum
  @discount = discount
  @product = product
  @version = version
  @trial_config = trial_config
  @plan_phases = plan_phases
  @base_plan = base_plan
  @base_plan_id = base_plan_id
  @external_plan_id = external_plan_id
  @currency = currency
  @invoicing_currency = invoicing_currency
  @net_terms = net_terms
  @default_invoice_memo = default_invoice_memo
  @prices = prices
  @adjustments = adjustments
  @additional_properties = additional_properties
end

Instance Attribute Details

#adjustmentsArray[Object]

Adjustments for this plan. If the plan has phases, this includes adjustments across all phases of the plan.

Returns:

  • (Array[Object])


168
169
170
# File 'lib/api_reference/models/plan.rb', line 168

def adjustments
  @adjustments
end

#base_planPlanMinified

Legacy field representing the parent plan if the current plan is a 'child plan', overriding prices from the parent.

Returns:



124
125
126
# File 'lib/api_reference/models/plan.rb', line 124

def base_plan
  @base_plan
end

#base_plan_idString

Legacy field representing the parent plan ID if the current plan is a 'child plan', overriding prices from the parent.

Returns:

  • (String)


129
130
131
# File 'lib/api_reference/models/plan.rb', line 129

def base_plan_id
  @base_plan_id
end

#created_atDateTime

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (DateTime)


63
64
65
# File 'lib/api_reference/models/plan.rb', line 63

def created_at
  @created_at
end

#currencyString

An ISO 4217 currency string or custom pricing unit (credits) for this plan's prices.

Returns:

  • (String)


140
141
142
# File 'lib/api_reference/models/plan.rb', line 140

def currency
  @currency
end

#default_invoice_memoString

The default memo text on the invoices corresponding to subscriptions on this plan. Note that each subscription may configure its own memo.

Returns:

  • (String)


158
159
160
# File 'lib/api_reference/models/plan.rb', line 158

def default_invoice_memo
  @default_invoice_memo
end

#descriptionString

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (String)


42
43
44
# File 'lib/api_reference/models/plan.rb', line 42

def description
  @description
end

#discountObject

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (Object)


91
92
93
# File 'lib/api_reference/models/plan.rb', line 91

def discount
  @discount
end

#external_plan_idString

An optional user-defined ID for this plan resource, used throughout the system as an alias for this Plan. Use this field to identify a plan by an existing identifier in your system.

Returns:

  • (String)


135
136
137
# File 'lib/api_reference/models/plan.rb', line 135

def external_plan_id
  @external_plan_id
end

#idString

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (String)


28
29
30
# File 'lib/api_reference/models/plan.rb', line 28

def id
  @id
end

#invoicing_currencyString

An ISO 4217 currency string for which this plan is billed in. Matches currency unless currency is a custom pricing unit.

Returns:

  • (String)


145
146
147
# File 'lib/api_reference/models/plan.rb', line 145

def invoicing_currency
  @invoicing_currency
end

#maximumMaximum

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



77
78
79
# File 'lib/api_reference/models/plan.rb', line 77

def maximum
  @maximum
end

#maximum_amountString

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (String)


49
50
51
# File 'lib/api_reference/models/plan.rb', line 49

def maximum_amount
  @maximum_amount
end

#metadataHash[String, String]

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (Hash[String, String])


21
22
23
# File 'lib/api_reference/models/plan.rb', line 21

def 
  @metadata
end

#minimumMinimum

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



84
85
86
# File 'lib/api_reference/models/plan.rb', line 84

def minimum
  @minimum
end

#minimum_amountString

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (String)


56
57
58
# File 'lib/api_reference/models/plan.rb', line 56

def minimum_amount
  @minimum_amount
end

#nameString

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (String)


35
36
37
# File 'lib/api_reference/models/plan.rb', line 35

def name
  @name
end

#net_termsInteger

Determines the difference between the invoice issue date and the due date. A value of "0" here signifies that invoices are due on issue, whereas a value of "30" means that the customer has a month to pay the invoice before its overdue. Note that individual subscriptions or invoices may set a different net terms configuration.

Returns:

  • (Integer)


153
154
155
# File 'lib/api_reference/models/plan.rb', line 153

def net_terms
  @net_terms
end

#plan_phasesArray[PlanPhase]

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



119
120
121
# File 'lib/api_reference/models/plan.rb', line 119

def plan_phases
  @plan_phases
end

#pricesArray[Object]

Prices for this plan. If the plan has phases, this includes prices across all phases of the plan.

Returns:

  • (Array[Object])


163
164
165
# File 'lib/api_reference/models/plan.rb', line 163

def prices
  @prices
end

#productProduct

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



98
99
100
# File 'lib/api_reference/models/plan.rb', line 98

def product
  @product
end

#statusStatus

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



70
71
72
# File 'lib/api_reference/models/plan.rb', line 70

def status
  @status
end

#trial_configTrialConfig

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



112
113
114
# File 'lib/api_reference/models/plan.rb', line 112

def trial_config
  @trial_config
end

#versionInteger

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (Integer)


105
106
107
# File 'lib/api_reference/models/plan.rb', line 105

def version
  @version
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/api_reference/models/plan.rb', line 259

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
   = hash.key?('metadata') ? hash['metadata'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  maximum_amount =
    hash.key?('maximum_amount') ? hash['maximum_amount'] : nil
  minimum_amount =
    hash.key?('minimum_amount') ? hash['minimum_amount'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  status = hash.key?('status') ? hash['status'] : nil
  maximum = Maximum.from_hash(hash['maximum']) if hash['maximum']
  minimum = Minimum.from_hash(hash['minimum']) if hash['minimum']
  discount = hash.key?('discount') ? hash['discount'] : nil
  product = Product.from_hash(hash['product']) if hash['product']
  version = hash.key?('version') ? hash['version'] : nil
  trial_config = TrialConfig.from_hash(hash['trial_config']) if hash['trial_config']
  # Parameter is an array, so we need to iterate through it
  plan_phases = nil
  unless hash['plan_phases'].nil?
    plan_phases = []
    hash['plan_phases'].each do |structure|
      plan_phases << (PlanPhase.from_hash(structure) if structure)
    end
  end

  plan_phases = nil unless hash.key?('plan_phases')
  base_plan = PlanMinified.from_hash(hash['base_plan']) if hash['base_plan']
  base_plan_id = hash.key?('base_plan_id') ? hash['base_plan_id'] : nil
  external_plan_id =
    hash.key?('external_plan_id') ? hash['external_plan_id'] : nil
  currency = hash.key?('currency') ? hash['currency'] : nil
  invoicing_currency =
    hash.key?('invoicing_currency') ? hash['invoicing_currency'] : nil
  net_terms = hash.key?('net_terms') ? hash['net_terms'] : nil
  default_invoice_memo =
    hash.key?('default_invoice_memo') ? hash['default_invoice_memo'] : nil
  prices = hash.key?('prices') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Price2), hash['prices']
  ) : nil
  adjustments = hash.key?('adjustments') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Adjustment2), hash['adjustments']
  ) : nil

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Plan.new(metadata: ,
           id: id,
           name: name,
           description: description,
           maximum_amount: maximum_amount,
           minimum_amount: minimum_amount,
           created_at: created_at,
           status: status,
           maximum: maximum,
           minimum: minimum,
           discount: discount,
           product: product,
           version: version,
           trial_config: trial_config,
           plan_phases: plan_phases,
           base_plan: base_plan,
           base_plan_id: base_plan_id,
           external_plan_id: external_plan_id,
           currency: currency,
           invoicing_currency: invoicing_currency,
           net_terms: net_terms,
           default_invoice_memo: default_invoice_memo,
           prices: prices,
           adjustments: adjustments,
           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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
# File 'lib/api_reference/models/plan.rb', line 171

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['metadata'] = 'metadata'
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['description'] = 'description'
  @_hash['maximum_amount'] = 'maximum_amount'
  @_hash['minimum_amount'] = 'minimum_amount'
  @_hash['created_at'] = 'created_at'
  @_hash['status'] = 'status'
  @_hash['maximum'] = 'maximum'
  @_hash['minimum'] = 'minimum'
  @_hash['discount'] = 'discount'
  @_hash['product'] = 'product'
  @_hash['version'] = 'version'
  @_hash['trial_config'] = 'trial_config'
  @_hash['plan_phases'] = 'plan_phases'
  @_hash['base_plan'] = 'base_plan'
  @_hash['base_plan_id'] = 'base_plan_id'
  @_hash['external_plan_id'] = 'external_plan_id'
  @_hash['currency'] = 'currency'
  @_hash['invoicing_currency'] = 'invoicing_currency'
  @_hash['net_terms'] = 'net_terms'
  @_hash['default_invoice_memo'] = 'default_invoice_memo'
  @_hash['prices'] = 'prices'
  @_hash['adjustments'] = 'adjustments'
  @_hash
end

.nullablesObject

An array for nullable fields



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/api_reference/models/plan.rb', line 206

def self.nullables
  %w[
    maximum_amount
    minimum_amount
    maximum
    minimum
    discount
    plan_phases
    base_plan
    base_plan_id
    external_plan_id
    net_terms
    default_invoice_memo
  ]
end

.optionalsObject

An array for optional fields



201
202
203
# File 'lib/api_reference/models/plan.rb', line 201

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Plan | Hash)

    value against the validation is performed.



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/api_reference/models/plan.rb', line 349

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.name,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.description,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.maximum_amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.minimum_amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.status,
                              ->(val) { Status.validate(val) }) and
        APIHelper.valid_type?(value.maximum,
                              ->(val) { Maximum.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.minimum,
                              ->(val) { Minimum.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.discount,
                              ->(val) { val.instance_of? Object }) and
        APIHelper.valid_type?(value.product,
                              ->(val) { Product.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.version,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.trial_config,
                              ->(val) { TrialConfig.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.plan_phases,
                              ->(val) { PlanPhase.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) and
        APIHelper.valid_type?(value.base_plan,
                              ->(val) { PlanMinified.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.base_plan_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.external_plan_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.currency,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.invoicing_currency,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.net_terms,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.default_invoice_memo,
                              ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:Price2)
                       .validate(value.prices) and
        UnionTypeLookUp.get(:Adjustment2)
                       .validate(value.adjustments)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['metadata'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['name'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['description'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['maximum_amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['minimum_amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['status'],
                            ->(val) { Status.validate(val) }) and
      APIHelper.valid_type?(value['maximum'],
                            ->(val) { Maximum.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['minimum'],
                            ->(val) { Minimum.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['discount'],
                            ->(val) { val.instance_of? Object }) and
      APIHelper.valid_type?(value['product'],
                            ->(val) { Product.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['version'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['trial_config'],
                            ->(val) { TrialConfig.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['plan_phases'],
                            ->(val) { PlanPhase.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
      APIHelper.valid_type?(value['base_plan'],
                            ->(val) { PlanMinified.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['base_plan_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['external_plan_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['currency'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['invoicing_currency'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['net_terms'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['default_invoice_memo'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:Price2)
                     .validate(value['prices']) and
      UnionTypeLookUp.get(:Adjustment2)
                     .validate(value['adjustments'])
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/api_reference/models/plan.rb', line 486

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata.inspect}, id: #{@id.inspect}, name: #{@name.inspect},"\
  " description: #{@description.inspect}, maximum_amount: #{@maximum_amount.inspect},"\
  " minimum_amount: #{@minimum_amount.inspect}, created_at: #{@created_at.inspect}, status:"\
  " #{@status.inspect}, maximum: #{@maximum.inspect}, minimum: #{@minimum.inspect}, discount:"\
  " #{@discount.inspect}, product: #{@product.inspect}, version: #{@version.inspect},"\
  " trial_config: #{@trial_config.inspect}, plan_phases: #{@plan_phases.inspect}, base_plan:"\
  " #{@base_plan.inspect}, base_plan_id: #{@base_plan_id.inspect}, external_plan_id:"\
  " #{@external_plan_id.inspect}, currency: #{@currency.inspect}, invoicing_currency:"\
  " #{@invoicing_currency.inspect}, net_terms: #{@net_terms.inspect}, default_invoice_memo:"\
  " #{@default_invoice_memo.inspect}, prices: #{@prices.inspect}, adjustments:"\
  " #{@adjustments.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_created_atObject



343
344
345
# File 'lib/api_reference/models/plan.rb', line 343

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_sObject

Provides a human-readable string representation of the object.



472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/api_reference/models/plan.rb', line 472

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata}, id: #{@id}, name: #{@name}, description:"\
  " #{@description}, maximum_amount: #{@maximum_amount}, minimum_amount: #{@minimum_amount},"\
  " created_at: #{@created_at}, status: #{@status}, maximum: #{@maximum}, minimum:"\
  " #{@minimum}, discount: #{@discount}, product: #{@product}, version: #{@version},"\
  " trial_config: #{@trial_config}, plan_phases: #{@plan_phases}, base_plan: #{@base_plan},"\
  " base_plan_id: #{@base_plan_id}, external_plan_id: #{@external_plan_id}, currency:"\
  " #{@currency}, invoicing_currency: #{@invoicing_currency}, net_terms: #{@net_terms},"\
  " default_invoice_memo: #{@default_invoice_memo}, prices: #{@prices}, adjustments:"\
  " #{@adjustments}, additional_properties: #{@additional_properties}>"
end