Class: BillForward::Coupon

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

Overview

<p>A coupon allows the customer to apply one or more discounts to a subscription.A coupon can be used to generate coupon codes which can then be added or removed from subscription.</p>

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Coupon

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



188
189
190
191
192
193
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
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
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
# File 'lib/bf_ruby2/models/coupon.rb', line 188

def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}

  if attributes.has_key?(:'created')
    self.created = attributes[:'created']
  end

  if attributes.has_key?(:'changedBy')
    self.changed_by = attributes[:'changedBy']
  end

  if attributes.has_key?(:'updated')
    self.updated = attributes[:'updated']
  end

  if attributes.has_key?(:'name')
    self.name = attributes[:'name']
  end

  if attributes.has_key?(:'couponCode')
    self.coupon_code = attributes[:'couponCode']
  end

  if attributes.has_key?(:'coupons')
    self.coupons = attributes[:'coupons']
  end

  if attributes.has_key?(:'uses')
    self.uses = attributes[:'uses']
  end

  if attributes.has_key?(:'product')
    self.product = attributes[:'product']
  end

  if attributes.has_key?(:'productName')
    self.product_name = attributes[:'productName']
  end

  if attributes.has_key?(:'productID')
    self.product_id = attributes[:'productID']
  end

  if attributes.has_key?(:'productRatePlan')
    self.product_rate_plan = attributes[:'productRatePlan']
  end

  if attributes.has_key?(:'productRatePlanName')
    self.product_rate_plan_name = attributes[:'productRatePlanName']
  end

  if attributes.has_key?(:'productRatePlanID')
    self.product_rate_plan_id = attributes[:'productRatePlanID']
  end

  if attributes.has_key?(:'currency')
    self.currency = attributes[:'currency']
  end

  if attributes.has_key?(:'parentCouponCodeRedeemable')
    self.parent_coupon_code_redeemable = attributes[:'parentCouponCodeRedeemable']
  else
    self.parent_coupon_code_redeemable = false
  end

  if attributes.has_key?(:'organizationID')
    self.organization_id = attributes[:'organizationID']
  end

  if attributes.has_key?(:'discounts')
    if (value = attributes[:'discounts']).is_a?(Array)
      self.discounts = value
    end
  end

  if attributes.has_key?(:'deleted')
    self.deleted = attributes[:'deleted']
  else
    self.deleted = false
  end

  if attributes.has_key?(:'parentCouponCode')
    self.parent_coupon_code = attributes[:'parentCouponCode']
  end

  if attributes.has_key?(:'appliesTo')
    self.applies_to = attributes[:'appliesTo']
  end

  if attributes.has_key?(:'appliesToID')
    self.applies_to_id = attributes[:'appliesToID']
  end

  if attributes.has_key?(:'remainingUses')
    self.remaining_uses = attributes[:'remainingUses']
  end

  if attributes.has_key?(:'used')
    self.used = attributes[:'used']
  end

  if attributes.has_key?(:'discountValue')
    self.discount_value = attributes[:'discountValue']
  end

  if attributes.has_key?(:'validUntil')
    self.valid_until = attributes[:'validUntil']
  end

end

Instance Attribute Details

#applies_toObject

