Class: AdvancedBilling::CreateOrUpdateFlatAmountCoupon

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

Overview

CreateOrUpdateFlatAmountCoupon 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 = nil, code = nil, amount_in_cents = nil, description = SKIP, allow_negative_balance = SKIP, recurring = SKIP, end_date = SKIP, product_family_id = SKIP, stackable = SKIP, compounding_strategy = SKIP, exclude_mid_period_allocations = SKIP, apply_on_cancel_at_end_of_period = SKIP) ⇒ CreateOrUpdateFlatAmountCoupon

Returns a new instance of CreateOrUpdateFlatAmountCoupon.



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

def initialize(name = nil, code = nil, amount_in_cents = nil,
               description = SKIP, allow_negative_balance = SKIP,
               recurring = SKIP, end_date = SKIP, product_family_id = SKIP,
               stackable = SKIP, compounding_strategy = SKIP,
               exclude_mid_period_allocations = SKIP,
               apply_on_cancel_at_end_of_period = SKIP)
  @name = name
  @code = code
  @description = description unless description == SKIP
  @amount_in_cents = amount_in_cents
  @allow_negative_balance = allow_negative_balance unless allow_negative_balance == SKIP
  @recurring = recurring unless recurring == SKIP
  @end_date = end_date unless end_date == SKIP
  @product_family_id = product_family_id unless product_family_id == SKIP
  @stackable = stackable unless stackable == SKIP
  @compounding_strategy = compounding_strategy unless compounding_strategy == SKIP
  unless exclude_mid_period_allocations == SKIP
    @exclude_mid_period_allocations =
      exclude_mid_period_allocations
  end
  unless apply_on_cancel_at_end_of_period == SKIP
    @apply_on_cancel_at_end_of_period =
      apply_on_cancel_at_end_of_period
  end
end

Instance Attribute Details

#allow_negative_balanceString

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


38
39
40
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 38

def allow_negative_balance
  @allow_negative_balance
end

#amount_in_centsInteger

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (Integer)


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

def amount_in_cents
  @amount_in_cents
end

#apply_on_cancel_at_end_of_periodTrueClass | FalseClass

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (TrueClass | FalseClass)


80
81
82
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 80

def apply_on_cancel_at_end_of_period
  @apply_on_cancel_at_end_of_period
end

#codeString

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


20
21
22
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 20

def code
  @code
end

#compounding_strategyCompoundingStrategy

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:



68
69
70
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 68

def compounding_strategy
  @compounding_strategy
end

#descriptionString

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


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

def description
  @description
end

#end_dateString

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


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

def end_date
  @end_date
end

#exclude_mid_period_allocationsTrueClass | FalseClass

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (TrueClass | FalseClass)


74
75
76
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 74

def exclude_mid_period_allocations
  @exclude_mid_period_allocations
end

#nameString

the name of the coupon

Returns:

  • (String)


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

def name
  @name
end

#product_family_idString

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


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

def product_family_id
  @product_family_id
end

#recurringString

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


44
45
46
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 44

def recurring
  @recurring
end

#stackableString

may contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


62
63
64
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 62

def stackable
  @stackable
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



149
150
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
182
183
184
185
186
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 149

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  code = hash.key?('code') ? hash['code'] : nil
  amount_in_cents =
    hash.key?('amount_in_cents') ? hash['amount_in_cents'] : nil
  description = hash.key?('description') ? hash['description'] : SKIP
  allow_negative_balance =
    hash.key?('allow_negative_balance') ? hash['allow_negative_balance'] : SKIP
  recurring = hash.key?('recurring') ? hash['recurring'] : SKIP
  end_date = hash.key?('end_date') ? hash['end_date'] : SKIP
  product_family_id =
    hash.key?('product_family_id') ? hash['product_family_id'] : SKIP
  stackable = hash.key?('stackable') ? hash['stackable'] : SKIP
  compounding_strategy = hash.key?('compounding_strategy') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateOrUpdateFlatAmountCouponCompoundingStrategy), hash['compounding_strategy']
  ) : SKIP
  exclude_mid_period_allocations =
    hash.key?('exclude_mid_period_allocations') ? hash['exclude_mid_period_allocations'] : SKIP
  apply_on_cancel_at_end_of_period =
    hash.key?('apply_on_cancel_at_end_of_period') ? hash['apply_on_cancel_at_end_of_period'] : SKIP

  # Create object from extracted values.
  CreateOrUpdateFlatAmountCoupon.new(name,
                                     code,
                                     amount_in_cents,
                                     description,
                                     allow_negative_balance,
                                     recurring,
                                     end_date,
                                     product_family_id,
                                     stackable,
                                     compounding_strategy,
                                     exclude_mid_period_allocations,
                                     apply_on_cancel_at_end_of_period)
end

.namesObject

A mapping from model property names to API property names.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 83

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['code'] = 'code'
  @_hash['description'] = 'description'
  @_hash['amount_in_cents'] = 'amount_in_cents'
  @_hash['allow_negative_balance'] = 'allow_negative_balance'
  @_hash['recurring'] = 'recurring'
  @_hash['end_date'] = 'end_date'
  @_hash['product_family_id'] = 'product_family_id'
  @_hash['stackable'] = 'stackable'
  @_hash['compounding_strategy'] = 'compounding_strategy'
  @_hash['exclude_mid_period_allocations'] =
    'exclude_mid_period_allocations'
  @_hash['apply_on_cancel_at_end_of_period'] =
    'apply_on_cancel_at_end_of_period'
  @_hash
end

.nullablesObject

An array for nullable fields



118
119
120
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 118

def self.nullables
  []
end

.optionalsObject

An array for optional fields



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 103

def self.optionals
  %w[
    description
    allow_negative_balance
    recurring
    end_date
    product_family_id
    stackable
    compounding_strategy
    exclude_mid_period_allocations
    apply_on_cancel_at_end_of_period
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/advanced_billing/models/create_or_update_flat_amount_coupon.rb', line 190

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.name,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.amount_in_cents,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['name'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['code'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['amount_in_cents'],
                            ->(val) { val.instance_of? Integer })
  )
end