Class: Samurai::Transaction

Inherits:
Base show all
Includes:
ActiveResourceSupport, CacheableByToken
Defined in:
lib/samurai/transaction.rb

Overview

This class represents a Samurai Transaction It can be used to query Transactions & capture/void/credit/reverse

Instance Method Summary collapse

Methods included from ActiveResourceSupport

included

Methods included from CacheableByToken

included, #save

Methods inherited from Base

#has_errors?, setup_site!

Instance Method Details

#capture(amount = nil, options = {}) ⇒ Object

Captures an authorization. Optionally specify an ‘amount` to do a partial capture of the initial authorization. The default is to capture the full amount of the authorization.



17
18
19
# File 'lib/samurai/transaction.rb', line 17

def capture(amount = nil, options = {})
  execute(:capture, {:amount => amount || self.amount}.reverse_merge(options))
end

#credit(amount = nil, options = {}) ⇒ Object

Create a credit or refund against the original transaction. Optionally accepts an ‘amount` to credit, the default is to credit the full value of the original amount



30
31
32
# File 'lib/samurai/transaction.rb', line 30

def credit(amount = nil, options = {})
  execute(:credit, {:amount => amount || self.amount}.reverse_merge(options))
end

#failed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/samurai/transaction.rb', line 44

def failed?
  !success?
end

#idObject Also known as: token

Alias for ‘transaction_token`



10
11
12
# File 'lib/samurai/transaction.rb', line 10

def id
  transaction_token
end

#reverse(amount = nil, options = {}) ⇒ Object

Reverse this transaction. First, tries a void. If a void is unsuccessful, (because the transaction has already settled) perform a credit for the full amount.



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

def reverse(amount = nil, options = {})
  execute(:reverse, {:amount => amount || self.amount}.reverse_merge(options))
end

#success?Boolean Also known as: success

Returns:

  • (Boolean)


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

def success?
  respond_to?(:processor_response) && processor_response && processor_response.success
end

#void(options = {}) ⇒ Object

Void this transaction. If the transaction has not yet been captured and settled it can be voided to prevent any funds from transferring.



23
24
25
# File 'lib/samurai/transaction.rb', line 23

def void(options = {})
  execute(:void, options)
end