Class: ApiReference::TrialDiscount

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

Overview

TrialDiscount Model.

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(applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, trial_amount_discount: SKIP, trial_percentage_discount: SKIP, additional_properties: nil) ⇒ TrialDiscount

Returns a new instance of TrialDiscount.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/api_reference/models/trial_discount.rb', line 71

def initialize(applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP,
               trial_amount_discount: SKIP, trial_percentage_discount: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @discount_type = 'trial'
  @applies_to_price_ids = applies_to_price_ids unless applies_to_price_ids == SKIP
  @filters = filters unless filters == SKIP
  @reason = reason unless reason == SKIP
  @trial_amount_discount = trial_amount_discount unless trial_amount_discount == SKIP
  unless trial_percentage_discount == SKIP
    @trial_percentage_discount =
      trial_percentage_discount
  end
  @additional_properties = additional_properties
end

Instance Attribute Details

#applies_to_price_idsArray[String]

List of price_ids that this discount applies to. For plan/plan phase discounts, this can be a subset of prices.

Returns:

  • (Array[String])


19
20
21
# File 'lib/api_reference/models/trial_discount.rb', line 19

def applies_to_price_ids
  @applies_to_price_ids
end

#discount_typeString (readonly)

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/api_reference/models/trial_discount.rb', line 14

def discount_type
  @discount_type
end

#filtersArray[PriceFilter]

The filters that determine which prices to apply this discount to.

Returns:



23
24
25
# File 'lib/api_reference/models/trial_discount.rb', line 23

def filters
  @filters
end

#reasonString

The filters that determine which prices to apply this discount to.

Returns:

  • (String)


27
28
29
# File 'lib/api_reference/models/trial_discount.rb', line 27

def reason
  @reason
end

#trial_amount_discountString

Only available if discount_type is trial

Returns:

  • (String)


31
32
33
# File 'lib/api_reference/models/trial_discount.rb', line 31

def trial_amount_discount
  @trial_amount_discount
end

#trial_percentage_discountFloat

Only available if discount_type is trial

Returns:

  • (Float)


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

def trial_percentage_discount
  @trial_percentage_discount
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/api_reference/models/trial_discount.rb', line 90

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  applies_to_price_ids =
    hash.key?('applies_to_price_ids') ? hash['applies_to_price_ids'] : SKIP
  # Parameter is an array, so we need to iterate through it
  filters = nil
  unless hash['filters'].nil?
    filters = []
    hash['filters'].each do |structure|
      filters << (PriceFilter.from_hash(structure) if structure)
    end
  end

  filters = SKIP unless hash.key?('filters')
  reason = hash.key?('reason') ? hash['reason'] : SKIP
  trial_amount_discount =
    hash.key?('trial_amount_discount') ? hash['trial_amount_discount'] : SKIP
  trial_percentage_discount =
    hash.key?('trial_percentage_discount') ? hash['trial_percentage_discount'] : SKIP

  # 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.
  TrialDiscount.new(applies_to_price_ids: applies_to_price_ids,
                    filters: filters,
                    reason: reason,
                    trial_amount_discount: trial_amount_discount,
                    trial_percentage_discount: trial_percentage_discount,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



38
39
40
41
42
43
44
45
46
47
# File 'lib/api_reference/models/trial_discount.rb', line 38

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['discount_type'] = 'discount_type'
  @_hash['applies_to_price_ids'] = 'applies_to_price_ids'
  @_hash['filters'] = 'filters'
  @_hash['reason'] = 'reason'
  @_hash['trial_amount_discount'] = 'trial_amount_discount'
  @_hash['trial_percentage_discount'] = 'trial_percentage_discount'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
64
65
66
67
68
69
# File 'lib/api_reference/models/trial_discount.rb', line 61

def self.nullables
  %w[
    applies_to_price_ids
    filters
    reason
    trial_amount_discount
    trial_percentage_discount
  ]
end

.optionalsObject

An array for optional fields



50
51
52
53
54
55
56
57
58
# File 'lib/api_reference/models/trial_discount.rb', line 50

def self.optionals
  %w[
    applies_to_price_ids
    filters
    reason
    trial_amount_discount
    trial_percentage_discount
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (TrialDiscount | Hash)

    value against the validation is performed.



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/api_reference/models/trial_discount.rb', line 130

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.discount_type,
                                 ->(val) { val.instance_of? String })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['discount_type'],
                        ->(val) { val.instance_of? String })
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



152
153
154
155
156
157
158
159
# File 'lib/api_reference/models/trial_discount.rb', line 152

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_type: #{@discount_type.inspect}, applies_to_price_ids:"\
  " #{@applies_to_price_ids.inspect}, filters: #{@filters.inspect}, reason:"\
  " #{@reason.inspect}, trial_amount_discount: #{@trial_amount_discount.inspect},"\
  " trial_percentage_discount: #{@trial_percentage_discount.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



143
144
145
146
147
148
149
# File 'lib/api_reference/models/trial_discount.rb', line 143

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_type: #{@discount_type}, applies_to_price_ids:"\
  " #{@applies_to_price_ids}, filters: #{@filters}, reason: #{@reason}, trial_amount_discount:"\
  " #{@trial_amount_discount}, trial_percentage_discount: #{@trial_percentage_discount},"\
  " additional_properties: #{@additional_properties}>"
end