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

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #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, apply_on_subscription_expiration: SKIP, coupon_restrictions: SKIP, currency_prices: SKIP, additional_properties: {}) ⇒ Coupon

Returns a new instance of Coupon.



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

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,
               apply_on_subscription_expiration: SKIP,
               coupon_restrictions: SKIP, currency_prices: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @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
  unless apply_on_subscription_expiration == SKIP
    @apply_on_subscription_expiration =
      apply_on_subscription_expiration
  end
  @coupon_restrictions = coupon_restrictions unless coupon_restrictions == SKIP
  @currency_prices = currency_prices unless currency_prices == SKIP
end

Instance Attribute Details

#allow_negative_balanceTrueClass | FalseClass

If set to true, discount is not limited (credits will carry forward to next billing).

Returns:

  • (TrueClass | FalseClass)


100
101
102
# File 'lib/advanced_billing/models/coupon.rb', line 100

def allow_negative_balance
  @allow_negative_balance
end

#amountFloat

TODO: Write general description for this method

Returns:

  • (Float)


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

def amount
  @amount
end

#amount_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def amount_in_cents
  @amount_in_cents
end

#apply_on_cancel_at_end_of_periodTrueClass | FalseClass

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:

  • (TrueClass | FalseClass)


170
171
172
# File 'lib/advanced_billing/models/coupon.rb', line 170

def apply_on_cancel_at_end_of_period
  @apply_on_cancel_at_end_of_period
end

#apply_on_subscription_expirationTrueClass | FalseClass

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:

  • (TrueClass | FalseClass)


178
179
180
# File 'lib/advanced_billing/models/coupon.rb', line 178

def apply_on_subscription_expiration
  @apply_on_subscription_expiration
end

#archived_atDateTime

If set to true, discount is not limited (credits will carry forward to next billing).

Returns:

  • (DateTime)


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

def archived_at
  @archived_at
end

#codeString

TODO: Write general description for this method

Returns:

  • (String)


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

def code
  @code
end

#compounding_strategyCompoundingStrategy

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:



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

def compounding_strategy
  @compounding_strategy
end

#conversion_limitString

If set to true, discount is not limited (credits will carry forward to next billing).

Returns:

  • (String)


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

def conversion_limit
  @conversion_limit
end

#coupon_restrictionsArray[CouponRestriction]

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:



186
187
188
# File 'lib/advanced_billing/models/coupon.rb', line 186

def coupon_restrictions
  @coupon_restrictions
end

#created_atDateTime

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:

  • (DateTime)


138
139
140
# File 'lib/advanced_billing/models/coupon.rb', line 138

def created_at
  @created_at
end

#currency_pricesArray[CouponCurrency]

Returned in read, find, and list endpoints if the query parameter is provided.

Returns:



191
192
193
# File 'lib/advanced_billing/models/coupon.rb', line 191

def currency_prices
  @currency_prices
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


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

def description
  @description
end

#discount_typeDiscountType

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:



154
155
156
# File 'lib/advanced_billing/models/coupon.rb', line 154

def discount_type
  @discount_type
end

#duration_intervalInteger

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:

  • (Integer)


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

def duration_interval
  @duration_interval
end

#duration_interval_spanString

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:

  • (String)


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

def duration_interval_span
  @duration_interval_span
end

#duration_interval_unitString

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:

  • (String)


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

def duration_interval_unit
  @duration_interval_unit
end

#duration_period_countInteger

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:

  • (Integer)


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

def duration_period_count
  @duration_period_count
end

#end_dateDateTime

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:

  • (DateTime)


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

def end_date
  @end_date
end

#exclude_mid_period_allocationsTrueClass | FalseClass

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:

  • (TrueClass | FalseClass)


162
163
164
# File 'lib/advanced_billing/models/coupon.rb', line 162

def exclude_mid_period_allocations
  @exclude_mid_period_allocations
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def id
  @id
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def name
  @name
end

#percentageString

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:

  • (String)


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

def percentage
  @percentage
end

#product_family_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def product_family_id
  @product_family_id
end

#product_family_nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def product_family_name
  @product_family_name
