Class: Transbank::Onepay::Item

Inherits:
Object
  • Object
show all
Includes:
Utils::JSONUtils
Defined in:
lib/transbank/sdk/onepay/models/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::JSONUtils

included, #jsonify, #transform_hash_keys, #underscore

Constructor Details

#initialize(opts = {}) ⇒ Item

Merchant might want to add

Parameters:

  • opts (Hash) (defaults to: {})

    options Hash

  • description (String)

    The item’s description

  • quantity (Integer)

    How many of units of [Item]

  • amount (Integer)

    The value of each unit of [Item]

  • additional_data (String)

    A string with whatever additional data the

  • expire (Integer)

    Expiry for the Item

Raises:

  • (ItemError)

    when opts is not a [Hash]



30
31
32
33
34
35
36
37
38
# 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

Instance Attribute Details

#additional_dataObject

Merchant might want to add



18
19
20
# File 'lib/transbank/sdk/onepay/models/item.rb', line 18

def additional_data
  @additional_data
end

#amountObject

Returns the value of attribute amount.



14
15
16
# File 'lib/transbank/sdk/onepay/models/item.rb', line 14

def amount
  @amount
end

#descriptionString

Returns An item’s description.

Returns:

  • (String)

    An item’s description



8
9
10
# File 'lib/transbank/sdk/onepay/models/item.rb', line 8

def description
  @description
end

#expireObject

Returns the value of attribute expire.



21
22
23
# File 'lib/transbank/sdk/onepay/models/item.rb', line 21

def expire
  @expire
end

#quantityObject

Returns the value of attribute quantity.



11
12
13
# File 'lib/transbank/sdk/onepay/models/item.rb', line 11

def quantity
  @quantity
end

Instance Method Details

#==(another_item) ⇒ boolean

Override == to allow comparison between [Item]s

Returns:

  • (boolean)

    true if equal, false otherwise



89
90
91
92
93
94
95
# 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

#eql?(another_item) ⇒ Boolean

Alias for #==

Returns:

  • (Boolean)


98
99
100
# File 'lib/transbank/sdk/onepay/models/item.rb', line 98

def eql?(another_item)
  self.==(another_item)
end

#totalNumeric

Return the total amount to pay for the Item, that is, amount * quantity

Returns:

  • (Numeric)

    the total amount to pay for the [Item]



83
84
85
# File 'lib/transbank/sdk/onepay/models/item.rb', line 83

def total
  self.quantity * self.amount
end