Class: Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/mock_braintree/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Transaction

Returns a new instance of Transaction.



6
7
8
9
10
11
12
# File 'lib/mock_braintree/transaction.rb', line 6

def initialize(hash = {})
  @amount = hash[:amount]
  @nonce = hash[:nonce]
  @id = id
  @options = hash.fetch(:options, nil)
  @submit_for_settlement = submit_for_settlement
end

Instance Attribute Details

#amount ⇒ Object (readonly)

Returns the value of attribute amount.



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

def amount
  @amount
end

#nonce ⇒ Object (readonly)

Returns the value of attribute nonce.



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

def nonce
  @nonce
end

Instance Method Details

#id ⇒ Object

def transaction self end



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

def id
  SecureRandom.hex(3)
end

#status ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mock_braintree/transaction.rb', line 14

def status
  if (amount.to_f < 2000) && (submit_for_settlement == true)
    'submitted_for_settlement'
  elsif (amount.to_f < 2000) && (submit_for_settlement == false)
    'authorized'
  elsif (amount.to_f >= 2000) && amount.to_i < 3000
    'processor_declined'
  elsif (amount.to_f >= 3000) && amount.to_i <= 3000.99
    'failed'
  else
    'authorized'
  end
end