end

#recurringTrueClass | FalseClass

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:

  • (TrueClass | FalseClass)


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

def recurring
  @recurring
end

#recurring_schemeRecurringScheme

After the given time, this coupon code will be invalid for new signups. Recurring discounts started before this date will continue to recur even after this date.

Returns:



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

def recurring_scheme
  @recurring_scheme
end

#stackableTrueClass | FalseClass

A stackable coupon can be combined with other coupons on a Subscription.

Returns:

  • (TrueClass | FalseClass)


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

def stackable
  @stackable
end

#start_dateDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


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

def start_date
  @start_date
end

#updated_atDateTime

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:

  • (DateTime)


146
147
148
# File 'lib/advanced_billing/models/coupon.rb', line 146

def updated_at
  @updated_at
end

#use_site_exchange_rateTrueClass | FalseClass

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Returns:

  • (TrueClass | FalseClass)


130
131
132
# File 'lib/advanced_billing/models/coupon.rb', line 130

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.



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
470
471
472
473
474
475
476
# File 'lib/advanced_billing/models/coupon.rb', line 351

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 = if hash.key?('start_date')
                 (DateTimeHelper.from_rfc3339(hash['start_date']) if hash['start_date'])
               else
                 SKIP
               end
  end_date = if hash.key?('end_date')
               (DateTimeHelper.from_rfc3339(hash['end_date']) if hash['end_date'])
             else
               SKIP
             end
  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 = if hash.key?('archived_at')
                  (DateTimeHelper.from_rfc3339(hash['archived_at']) if hash['archived_at'])
                else
                  SKIP
                end
  conversion_limit =
    hash.key?('conversion_limit') ? hash['conversion_limit'] : SKIP
  stackable = hash.key?('stackable') ? hash['stackable'] : SKIP
  compounding_strategy =
    hash.key?('compounding_strategy') ? hash['compounding_strategy'] : SKIP
  use_site_exchange_rate =
    hash.key?('use_site_exchange_rate') ? hash['use_site_exchange_rate'] : SKIP
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               else
                 SKIP
               end
  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
  apply_on_subscription_expiration =
    hash.key?('apply_on_subscription_expiration') ? hash['apply_on_subscription_expiration'] : 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')
  # Parameter is an array, so we need to iterate through it
  currency_prices = nil
  unless hash['currency_prices'].nil?
    currency_prices = []
    hash['currency_prices'].each do |structure|
      currency_prices << (CouponCurrency.from_hash(structure) if structure)
    end
  end

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

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

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

.namesObject

A mapping from model property names to API property names.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/advanced_billing/models/coupon.rb', line 194

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['apply_on_subscription_expiration'] =
    'apply_on_subscription_expiration'
  @_hash['coupon_restrictions'] = 'coupon_restrictions'
  @_hash['currency_prices'] = 'currency_prices'
  @_hash
end

.nullablesObject

An array for nullable fields



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/advanced_billing/models/coupon.rb', line 271

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

.optionalsObject

An array for optional fields



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
265
266
267
268
# File 'lib/advanced_billing/models/coupon.rb', line 234

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
    apply_on_subscription_expiration
    coupon_restrictions
    currency_prices
  ]
end

Instance Method Details

#to_custom_archived_atObject



486
487
488
# File 'lib/advanced_billing/models/coupon.rb', line 486

def to_custom_archived_at
  DateTimeHelper.to_rfc3339(archived_at)
end

#to_custom_created_atObject



490
491
492
# File 'lib/advanced_billing/models/coupon.rb', line 490

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_end_dateObject



482
483
484
# File 'lib/advanced_billing/models/coupon.rb', line 482

def to_custom_end_date
  DateTimeHelper.to_rfc3339(end_date)
end

#to_custom_start_dateObject



478
479
480
# File 'lib/advanced_billing/models/coupon.rb', line 478

def to_custom_start_date
  DateTimeHelper.to_rfc3339(start_date)
end

#to_custom_updated_atObject



494
495
496
# File 'lib/advanced_billing/models/coupon.rb', line 494

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end