Class: Samurai::Transaction
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Samurai::Transaction
- 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
-
#capture(amount = nil, options = {}) ⇒ Object
Captures an authorization.
-
#credit(amount = nil, options = {}) ⇒ Object
Create a credit or refund against the original transaction.
- #failed? ⇒ Boolean
-
#id ⇒ Object
(also: #token)
Alias for ‘transaction_token`.
-
#reverse(amount = nil, options = {}) ⇒ Object
Reverse this transaction.
- #success? ⇒ Boolean (also: #success)
-
#void(options = {}) ⇒ Object
Void this transaction.
Methods included from ActiveResourceSupport
Methods included from CacheableByToken
Methods inherited from Base
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, = {}) execute(:capture, {:amount => amount || self.amount}.reverse_merge()) 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, = {}) execute(:credit, {:amount => amount || self.amount}.reverse_merge()) end |
#failed? ⇒ Boolean
44 45 46 |
# File 'lib/samurai/transaction.rb', line 44 def failed? !success? end |
#id ⇒ Object 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, = {}) execute(:reverse, {:amount => amount || self.amount}.reverse_merge()) end |
#success? ⇒ Boolean Also known as: success
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( = {}) execute(:void, ) end |