Class: Mondo::Transaction

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#client, #raw_data

Instance Method Summary collapse

Methods inherited from Resource

boolean_accessor, boolean_reader, date_accessor, date_writer, #initialize, #inspect, #to_s

Constructor Details

This class inherits a constructor from Mondo::Resource

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#decline_reasonObject

Returns the value of attribute decline_reason.



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

def decline_reason
  @decline_reason
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#is_loadObject

Returns the value of attribute is_load.



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

def is_load
  @is_load
end

#metadataObject

Returns the value of attribute metadata.



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

def 
  @metadata
end

#notesObject

Returns the value of attribute notes.



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

def notes
  @notes
end

#settledObject

Returns the value of attribute settled.



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

def settled
  @settled
end

Instance Method Details

#account_balanceObject



28
29
30
# File 'lib/api/mondo/transaction.rb', line 28

def 
  Money.new(raw_data['account_balance'], currency)
end

#amountObject



20
21
22
# File 'lib/api/mondo/transaction.rb', line 20

def amount
  Money.new(raw_data['amount'], currency)
end

#attachmentsObject



57
58
59
60
61
# File 'lib/api/mondo/transaction.rb', line 57

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

#currencyObject



32
33
34
# File 'lib/api/mondo/transaction.rb', line 32

def currency
  Money::Currency.new(raw_data['currency'])
end

#declined?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/api/mondo/transaction.rb', line 16

def declined?
  raw_data['decline_reason'].present?
end

#local_amountObject



24
25
26
# File 'lib/api/mondo/transaction.rb', line 24

def local_amount
  Money.new(raw_data['local_amount'], local_currency)
end

#local_currencyObject



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

def local_currency
  Money::Currency.new(raw_data['local_currency'])
end

#merchant(opts = {}) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/api/mondo/transaction.rb', line 63

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



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/api/mondo/transaction.rb', line 44

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



40
41
42
# File 'lib/api/mondo/transaction.rb', line 40

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

#tagsObject



72
73
74
# File 'lib/api/mondo/transaction.rb', line 72

def tags
  ["tags"]
end

#tags=(t) ⇒ Object



76
77
78
# File 'lib/api/mondo/transaction.rb', line 76

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