Class: MusicTodayApiWrapper::Resources::Purchase::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/purchase/invoice.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, sub_total, shipping, taxes) ⇒ Invoice

Returns a new instance of Invoice.



7
8
9
10
11
12
13
# File 'lib/resources/purchase/invoice.rb', line 7

def initialize(id, sub_total, shipping, taxes)
  @id = id
  @sub_total = sub_total.to_f
  @shipping = shipping.to_f
  @taxes = taxes.to_f
  @total = (@sub_total + @shipping + @taxes).round(2)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/resources/purchase/invoice.rb', line 5

def id
  @id
end

#shippingObject

Returns the value of attribute shipping.



5
6
7
# File 'lib/resources/purchase/invoice.rb', line 5

def shipping
  @shipping
end

#sub_totalObject

Returns the value of attribute sub_total.



5
6
7
# File 'lib/resources/purchase/invoice.rb', line 5

def sub_total
  @sub_total
end

#taxesObject

Returns the value of attribute taxes.



5
6
7
# File 'lib/resources/purchase/invoice.rb', line 5

def taxes
  @taxes
end

#totalObject

Returns the value of attribute total.



5
6
7
# File 'lib/resources/purchase/invoice.rb', line 5

def total
  @total
end

Class Method Details

.from_hash(hash) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/resources/purchase/invoice.rb', line 15

def self.from_hash(hash)
  totals = hash['billing']['totals']
  Invoice.new(hash['orderNumber'],
              totals['subtotal'],
              totals['shipping'],
              totals['totalTax'])
end