Class: AdvancedBilling::CreateInvoiceCoupon

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

Overview

CreateInvoiceCoupon 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(code: SKIP, percentage: SKIP, amount: SKIP, description: SKIP, product_family_id: SKIP, compounding_strategy: SKIP, additional_properties: {}) ⇒ CreateInvoiceCoupon

Returns a new instance of CreateInvoiceCoupon.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/advanced_billing/models/create_invoice_coupon.rb', line 69

def initialize(code: SKIP, percentage: SKIP, amount: SKIP,
               description: SKIP, product_family_id: SKIP,
               compounding_strategy: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @code = code unless code == SKIP
  @percentage = percentage unless percentage == SKIP
  @amount = amount unless amount == SKIP
  @description = description unless description == SKIP
  @product_family_id = product_family_id unless product_family_id == SKIP
  @compounding_strategy = compounding_strategy unless compounding_strategy == SKIP
end

Instance Attribute Details

#amountObject

TODO: Write general description for this method

Returns:

  • (Object)


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

def amount
  @amount
end

#codeString

TODO: Write general description for this method

Returns:

  • (String)


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

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:



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

def compounding_strategy
  @compounding_strategy
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


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

def description
  @description
end

#percentageObject

TODO: Write general description for this method

Returns:

  • (Object)


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

def percentage
  @percentage
end

#product_family_idObject

TODO: Write general description for this method

Returns:

  • (Object)


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

def product_family_id
  @product_family_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



86
87
88
89
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
# File 'lib/advanced_billing/models/create_invoice_coupon.rb', line 86

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  code = hash.key?('code') ? hash['code'] : SKIP
  percentage = hash.key?('percentage') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateInvoiceCouponPercentage), hash['percentage']
  ) : SKIP
  amount = hash.key?('amount') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateInvoiceCouponAmount), hash['amount']
  ) : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  product_family_id = hash.key?('product_family_id') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateInvoiceCouponProductFamilyId), hash['product_family_id']
  ) : SKIP
  compounding_strategy =
    hash.key?('compounding_strategy') ? hash['compounding_strategy'] : SKIP

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

  # Create object from extracted values.
  CreateInvoiceCoupon.new(code: code,
                          percentage: percentage,
                          amount: amount,
                          description: description,
                          product_family_id: product_family_id,
                          compounding_strategy: compounding_strategy,
                          additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



41
42
43
44
45
46
47
48
49
50
# File 'lib/advanced_billing/models/create_invoice_coupon.rb', line 41

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['code'] = 'code'
  @_hash['percentage'] = 'percentage'
  @_hash['amount'] = 'amount'
  @_hash['description'] = 'description'
  @_hash['product_family_id'] = 'product_family_id'
  @_hash['compounding_strategy'] = 'compounding_strategy'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



53
54
55
56
57
58
59
60
61
62
# File 'lib/advanced_billing/models/create_invoice_coupon.rb', line 53

def self.optionals
  %w[
    code
    percentage
    amount
    description
    product_family_id
    compounding_strategy
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



119
120
121
122
123
124
125
# File 'lib/advanced_billing/models/create_invoice_coupon.rb', line 119

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

  return false unless value.instance_of? Hash

  true
end