class Transbank::Onepay::Item
Attributes
@return additional_data
[String] A string with whatever additional data the Merchant might want to add
@return amount [Integer] The value of each unit of [Item]
@return [String] An item's description
@return expire [Integer] Expiry for the Item
@return quantity [Integer] How many of units of [Item]
Public Class Methods
@param [Hash] opts options Hash @param description [String] The item's description @param quantity [Integer] How many of units of [Item] @param amount [Integer] The value of each unit of [Item] @param additional_data
[String] A string with whatever additional data the Merchant might want to add @param expire [Integer] Expiry for the Item
@raise [ItemError] when opts is not a [Hash]
# File lib/transbank/sdk/onepay/models/item.rb, line 30 def initialize(opts = {}) raise Errors::ItemError, 'Item must be a Hash' unless opts.is_a? Hash opts = transform_hash_keys opts self.description = opts.fetch(:description) self.quantity = opts.fetch(:quantity) self.amount = opts.fetch(:amount) self.additional_data = opts.fetch(:additional_data, nil) self.expire = opts.fetch(:expire, nil) end
Public Instance Methods
Override == to allow comparison between [Item]s @return [boolean] true if equal, false otherwise
# File lib/transbank/sdk/onepay/models/item.rb, line 89 def ==(another_item) self.description == another_item.description && self.quantity == another_item.quantity && self.amount == another_item.amount && self.additional_data == another_item.additional_data && self.expire == another_item.expire end
@param additional_data
[String] A string with whatever additional data the Merchant might want to add
# File lib/transbank/sdk/onepay/models/item.rb, line 70 def additional_data=(additional_data) additional_data = '' if additional_data.nil? @additional_data = additional_data end
@param amount [Integer] The value of each unit of [Item] @raise [ItemError] when amount cannot be null. @raise [ArgumentError] when amount is not an Integer.
# File lib/transbank/sdk/onepay/models/item.rb, line 60 def amount=(amount) raise Errors::ItemError, "Amount cannot be null" if amount.nil? if amount != Integer(amount) raise ArgumentError, "Amount is not an Integer" end @amount = amount end
@param description [String] An item's description @raise [ItemError] when description is null
# File lib/transbank/sdk/onepay/models/item.rb, line 42 def description=(description) raise Errors::ItemError, "Description cannot be null" if description.nil? @description = description end
Alias for #==
# File lib/transbank/sdk/onepay/models/item.rb, line 98 def eql?(another_item) self.==(another_item) end
@param expire [Integer] Expiry for the Item
# File lib/transbank/sdk/onepay/models/item.rb, line 76 def expire=(expire) expire = expire || 0 @expire = expire end
@param quantity [Integer] How many of units of [Item] @raise [ItemError] when given quantity is nil or less than zero.
# File lib/transbank/sdk/onepay/models/item.rb, line 49 def quantity=(quantity) raise Errors::ItemError, "Quantity cannot be null" if quantity.nil? if quantity < 0 raise Errors::ItemError, "Quantity cannot be less than zero" end @quantity = quantity end
Return the total amount to pay for the Item
, that is, amount * quantity @return [Numeric] the total amount to pay for the [Item]
# File lib/transbank/sdk/onepay/models/item.rb, line 83 def total self.quantity * self.amount end