{ "description" : "For unique coupon codes this is what the coupon applies to, usually subscription.", "verbs“: }



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

def applies_to
  @applies_to
end

#applies_to_idObject

{ "description" : "For a coupon added to a subscription this is the the ID of the subscription. This can be used to remove the coupon from the target.", "verbs“: }



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

def applies_to_id
  @applies_to_id
end

#changed_byObject

{ "description" : "ID of the user who last updated the entity.", "verbs":[] }



33
34
35
# File 'lib/bf_ruby2/models/coupon.rb', line 33

def changed_by
  @changed_by
end

#coupon_codeObject

{ "description" : "Code used to identify this set of coupons. If unique codes are required this will be used as the prefix to generate individual coupon codes. When a unique code is returned the original couponCode is returned in the parentCouponCode property. For example a single coupon code SUMMER maybe be issued at an event to encourage sign-up, the same code can be redeemed by multiple accounts. In another example you may want to issue unique coupon codes per a customer, for example SUMMER-A4FC, SUMMER-BCQ4, each code can only be calimed once.", "verbs“: }



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

def coupon_code
  @coupon_code
end

#couponsObject

{ "default" : "&infin;", "description" : "Number of times the coupon can be claimed. In the case of generating unique coupon codes this is the maximum quantity that can be genereated. For example set this value to 10 if you want to limit the total number of subscriptions that will use this code to 10.", "verbs“: }



45
46
47
# File 'lib/bf_ruby2/models/coupon.rb', line 45

def coupons
  @coupons
end

#createdObject

{ "description" : "The UTC DateTime when the object was created.", "verbs":[] }



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

def created
  @created
end

#currencyObject

{ "description" : "If the coupon is not for a specific rate-plan, and can apply to any subscription, the currency should be provivded. Currency is specified by a three character ISO 4217 currency code.", "verbs“: }



69
70
71
# File 'lib/bf_ruby2/models/coupon.rb', line 69

def currency
  @currency
end

#deletedObject

{ "description" : "If a coupon has been deleted, any subsequent attempts to add it to a subscription will fail. Note: This will not affect existing subscription using the coupon. Please see deleting a coupon for more details", "verbs“: }



80
81
82
# File 'lib/bf_ruby2/models/coupon.rb', line 80

def deleted
  @deleted
end

#discount_valueObject

Returns the value of attribute discount_value.



97
98
99
# File 'lib/bf_ruby2/models/coupon.rb', line 97

def discount_value
  @discount_value
end

#discountsObject

{ "description" : "For each discount item on the coupon, only one discount type should be set between cashDiscount, percentageDiscount and unitsFree. cashDiscount gives a fixed monetary discount, for example $10.00. percentageDiscount gives a percentage discount on the overall invoice cost. unitsFree discounts the pricing by the number of units specified for that component. All discounts are applied against the base cost or units. Discounts are not compound. Discounts will never exceed the value of a pricing component of the overall invoice - thus at most the discount will reduce the cost to zero. If no pricing component is specified the discount will apply to the total invoice cost.", "verbs“: }



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

def discounts
  @discounts
end

#nameObject

{ "description" : "", "verbs“: }



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

def name
  @name
end

#organization_idObject

Returns the value of attribute organization_id.



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

def organization_id
  @organization_id
end

#parent_coupon_codeObject

{ "description" : "For unique coupon codes this is the original coupon code, for example SUMMER", "verbs“: }



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

def parent_coupon_code
  @parent_coupon_code
end

#parent_coupon_code_redeemableObject

{ "default" : "true", "description" : "If true the coupon without postfix can be added to a subscription, for example if parentCouponCodeRedeemable is true and the coupon was created with code SUMMER customers could claim using SUMMER. If parentCouponCodeRedeemable is false then only unique coupon codes can be claimed, for example SUMMER-AB4C, SUMMER-YZB4.", "verbs“: }



72
73
74
# File 'lib/bf_ruby2/models/coupon.rb', line 72

def parent_coupon_code_redeemable
  @parent_coupon_code_redeemable
end

#productObject

{ "description" : "Name or ID of the product this coupon applies to. Requires a specific rate-plan to be set.", "verbs“: }



51
52
53
# File 'lib/bf_ruby2/models/coupon.rb', line 51

def product
  @product
end

#product_idObject

{ "description" : "", "verbs“: }



57
58
59
# File 'lib/bf_ruby2/models/coupon.rb', line 57

def product_id
  @product_id
end

#product_nameObject

{ "description" : "", "verbs“: }



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

def product_name
  @product_name
end

#product_rate_planObject

{ "description" : "Name or ID of the rate-plan this coupon applies to. ", "verbs“: }



60
61
62
# File 'lib/bf_ruby2/models/coupon.rb', line 60

def product_rate_plan
  @product_rate_plan
end

#product_rate_plan_idObject

{ "description" : "", "verbs“: }



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

def product_rate_plan_id
  @product_rate_plan_id
end

#product_rate_plan_nameObject

{ "description" : "", "verbs“: }



63
64
65
# File 'lib/bf_ruby2/models/coupon.rb', line 63

def product_rate_plan_name
  @product_rate_plan_name
end

#remaining_usesObject

{ "description" : "", "verbs“: }



92
93
94
# File 'lib/bf_ruby2/models/coupon.rb', line 92

def remaining_uses
  @remaining_uses
end

#updatedObject

{ "description" : "The UTC DateTime when the object was last updated.", "verbs":[] }



36
37
38
# File 'lib/bf_ruby2/models/coupon.rb', line 36

def updated
  @updated
end

#usedObject

{ "description" : "", "verbs“: }



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

def used
  @used
end

#usesObject

{ "default" : "&infin;", "description" : "This specifies how many times a discount will be added to a subscription once the coupon is added. For example if the uses is set to 3 it will discount 3 times, set this to a large number, for example 9999999, to give infinite applications, .", "verbs“: }



48
49
50
# File 'lib/bf_ruby2/models/coupon.rb', line 48

def uses
  @uses
end

#valid_untilObject

{ "description" : "If the coupon was removed from the subscription this is the date and time from when it no ceased to be applied.", "verbs“: }



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

def valid_until
  @valid_until
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



125
126
127
128
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
# File 'lib/bf_ruby2/models/coupon.rb', line 125

def self.attribute_map
  {
    :'created' => :'created',
    :'changed_by' => :'changedBy',
    :'updated' => :'updated',
    :'name' => :'name',
    :'coupon_code' => :'couponCode',
    :'coupons' => :'coupons',
    :'uses' => :'uses',
    :'product' => :'product',
    :'product_name' => :'productName',
    :'product_id' => :'productID',
    :'product_rate_plan' => :'productRatePlan',
    :'product_rate_plan_name' => :'productRatePlanName',
    :'product_rate_plan_id' => :'productRatePlanID',
    :'currency' => :'currency',
    :'parent_coupon_code_redeemable' => :'parentCouponCodeRedeemable',
    :'organization_id' => :'organizationID',
    :'discounts' => :'discounts',
    :'deleted' => :'deleted',
    :'parent_coupon_code' => :'parentCouponCode',
    :'applies_to' => :'appliesTo',
    :'applies_to_id' => :'appliesToID',
    :'remaining_uses' => :'remainingUses',
    :'used' => :'used',
    :'discount_value' => :'discountValue',
    :'valid_until' => :'validUntil'
  }
end

.swagger_typesObject

Attribute type mapping.



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

def self.swagger_types
  {
    :'created' => :'DateTime',
    :'changed_by' => :'String',
    :'updated' => :'DateTime',
    :'name' => :'String',
    :'coupon_code' => :'String',
    :'coupons' => :'Integer',
    :'uses' => :'Integer',
    :'product' => :'String',
    :'product_name' => :'String',
    :'product_id' => :'String',
    :'product_rate_plan' => :'String',
    :'product_rate_plan_name' => :'String',
    :'product_rate_plan_id' => :'String',
    :'currency' => :'String',
    :'parent_coupon_code_redeemable' => :'BOOLEAN',
    :'organization_id' => :'String',
    :'discounts' => :'Array<CouponDiscount>',
    :'deleted' => :'BOOLEAN',
    :'parent_coupon_code' => :'String',
    :'applies_to' => :'String',
    :'applies_to_id' => :'String',
    :'remaining_uses' => :'Integer',
    :'used' => :'Integer',
    :'discount_value' => :'Float',
    :'valid_until' => :'DateTime'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/bf_ruby2/models/coupon.rb', line 336

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      created == o.created &&
      changed_by == o.changed_by &&
      updated == o.updated &&
      name == o.name &&
      coupon_code == o.coupon_code &&
      coupons == o.coupons &&
      uses == o.uses &&
      product == o.product &&
      product_name == o.product_name &&
      product_id == o.product_id &&
      product_rate_plan == o.product_rate_plan &&
      product_rate_plan_name == o.product_rate_plan_name &&
      product_rate_plan_id == o.product_rate_plan_id &&
      currency == o.currency &&
      parent_coupon_code_redeemable == o.parent_coupon_code_redeemable &&
      organization_id == o.organization_id &&
      discounts == o.discounts &&
      deleted == o.deleted &&
      parent_coupon_code == o.parent_coupon_code &&
      applies_to == o.applies_to &&
      applies_to_id == o.applies_to_id &&
      remaining_uses == o.remaining_uses &&
      used == o.used &&
      discount_value == o.discount_value &&
      valid_until == o.valid_until
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



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

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :BOOLEAN
    if value.to_s =~ /^(true|t|yes|y|1)$/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    temp_model = BillForward.const_get(type).new
    temp_model.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/bf_ruby2/models/coupon.rb', line 468

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map{ |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/bf_ruby2/models/coupon.rb', line 381

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.swagger_types.each_pair do |key, type|
    if type =~ /^Array<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


368
369
370
# File 'lib/bf_ruby2/models/coupon.rb', line 368

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



374
375
376
# File 'lib/bf_ruby2/models/coupon.rb', line 374

def hash
  [created, changed_by, updated, name, coupon_code, coupons, uses, product, product_name, product_id, product_rate_plan, product_rate_plan_name, product_rate_plan_id, currency, parent_coupon_code_redeemable, organization_id, discounts, deleted, parent_coupon_code, applies_to, applies_to_id, remaining_uses, used, discount_value, valid_until].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properies with the reasons



304
305
306
307
# File 'lib/bf_ruby2/models/coupon.rb', line 304

def list_invalid_properties
  invalid_properties = Array.new
  return invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



448
449
450
# File 'lib/bf_ruby2/models/coupon.rb', line 448

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



454
455
456
457
458
459
460
461
462
# File 'lib/bf_ruby2/models/coupon.rb', line 454

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



442
443
444
# File 'lib/bf_ruby2/models/coupon.rb', line 442

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/bf_ruby2/models/coupon.rb', line 311

def valid?
  return false if @name.nil?
  return false if @coupon_code.nil?
  return false if @coupons.nil?
  return false if @uses.nil?
  return false if @parent_coupon_code_redeemable.nil?
  return false if @organization_id.nil?
  return false if @discounts.nil?
  applies_to_validator = EnumAttributeValidator.new('String', ["none", "subscription", "account"])
  return false unless applies_to_validator.valid?(@applies_to)
  return true
end