class Transbank::Onepay::Item

Attributes

additional_data[R]

@return additional_data [String] A string with whatever additional data the Merchant might want to add

amount[R]

@return amount [Integer] The value of each unit of [Item]

description[R]

@return [String] An item's description

expire[R]

@return expire [Integer] Expiry for the Item

quantity[R]

@return quantity [Integer] How many of units of [Item]

Public Class Methods

new(opts = {}) click to toggle source

@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

==(another_item) click to toggle source

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
additional_data=(additional_data) click to toggle source

@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
amount=(amount) click to toggle source

@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
description=(description) click to toggle source

@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
eql?(another_item) click to toggle source

Alias for #==

# File lib/transbank/sdk/onepay/models/item.rb, line 98
def eql?(another_item)
  self.==(another_item)
end
expire=(expire) click to toggle source

@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
quantity=(quantity) click to toggle source

@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
total() click to toggle source

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