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



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

def id
  SecureRandom.hex(3)
end

#status ⇒ Object



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

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

#success? ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/mock_braintree/transaction.rb', line 14

def success?
  if (status == 'authorized') || (status == 'submitted_for_settlement')
    true
  else
    false
  end
end

#transaction ⇒ Object



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

def transaction
  self
end