class Bfwd::Coupon
<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>
Attributes
{ "description" : "For unique coupon codes this is what the coupon applies to, usually subscription.", "verbs":["GET"] }
{ "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":["GET"] }
{ "description" : "ID of the user who last updated the entity.", "verbs":[] }
{ "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":["POST","GET"] }
{ "default" : "∞", "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":["POST","GET"] }
{ "description" : "The UTC DateTime when the object was created.", "verbs":[] }
{ "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":["POST","GET"] }
{ "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":["GET"] }
{ "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":["POST","GET"] }
{ "description" : "", "verbs":["POST","GET"] }
{ "description" : "For unique coupon codes this is the original coupon code, for example SUMMER", "verbs":["GET"] }
{ "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":["POST","GET"] }
{ "description" : "Name or ID of the product this coupon applies to. Requires a specific rate-plan to be set.", "verbs":["POST"] }
{ "description" : "", "verbs":["GET"] }
{ "description" : "", "verbs":["GET"] }
{ "description" : "Name or ID of the rate-plan this coupon applies to. ", "verbs":["POST"] }
{ "description" : "", "verbs":["GET"] }
{ "description" : "", "verbs":["GET"] }
{ "description" : "", "verbs":["GET"] }
{ "description" : "The UTC DateTime when the object was last updated.", "verbs":[] }
{ "description" : "", "verbs":["GET"] }
{ "default" : "∞", "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":["POST","GET"] }
{ "description" : "If the coupon was removed from the subscription this is the date and time from when it no ceased to be applied.", "verbs":["GET"] }
Public Class Methods
Attribute mapping from ruby-style variable name to JSON key.
# File lib/bf_ruby2/models/coupon.rb, line 114 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
Initializes the object @param [Hash] attributes Model attributes in the form of hash
# File lib/bf_ruby2/models/coupon.rb, line 177 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
Attribute type mapping.
# File lib/bf_ruby2/models/coupon.rb, line 145 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
Public Instance Methods
Checks equality by comparing each attribute. @param [Object] Object to be compared
# File lib/bf_ruby2/models/coupon.rb, line 353 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
Deserializes the data based on type @param string type Data type @param string value Value to be deserialized @return [Object] Deserialized data
# File lib/bf_ruby2/models/coupon.rb, line 419 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 =~ /\A(true|t|yes|y|1)\z/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 = Bfwd.const_get(type).new temp_model.build_from_hash(value) end end
Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value @param [Object] value Any valid value @return [Hash] Returns the value in the form of hash
# File lib/bf_ruby2/models/coupon.rb, line 485 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
Custom attribute writer method checking allowed values (enum). @param [Object] applies_to
Object to be assigned
# File lib/bf_ruby2/models/coupon.rb, line 343 def applies_to=(applies_to) validator = EnumAttributeValidator.new('String', ["none", "subscription", "account"]) unless validator.valid?(applies_to) fail ArgumentError, "invalid value for 'applies_to', must be one of #{validator.allowable_values}." end @applies_to = applies_to end
Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself
# File lib/bf_ruby2/models/coupon.rb, line 398 def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) self.class.swagger_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/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
@see the `==` method @param [Object] Object to be compared
# File lib/bf_ruby2/models/coupon.rb, line 385 def eql?(o) self == o end
Calculates hash code according to all attributes. @return [Fixnum] Hash code
# File lib/bf_ruby2/models/coupon.rb, line 391 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
Show invalid properties with the reasons. Usually used together with valid? @return Array for valid properies with the reasons
# File lib/bf_ruby2/models/coupon.rb, line 293 def list_invalid_properties invalid_properties = Array.new if @name.nil? invalid_properties.push("invalid value for 'name', name cannot be nil.") end if @coupon_code.nil? invalid_properties.push("invalid value for 'coupon_code', coupon_code cannot be nil.") end if @coupons.nil? invalid_properties.push("invalid value for 'coupons', coupons cannot be nil.") end if @uses.nil? invalid_properties.push("invalid value for 'uses', uses cannot be nil.") end if @parent_coupon_code_redeemable.nil? invalid_properties.push("invalid value for 'parent_coupon_code_redeemable', parent_coupon_code_redeemable cannot be nil.") end if @organization_id.nil? invalid_properties.push("invalid value for 'organization_id', organization_id cannot be nil.") end if @discounts.nil? invalid_properties.push("invalid value for 'discounts', discounts cannot be nil.") end return invalid_properties end
Returns the object in the form of hash @return [Hash] Returns the object in the form of hash
# File lib/bf_ruby2/models/coupon.rb, line 471 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
Returns the string representation of the object @return [String] String presentation of the object
# File lib/bf_ruby2/models/coupon.rb, line 459 def to_s to_hash.to_s end
Check to see if the all the properties in the model are valid @return true if the model is valid
# File lib/bf_ruby2/models/coupon.rb, line 328 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