Class: PagseguroCatcher::Transaction::Base

Inherits:
Body
  • Object
show all
Defined in:
lib/pagseguro_catcher/transaction/base.rb

Instance Attribute Summary

Attributes inherited from Body

#body

Instance Method Summary collapse

Methods inherited from Body

#[], #method_missing

Constructor Details

#initialize(xml) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/pagseguro_catcher/transaction/base.rb', line 7

def initialize(xml)
  self.body = Hash.from_xml(xml)["transaction"]
  self.body.recursive_symbolize_keys! if self.body
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PagseguroCatcher::Transaction::Body

Instance Method Details

#amountObject



12
13
14
15
# File 'lib/pagseguro_catcher/transaction/base.rb', line 12

def amount
  @amount ||= PagseguroCatcher::Transaction::Amount.new(self.body)
  @amount
end

#dateObject



41
42
43
# File 'lib/pagseguro_catcher/transaction/base.rb', line 41

def date
  self[:date].to_datetime.change(:offset => "-0300")
end

#each_itemObject



37
38
39
# File 'lib/pagseguro_catcher/transaction/base.rb', line 37

def each_item
  self.items.each { |item| yield item }
end

#itemsObject



27
28
29
30
31
32
33
34
35
# File 'lib/pagseguro_catcher/transaction/base.rb', line 27

def items
  @items = []
  
  self[:items][:item].each do |item|
    @items << PagseguroCatcher::Transaction::Item.new(item)
  end
  
  @items
end

#last_event_dateObject



45
46
47
# File 'lib/pagseguro_catcher/transaction/base.rb', line 45

def last_event_date
  self[:lastEventDate].to_datetime.change(:offset => "-0300")
end

#payment_method_codeObject



61
62
63
# File 'lib/pagseguro_catcher/transaction/base.rb', line 61

def payment_method_code
  PAYMENT_CODES[self[:paymentMethod][:code].to_i]
end

#payment_method_typeObject



57
58
59
# File 'lib/pagseguro_catcher/transaction/base.rb', line 57

def payment_method_type
  PAYMENT_TYPES[self[:paymentMethod][:type].to_i]
end

#senderObject



17
18
19
20
# File 'lib/pagseguro_catcher/transaction/base.rb', line 17

def sender
  @sender ||= PagseguroCatcher::Transaction::Sender.new(self.body)
  @sender
end

#shippingObject



22
23
24
25
# File 'lib/pagseguro_catcher/transaction/base.rb', line 22

def shipping
  @shipping ||= PagseguroCatcher::Transaction::Shipping.new(self.body)
  @shipping
end

#transaction_statusObject



53
54
55
# File 'lib/pagseguro_catcher/transaction/base.rb', line 53

def transaction_status
  TRANSACTION_STATUS[self[:status].to_i]
end

#transaction_typeObject



49
50
51
# File 'lib/pagseguro_catcher/transaction/base.rb', line 49

def transaction_type
  TRANSACTION_TYPES[self[:type].to_i]
end