Class: AdvancedBilling::Coupon
- Defined in:
- lib/advanced_billing/models/coupon.rb
Overview
Coupon Model.
Instance Attribute Summary collapse
-
#allow_negative_balance ⇒ TrueClass | FalseClass
TODO: Write general description for this method.
-
#amount ⇒ Float
TODO: Write general description for this method.
-
#amount_in_cents ⇒ Integer
TODO: Write general description for this method.
-
#apply_on_cancel_at_end_of_period ⇒ TrueClass | FalseClass
TODO: Write general description for this method.
-
#apply_on_subscription_expiration ⇒ TrueClass | FalseClass
TODO: Write general description for this method.
-
#archived_at ⇒ DateTime
TODO: Write general description for this method.
-
#code ⇒ String
TODO: Write general description for this method.
-
#compounding_strategy ⇒ CompoundingStrategy
TODO: Write general description for this method.
-
#conversion_limit ⇒ String
TODO: Write general description for this method.
-
#coupon_restrictions ⇒ Array[CouponRestriction]
TODO: Write general description for this method.
-
#created_at ⇒ DateTime
TODO: Write general description for this method.
-
#description ⇒ String
TODO: Write general description for this method.
-
#discount_type ⇒ DiscountType
TODO: Write general description for this method.
-
#duration_interval ⇒ Integer
TODO: Write general description for this method.
-
#duration_interval_span ⇒ String
TODO: Write general description for this method.
-
#duration_interval_unit ⇒ String
TODO: Write general description for this method.
-
#duration_period_count ⇒ Integer
TODO: Write general description for this method.
-
#end_date ⇒ DateTime
TODO: Write general description for this method.
-
#exclude_mid_period_allocations ⇒ TrueClass | FalseClass
TODO: Write general description for this method.
-
#id ⇒ Integer
TODO: Write general description for this method.
-
#name ⇒ String
TODO: Write general description for this method.
-
#percentage ⇒ String
TODO: Write general description for this method.
-
#product_family_id ⇒ Integer
TODO: Write general description for this method.
-
#product_family_name ⇒ String
TODO: Write general description for this method.
-
#recurring ⇒ TrueClass | FalseClass
TODO: Write general description for this method.
-
#recurring_scheme ⇒ RecurringScheme
TODO: Write general description for this method.
-
#stackable ⇒ TrueClass | FalseClass
TODO: Write general description for this method.
-
#start_date ⇒ DateTime
TODO: Write general description for this method.
-
#updated_at ⇒ DateTime
TODO: Write general description for this method.
-
#use_site_exchange_rate ⇒ TrueClass | FalseClass
TODO: Write general description for this method.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#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, additional_properties: {}) ⇒ Coupon
constructor
A new instance of Coupon.
- #to_custom_archived_at ⇒ Object
- #to_custom_created_at ⇒ Object
- #to_custom_end_date ⇒ Object
- #to_custom_start_date ⇒ Object
- #to_custom_updated_at ⇒ Object
Methods inherited from BaseModel
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, additional_properties: {}) ⇒ Coupon
Returns a new instance of Coupon.
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 |
# File 'lib/advanced_billing/models/coupon.rb', line 226 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, additional_properties: {}) @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 # Add additional model properties to the instance. additional_properties.each do |_name, _value| instance_variable_set("@#{_name}", _value) end end |
Instance Attribute Details
#allow_negative_balance ⇒ TrueClass | FalseClass
TODO: Write general description for this method
83 84 85 |
# File 'lib/advanced_billing/models/coupon.rb', line 83 def allow_negative_balance @allow_negative_balance end |
#amount ⇒ Float
TODO: Write general description for this method
31 32 33 |
# File 'lib/advanced_billing/models/coupon.rb', line 31 def amount @amount end |
#amount_in_cents ⇒ Integer
TODO: Write general description for this method
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_period ⇒ TrueClass | FalseClass
TODO: Write general description for this method
123 124 125 |
# File 'lib/advanced_billing/models/coupon.rb', line 123 def apply_on_cancel_at_end_of_period @apply_on_cancel_at_end_of_period end |
#apply_on_subscription_expiration ⇒ TrueClass | FalseClass
TODO: Write general description for this method
127 128 129 |
# File 'lib/advanced_billing/models/coupon.rb', line 127 def apply_on_subscription_expiration @apply_on_subscription_expiration end |
#archived_at ⇒ DateTime
TODO: Write general description for this method
87 88 89 |
# File 'lib/advanced_billing/models/coupon.rb', line 87 def archived_at @archived_at end |
#code ⇒ String
TODO: Write general description for this method
23 24 25 |
# File 'lib/advanced_billing/models/coupon.rb', line 23 def code @code end |
#compounding_strategy ⇒ CompoundingStrategy
TODO: Write general description for this method
99 100 101 |
# File 'lib/advanced_billing/models/coupon.rb', line 99 def compounding_strategy @compounding_strategy end |
#conversion_limit ⇒ String
TODO: Write general description for this method
91 92 93 |
# File 'lib/advanced_billing/models/coupon.rb', line 91 def conversion_limit @conversion_limit end |
#coupon_restrictions ⇒ Array[CouponRestriction]
TODO: Write general description for this method
131 132 133 |
# File 'lib/advanced_billing/models/coupon.rb', line 131 def coupon_restrictions @coupon_restrictions end |
#created_at ⇒ DateTime
TODO: Write general description for this method
107 108 109 |
# File 'lib/advanced_billing/models/coupon.rb', line 107 def created_at @created_at end |
#description ⇒ String
TODO: Write general description for this method
27 28 29 |
# File 'lib/advanced_billing/models/coupon.rb', line 27 def description @description end |
#discount_type ⇒ DiscountType
TODO: Write general description for this method
115 116 117 |
# File 'lib/advanced_billing/models/coupon.rb', line 115 def discount_type @discount_type end |
#duration_interval ⇒ Integer
TODO: Write general description for this method
71 72 73 |
# File 'lib/advanced_billing/models/coupon.rb', line 71 def duration_interval @duration_interval end |
#duration_interval_span ⇒ String
TODO: Write general description for this method
79 80 81 |
# File 'lib/advanced_billing/models/coupon.rb', line 79 def duration_interval_span @duration_interval_span end |
#duration_interval_unit ⇒ String
TODO: Write general description for this method
75 76 77 |
# File 'lib/advanced_billing/models/coupon.rb', line 75 def duration_interval_unit @duration_interval_unit end |
#duration_period_count ⇒ Integer
TODO: Write general description for this method
67 68 69 |
# File 'lib/advanced_billing/models/coupon.rb', line 67 def duration_period_count @duration_period_count end |
#end_date ⇒ DateTime
TODO: Write general description for this method
51 52 53 |
# File 'lib/advanced_billing/models/coupon.rb', line 51 def end_date @end_date end |
#exclude_mid_period_allocations ⇒ TrueClass | FalseClass
TODO: Write general description for this method
119 120 121 |
# File 'lib/advanced_billing/models/coupon.rb', line 119 def exclude_mid_period_allocations @exclude_mid_period_allocations end |
#id ⇒ Integer
TODO: Write general description for this method
15 16 17 |
# File 'lib/advanced_billing/models/coupon.rb', line 15 def id @id end |
#name ⇒ String
TODO: Write general description for this method
19 20 21 |
# File 'lib/advanced_billing/models/coupon.rb', line 19 def name @name end |
#percentage ⇒ String
TODO: Write general description for this method
55 56 57 |
# File 'lib/advanced_billing/models/coupon.rb', line 55 def percentage @percentage end |
#product_family_id ⇒ Integer
TODO: Write general description for this method
39 40 41 |
# File 'lib/advanced_billing/models/coupon.rb', line 39 def product_family_id @product_family_id end |
#product_family_name ⇒ String
TODO: Write general description for this method
43 44 45 |
# File 'lib/advanced_billing/models/coupon.rb', line 43 def product_family_name @product_family_name end |
#recurring ⇒ TrueClass | FalseClass
TODO: Write general description for this method
59 60 61 |
# File 'lib/advanced_billing/models/coupon.rb', line 59 def recurring @recurring end |
#recurring_scheme ⇒ RecurringScheme
TODO: Write general description for this method
63 64 65 |
# File 'lib/advanced_billing/models/coupon.rb', line 63 def recurring_scheme @recurring_scheme end |
#stackable ⇒ TrueClass | FalseClass
TODO: Write general description for this method
95 96 97 |
# File 'lib/advanced_billing/models/coupon.rb', line 95 def stackable @stackable end |
#start_date ⇒ DateTime
TODO: Write general description for this method
47 48 49 |
# File 'lib/advanced_billing/models/coupon.rb', line 47 def start_date @start_date end |
#updated_at ⇒ DateTime
TODO: Write general description for this method
111 112 113 |
# File 'lib/advanced_billing/models/coupon.rb', line 111 def updated_at @updated_at end |
#use_site_exchange_rate ⇒ TrueClass | FalseClass
TODO: Write general description for this method
103 104 105 |
# File 'lib/advanced_billing/models/coupon.rb', line 103 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.
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 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 |
# File 'lib/advanced_billing/models/coupon.rb', line 287 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') # Clean out expected properties from Hash. names.each_value { |k| hash.delete(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, additional_properties: hash) end |
.names ⇒ Object
A mapping from model property names to API property names.
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 164 165 166 167 168 169 170 |
# File 'lib/advanced_billing/models/coupon.rb', line 134 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 end |
.nullables ⇒ Object
An array for nullable fields
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/advanced_billing/models/coupon.rb', line 209 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 |
.optionals ⇒ Object
An array for optional fields
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 199 200 201 202 203 204 205 206 |
# File 'lib/advanced_billing/models/coupon.rb', line 173 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 ] end |
Instance Method Details
#to_custom_archived_at ⇒ Object
411 412 413 |
# File 'lib/advanced_billing/models/coupon.rb', line 411 def to_custom_archived_at DateTimeHelper.to_rfc3339(archived_at) end |
#to_custom_created_at ⇒ Object
415 416 417 |
# File 'lib/advanced_billing/models/coupon.rb', line 415 def to_custom_created_at DateTimeHelper.to_rfc3339(created_at) end |
#to_custom_end_date ⇒ Object
407 408 409 |
# File 'lib/advanced_billing/models/coupon.rb', line 407 def to_custom_end_date DateTimeHelper.to_rfc3339(end_date) end |
#to_custom_start_date ⇒ Object
403 404 405 |
# File 'lib/advanced_billing/models/coupon.rb', line 403 def to_custom_start_date DateTimeHelper.to_rfc3339(start_date) end |
#to_custom_updated_at ⇒ Object
419 420 421 |
# File 'lib/advanced_billing/models/coupon.rb', line 419 def to_custom_updated_at DateTimeHelper.to_rfc3339(updated_at) end |