Class: AdvancedBilling::Coupon

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

Overview

Coupon Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id = SKIP, name = SKIP, code = SKIP, description = SKIP, amount = SKIP, amount_in_cents = SKIP, product_family_id = SKIP, product_family_name = SKIP, start_date = SKIP, end_date = SKIP, percentage = SKIP, recurring = SKIP, recurring_scheme = SKIP, duration_period_count = SKIP, duration_interval = SKIP, duration_interval_unit = SKIP, duration_interval_span = SKIP, allow_negative_balance = SKIP, archived_at = SKIP, conversion_limit = SKIP, stackable = SKIP, compounding_strategy = SKIP, use_site_exchange_rate = SKIP, created_at = SKIP, updated_at = SKIP, discount_type = SKIP, exclude_mid_period_allocations = SKIP, apply_on_cancel_at_end_of_period = SKIP, coupon_restrictions = SKIP) ⇒ Coupon

Returns a new instance of Coupon.



215
216
217
218
219
220
221
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
257
258
259
260
261
262
263
264
# File 'lib/advanced_billing/models/coupon.rb', line 215

def initialize(id = SKIP, name = SKIP, code = SKIP, description = SKIP,
               amount = SKIP, amount_in_cents = SKIP,
               product_family_id = SKIP, product_family_name = SKIP,
               start_date = SKIP, end_date = SKIP, percentage = SKIP,
               recurring = SKIP, recurring_scheme = SKIP,
               duration_period_count = SKIP, duration_interval = SKIP,
               duration_interval_unit = SKIP, duration_interval_span = SKIP,
               allow_negative_balance = SKIP, archived_at = SKIP,
               conversion_limit = SKIP, stackable = SKIP,
               compounding_strategy = SKIP, use_site_exchange_rate = SKIP,
               created_at = SKIP, updated_at = SKIP, discount_type = SKIP,
               exclude_mid_period_allocations = SKIP,
               apply_on_cancel_at_end_of_period = SKIP,
               coupon_restrictions = SKIP)
  @id = id unless id == SKIP
  @name = name unless name == SKIP
  @code = code unless code == SKIP
  @description = description unless description == SKIP
  @amount = amount unless amount == SKIP
  @amount_in_cents = amount_in_cents unless amount_in_cents == SKIP
  @product_family_id = product_family_id unless product_family_id == SKIP
  @product_family_name = product_family_name unless product_family_name == SKIP
  @start_date = start_date unless start_date == SKIP
  @end_date = end_date unless end_date == SKIP
  @percentage = percentage unless percentage == SKIP
  @recurring = recurring unless recurring == SKIP
  @recurring_scheme = recurring_scheme unless recurring_scheme == SKIP
  @duration_period_count = duration_period_count unless duration_period_count == SKIP
  @duration_interval = duration_interval unless duration_interval == SKIP
  @duration_interval_unit = duration_interval_unit unless duration_interval_unit == SKIP
  @duration_interval_span = duration_interval_span unless duration_interval_span == SKIP
  @allow_negative_balance = allow_negative_balance unless allow_negative_balance == SKIP
  @archived_at = archived_at unless archived_at == SKIP
  @conversion_limit = conversion_limit unless conversion_limit == SKIP
  @stackable = stackable unless stackable == SKIP
  @compounding_strategy = compounding_strategy unless compounding_strategy == SKIP
  @use_site_exchange_rate = use_site_exchange_rate unless use_site_exchange_rate == SKIP
  @created_at = created_at unless created_at == SKIP
  @updated_at = updated_at unless updated_at == SKIP
  @discount_type = discount_type unless discount_type == 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
  @coupon_restrictions = coupon_restrictions unless coupon_restrictions == SKIP
end

Instance Attribute Details

#allow_negative_balanceTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


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

def allow_negative_balance
  @allow_negative_balance
end

#amountFloat

TODO: Write general description for this method

Returns:

  • (Float)


30
31
32
# File 'lib/advanced_billing/models/coupon.rb', line 30

def amount
  @amount
end

#amount_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


34
35
36
# File 'lib/advanced_billing/models/coupon.rb', line 34

def amount_in_cents
  @amount_in_cents
end

#apply_on_cancel_at_end_of_periodTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


122
123
124
# File 'lib/advanced_billing/models/coupon.rb', line 122

def apply_on_cancel_at_end_of_period
  @apply_on_cancel_at_end_of_period
end

#archived_atString

TODO: Write general description for this method

Returns:

  • (String)


86
87
88
# File 'lib/advanced_billing/models/coupon.rb', line 86

def archived_at
  @archived_at
end

#codeString

TODO: Write general description for this method

Returns:

  • (String)


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

