Class: AdvancedBilling::CouponPayload

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

Overview

CouponPayload 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(name: SKIP, code: SKIP, description: SKIP, percentage: SKIP, amount_in_cents: 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, apply_on_subscription_expiration: SKIP, additional_properties: {}) ⇒ CouponPayload

Returns a new instance of CouponPayload.



146
147
148
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
# File 'lib/advanced_billing/models/coupon_payload.rb', line 146

def initialize(name: SKIP, code: SKIP, description: SKIP, percentage: SKIP,
               amount_in_cents: 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,
               apply_on_subscription_expiration: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @name = name unless name == SKIP
  @code = code unless code == SKIP
  @description = description unless description == SKIP
  @percentage = percentage unless percentage == SKIP
  @amount_in_cents = amount_in_cents unless amount_in_cents == SKIP
  @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
  unless apply_on_subscription_expiration == SKIP
    @apply_on_subscription_expiration =
      apply_on_subscription_expiration
  end
end

Instance Attribute Details

#allow_negative_balanceTrueClass | FalseClass

If set to true, discount is not limited (credits will carry forward to next billing). Can’t be used together with restrictions.

Returns:

  • (TrueClass | FalseClass)


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

def allow_negative_balance
  @allow_negative_balance
end

#amount_in_centsInteger

Required when creating a new flat amount coupon. Can’t be used together with percentage. Flat USD discount

Returns:

  • (Integer)


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

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)


88
89
90
# File 'lib/advanced_billing/models/coupon_payload.rb', line 88

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)


96
97
98
# File 'lib/advanced_billing/models/coupon_payload.rb', line 96

def apply_on_subscription_expiration
  @apply_on_subscription_expiration
end

#codeString

Required when creating a new coupon. The code is limited to 255 characters. May contain uppercase alphanumeric characters and these special characters (which allow for email addresses to be used): “%”, “@”, “+”, “-”, “_”, and “.”

Returns:

  • (String)


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

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:



72
73
74
# File 'lib/advanced_billing/models/coupon_payload.rb', line 72

def compounding_strategy
  @compounding_strategy
end

#descriptionString

Required when creating a new coupon. A description of the coupon that can be displayed to customers in transactions and on statements. The description is limited to 255 characters.

Returns:

  • (String)


28
29
30
# File 'lib/advanced_billing/models/coupon_payload.rb', line 28

def description
  @description
end

#end_dateDate

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

Returns:

  • (Date)


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

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)


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

def exclude_mid_period_allocations
  @exclude_mid_period_allocations
end

#nameString

Required when creating a new coupon. This name is not displayed to customers and is limited to 255 characters.

Returns:

  • (String)


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

def name
  @name
end

#percentageObject

Required when creating a new percentage coupon. Can’t be used together with amount_in_cents. Percentage discount

Returns:

  • (Object)


33
34
35
# File 'lib/advanced_billing/models/coupon_payload.rb', line 33

def percentage
  @percentage
end

#product_family_idString

After the end of the given day, 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)


60
61
62
# File 'lib/advanced_billing/models/coupon_payload.rb', line 60

def product_family_id
  @product_family_id
end

#recurringTrueClass | FalseClass

If set to true, discount is not limited (credits will carry forward to next billing). Can’t be used together with restrictions.

Returns:

  • (TrueClass | FalseClass)


48
49
50
# File 'lib/advanced_billing/models/coupon_payload.rb', line 48

def recurring
  @recurring
end

#stackableTrueClass | FalseClass

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

Returns:

  • (TrueClass | FalseClass)


64
65
66
# File 'lib/advanced_billing/models/coupon_payload.rb', line 64

def stackable
  @stackable
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



185
186
187
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
# File 'lib/advanced_billing/models/coupon_payload.rb', line 185

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : SKIP
  code = hash.key?('code') ? hash['code'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  percentage = hash.key?('percentage') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CouponPayloadPercentage), hash['percentage']
  ) : SKIP
  amount_in_cents =
    hash.key?('amount_in_cents') ? hash['amount_in_cents'] : 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') ? 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
  apply_on_subscription_expiration =
    hash.key?('apply_on_subscription_expiration') ? hash['apply_on_subscription_expiration'] : SKIP

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

  # Create object from extracted values.
  CouponPayload.new(name: name,
                    code: code,
                    description: description,
                    percentage: percentage,
                    amount_in_cents: amount_in_cents,
                    allow_negative_balance: allow_negative_balance,
                    recurring: recurring,
                    end_date: end_date,
                    product_family_id: product_family_id,
                    stackable: stackable,
                    compounding_strategy: compounding_strategy,
                    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,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/advanced_billing/models/coupon_payload.rb', line 99

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['code'] = 'code'
  @_hash['description'] = 'description'
  @_hash['percentage'] = 'percentage'
  @_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['apply_on_subscription_expiration'] =
    'apply_on_subscription_expiration'
  @_hash
end

.nullablesObject

An array for nullable fields



142
143
144
# File 'lib/advanced_billing/models/coupon_payload.rb', line 142

def self.nullables
  []
end

.optionalsObject

An array for optional fields



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/advanced_billing/models/coupon_payload.rb', line 122

def self.optionals
  %w[
    name
    code
    description
    percentage
    amount_in_cents
    allow_negative_balance
    recurring
    end_date
    product_family_id
    stackable
    compounding_strategy
    exclude_mid_period_allocations
    apply_on_cancel_at_end_of_period
    apply_on_subscription_expiration
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (CouponPayload | Hash)

    value against the validation is performed.



236
237
238
239
240
241
242
# File 'lib/advanced_billing/models/coupon_payload.rb', line 236

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

  return false unless value.instance_of? Hash

  true
end