Class: Mondo::Transaction

Inherits:
Resource show all
Defined in:
lib/mondo/transaction.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#client, #raw_data

Instance Method Summary collapse

Methods inherited from Resource

date_accessor, date_writer, #initialize, #inspect, #to_s

Constructor Details

This class inherits a constructor from Mondo::Resource

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/mondo/transaction.rb', line 4

def amount
  @amount
end

#currencyObject

Returns the value of attribute currency.



4
5
6
# File 'lib/mondo/transaction.rb', line 4

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/mondo/transaction.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/mondo/transaction.rb', line 4

def id
  @id
end

#metadataObject

Returns the value of attribute metadata.



4
5
6
# File 'lib/mondo/transaction.rb', line 4

def 
  @metadata
end

#notesObject

Returns the value of attribute notes.



4
5
6
# File 'lib/mondo/transaction.rb', line 4

def notes
  @notes
end

Instance Method Details

#amount_with_currencyObject

TODO - proper currency library



14
15
16
# File 'lib/mondo/transaction.rb', line 14

def amount_with_currency
  "#{amount/100}#{currency}"
end

#attachmentsObject



35
36
37
38
39
# File 'lib/mondo/transaction.rb', line 35

def attachments
  @transactions ||= begin
    raw_data['attachments'].map { |tx| Attachment.new(tx, self.client) }
  end
end

#merchant(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/mondo/transaction.rb', line 41

def merchant(opts={})
  unless raw_data['merchant'].kind_of?(Hash)
    # Go and refetch the transaction with merchant info expanded
    self.raw_data['merchant'] = self.client.transaction(self.id, expand: [:merchant]).raw_data['merchant']
  end

  ::Mondo::Merchant.new(raw_data['merchant'], client) unless raw_data['merchant'].nil?
end

#register_attachment(args = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mondo/transaction.rb', line 22

def register_attachment(args={})
  attachment = Attachment.new(
    {
      external_id: self.id,
      file_url: args.fetch(:file_url),
      file_type: args.fetch(:file_type)
    },
    self.client
  )

  self.attachments << attachment if attachment.register
end

#save_metadataObject



18
19
20
# File 'lib/mondo/transaction.rb', line 18

def 
  self.client.api_patch("/transactions/#{self.id}", metadata: self.)
end

#tagsObject



50
51
52
# File 'lib/mondo/transaction.rb', line 50

def tags
  ["tags"]
end

#tags=(t) ⇒ Object



54
55
56
# File 'lib/mondo/transaction.rb', line 54

def tags=(t)
  ["tags"] = t
end