def code
  @code
end

#compounding_strategyObject

TODO: Write general description for this method

Returns:

  • (Object)


98
99
100
# File 'lib/advanced_billing/models/coupon.rb', line 98

def compounding_strategy
  @compounding_strategy
end

#conversion_limitString

TODO: Write general description for this method

Returns:

  • (String)


90
91
92
# File 'lib/advanced_billing/models/coupon.rb', line 90

def conversion_limit
  @conversion_limit
end

#coupon_restrictionsArray[CouponRestriction]

TODO: Write general description for this method

Returns:



126
127
128
# File 'lib/advanced_billing/models/coupon.rb', line 126

def coupon_restrictions
  @coupon_restrictions
end

#created_atString

TODO: Write general description for this method

Returns:

  • (String)


106
107
108
# File 'lib/advanced_billing/models/coupon.rb', line 106

def created_at
  @created_at
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


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

def description
  @description
end

#discount_typeDiscountType

TODO: Write general description for this method

Returns:



114
115
116
# File 'lib/advanced_billing/models/coupon.rb', line 114

def discount_type
  @discount_type
end

#duration_intervalInteger

TODO: Write general description for this method

Returns:

  • (Integer)


70
71
72
# File 'lib/advanced_billing/models/coupon.rb', line 70

def duration_interval
  @duration_interval
end

#duration_interval_spanString

TODO: Write general description for this method

Returns:

  • (String)


78
79
80
# File 'lib/advanced_billing/models/coupon.rb', line 78

def duration_interval_span
  @duration_interval_span
end

#duration_interval_unitString

TODO: Write general description for this method

Returns:

  • (String)


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

def duration_interval_unit
  @duration_interval_unit
end

#duration_period_countInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def duration_period_count
  @duration_period_count
end

#end_dateString

TODO: Write general description for this method

Returns:

  • (String)


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

def end_date
  @end_date
end

#exclude_mid_period_allocationsTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


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

def exclude_mid_period_allocations
  @exclude_mid_period_allocations
end

#idFloat

TODO: Write general description for this method

Returns:

  • (Float)


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

def id
  @id
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def name
  @name
end

#percentageFloat

TODO: Write general description for this method

Returns:

  • (Float)


54
55
56
# File 'lib/advanced_billing/models/coupon.rb', line 54

def percentage
  @percentage
end

#product_family_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def product_family_id
  @product_family_id
end

#product_family_nameString

TODO: Write general description for this method

Returns:

  • (String)


42
43
44
# File 'lib/advanced_billing/models/coupon.rb', line 42

def product_family_name
  @product_family_name
end

#recurringTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


58
59
60
# File 'lib/advanced_billing/models/coupon.rb', line 58

def recurring
  @recurring
end

#recurring_schemeRecurringScheme

TODO: Write general description for this method

Returns:



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

def recurring_scheme
  @recurring_scheme
end

#stackableTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


94
95
96
# File 'lib/advanced_billing/models/coupon.rb', line 94

def stackable
  @stackable
end

#start_dateString

TODO: Write general description for this method

Returns:

  • (String)


46
47
48
# File 'lib/advanced_billing/models/coupon.rb', line 46

def start_date
  @start_date
end

#updated_atString

TODO: Write general description for this method

Returns:

  • (String)


110
111
112
# File 'lib/advanced_billing/models/coupon.rb', line 110

def updated_at
  @updated_at
end

#use_site_exchange_rateTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


102
103
104
# File 'lib/advanced_billing/models/coupon.rb', line 102

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.



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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/advanced_billing/models/coupon.rb', line 267

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  code = hash.key?('code') ? hash['code'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  amount = hash.key?('amount') ? hash['amount'] : SKIP
  amount_in_cents =
    hash.key?('amount_in_cents') ? hash['amount_in_cents'] : SKIP
  product_family_id =
    hash.key?('product_family_id') ? hash['product_family_id'] : SKIP
  product_family_name =
    hash.key?('product_family_name') ? hash['product_family_name'] : SKIP
  start_date = hash.key?('start_date') ? hash['start_date'] : SKIP
  end_date = hash.key?('end_date') ? hash['end_date'] : SKIP
  percentage = hash.key?('percentage') ? hash['percentage'] : SKIP
  recurring = hash.key?('recurring') ? hash['recurring'] : SKIP
  recurring_scheme =
    hash.key?('recurring_scheme') ? hash['recurring_scheme'] : SKIP
  duration_period_count =
    hash.key?('duration_period_count') ? hash['duration_period_count'] : SKIP
  duration_interval =
    hash.key?('duration_interval') ? hash['duration_interval'] : SKIP
  duration_interval_unit =
    hash.key?('duration_interval_unit') ? hash['duration_interval_unit'] : SKIP
  duration_interval_span =
    hash.key?('duration_interval_span') ? hash['duration_interval_span'] : SKIP
  allow_negative_balance =
    hash.key?('allow_negative_balance') ? hash['allow_negative_balance'] : SKIP
  archived_at = hash.key?('archived_at') ? hash['archived_at'] : SKIP
  conversion_limit =
    hash.key?('conversion_limit') ? hash['conversion_limit'] : SKIP
  stackable = hash.key?('stackable') ? hash['stackable'] : SKIP
  compounding_strategy = hash.key?('compounding_strategy') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CouponCompoundingStrategy), hash['compounding_strategy']
  ) : SKIP
  use_site_exchange_rate =
    hash.key?('use_site_exchange_rate') ? hash['use_site_exchange_rate'] : SKIP
  created_at = hash.key?('created_at') ? hash['created_at'] : SKIP
  updated_at = hash.key?('updated_at') ? hash['updated_at'] : SKIP
  discount_type = hash.key?('discount_type') ? hash['discount_type'] : 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
  # Parameter is an array, so we need to iterate through it
  coupon_restrictions = nil
  unless hash['coupon_restrictions'].nil?
    coupon_restrictions = []
    hash['coupon_restrictions'].each do |structure|
      coupon_restrictions << (CouponRestriction.from_hash(structure) if structure)
    end
  end

  coupon_restrictions = SKIP unless hash.key?('coupon_restrictions')

  # Create object from extracted values.
  Coupon.new(id,
             name,
             code,
             description,
             amount,
             amount_in_cents,
             product_family_id,
             product_family_name,
             start_date,
             end_date,
             percentage,
             recurring,
             recurring_scheme,
             duration_period_count,
             duration_interval,
             duration_interval_unit,
             duration_interval_span,
             allow_negative_balance,
             archived_at,
             conversion_limit,
             stackable,
             compounding_strategy,
             use_site_exchange_rate,
             created_at,
             updated_at,
             discount_type,
             exclude_mid_period_allocations,
             apply_on_cancel_at_end_of_period,
             coupon_restrictions)
end

.namesObject

A mapping from model property names to API property names.



129
130
131
132
133
134
135
136
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
# File 'lib/advanced_billing/models/coupon.rb', line 129

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['code'] = 'code'
  @_hash['description'] = 'description'
  @_hash['amount'] = 'amount'
  @_hash['amount_in_cents'] = 'amount_in_cents'
  @_hash['product_family_id'] = 'product_family_id'
  @_hash['product_family_name'] = 'product_family_name'
  @_hash['start_date'] = 'start_date'
  @_hash['end_date'] = 'end_date'
  @_hash['percentage'] = 'percentage'
  @_hash['recurring'] = 'recurring'
  @_hash['recurring_scheme'] = 'recurring_scheme'
  @_hash['duration_period_count'] = 'duration_period_count'
  @_hash['duration_interval'] = 'duration_interval'
  @_hash['duration_interval_unit'] = 'duration_interval_unit'
  @_hash['duration_interval_span'] = 'duration_interval_span'
  @_hash['allow_negative_balance'] = 'allow_negative_balance'
  @_hash['archived_at'] = 'archived_at'
  @_hash['conversion_limit'] = 'conversion_limit'
  @_hash['stackable'] = 'stackable'
  @_hash['compounding_strategy'] = 'compounding_strategy'
  @_hash['use_site_exchange_rate'] = 'use_site_exchange_rate'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['discount_type'] = 'discount_type'
  @_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['coupon_restrictions'] = 'coupon_restrictions'
  @_hash
end

.nullablesObject

An array for nullable fields



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/advanced_billing/models/coupon.rb', line 201

def self.nullables
  %w[
    amount
    amount_in_cents
    end_date
    percentage
    duration_period_count
    duration_interval
    duration_interval_unit
    archived_at
    conversion_limit
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    id
    name
    code
    description
    amount
    amount_in_cents
    product_family_id
    product_family_name
    start_date
    end_date
    percentage
    recurring
    recurring_scheme
    duration_period_count
    duration_interval
    duration_interval_unit
    duration_interval_span
    allow_negative_balance
    archived_at
    conversion_limit
    stackable
    compounding_strategy
    use_site_exchange_rate
    created_at
    updated_at
    discount_type
    exclude_mid_period_allocations
    apply_on_cancel_at_end_of_period
    coupon_restrictions
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Coupon | Hash)

    value against the validation is performed.



359
360
361
362
363
364
365
# File 'lib/advanced_billing/models/coupon.rb', line 359

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end