Class: NmiDirectPost::Transaction
- Defined in:
- lib/nmi_direct_post/transaction.rb
Constant Summary collapse
- SAFE_PARAMS =
[:customer_vault_id, :type, :amount]
Constants inherited from Base
Base::AUTH_PARAMS, Base::GET_URI, Base::NO_CONNECTION, Base::POST_URI
Instance Attribute Summary collapse
-
#auth_code ⇒ Object
readonly
Returns the value of attribute auth_code.
-
#avs_response ⇒ Object
readonly
Returns the value of attribute avs_response.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#cvv_response ⇒ Object
readonly
Returns the value of attribute cvv_response.
-
#dup_seconds ⇒ Object
readonly
Returns the value of attribute dup_seconds.
-
#order_id ⇒ Object
readonly
Returns the value of attribute order_id.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Base
#response, #response_code, #response_text
Class Method Summary collapse
Instance Method Summary collapse
- #cleared? ⇒ Boolean
- #customer_vault ⇒ Object
- #declined? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(attributes) ⇒ Transaction
constructor
A new instance of Transaction.
- #pending? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
- #void! ⇒ Object
Methods inherited from Base
establish_connection, generate_query_string, get, #logger, password, post, #success?, username
Constructor Details
#initialize(attributes) ⇒ Transaction
Returns a new instance of Transaction.
27 28 29 30 31 32 33 34 |
# File 'lib/nmi_direct_post/transaction.rb', line 27 def initialize(attributes) super() @type, @amount = attributes[:type].to_s, attributes[:amount].to_f @transaction_id = attributes[:transaction_id].to_i if attributes[:transaction_id] @customer_vault_id = attributes[:customer_vault_id].to_i if attributes[:customer_vault_id] reload if (finding_by_transaction_id? && self.valid?) @type, @amount = attributes[:type].to_s, attributes[:amount].to_f if ['void', 'capture'].include?(attributes[:type].to_s) end |
Instance Attribute Details
#auth_code ⇒ Object (readonly)
Returns the value of attribute auth_code.
13 14 15 |
# File 'lib/nmi_direct_post/transaction.rb', line 13 def auth_code @auth_code end |
#avs_response ⇒ Object (readonly)
Returns the value of attribute avs_response.
13 14 15 |
# File 'lib/nmi_direct_post/transaction.rb', line 13 def avs_response @avs_response end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
13 14 15 |
# File 'lib/nmi_direct_post/transaction.rb', line 13 def condition @condition end |
#cvv_response ⇒ Object (readonly)
Returns the value of attribute cvv_response.
13 14 15 |
# File 'lib/nmi_direct_post/transaction.rb', line 13 def cvv_response @cvv_response end |
#dup_seconds ⇒ Object (readonly)
Returns the value of attribute dup_seconds.
13 14 15 |
# File 'lib/nmi_direct_post/transaction.rb', line 13 def dup_seconds @dup_seconds end |
#order_id ⇒ Object (readonly)
Returns the value of attribute order_id.
13 14 15 |
# File 'lib/nmi_direct_post/transaction.rb', line 13 def order_id @order_id end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
14 15 16 |
# File 'lib/nmi_direct_post/transaction.rb', line 14 def transaction_id @transaction_id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/nmi_direct_post/transaction.rb', line 13 def type @type end |
Class Method Details
.find_by_transaction_id(transaction_id) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/nmi_direct_post/transaction.rb', line 49 def self.find_by_transaction_id(transaction_id) raise StandardError, "TransactionID cannot be blank" if transaction_id.blank? NmiDirectPost.logger.debug { "Looking up NMI transaction by transaction_id(#{transaction_id})" } begin new(:transaction_id => transaction_id) rescue TransactionNotFoundError return nil end end |
Instance Method Details
#cleared? ⇒ Boolean
63 64 65 |
# File 'lib/nmi_direct_post/transaction.rb', line 63 def cleared? "complete" == condition end |
#customer_vault ⇒ Object
85 86 87 |
# File 'lib/nmi_direct_post/transaction.rb', line 85 def customer_vault @customer_vault ||= CustomerVault.find_by_customer_vault_id(@customer_vault_id) unless @customer_vault_id.blank? end |
#declined? ⇒ Boolean
71 72 73 |
# File 'lib/nmi_direct_post/transaction.rb', line 71 def declined? 2 == response end |
#failed? ⇒ Boolean
67 68 69 |
# File 'lib/nmi_direct_post/transaction.rb', line 67 def failed? "failed" == condition end |
#pending? ⇒ Boolean
59 60 61 |
# File 'lib/nmi_direct_post/transaction.rb', line 59 def pending? 'pendingsettlement' == condition end |
#reload ⇒ Object
89 90 91 92 |
# File 'lib/nmi_direct_post/transaction.rb', line 89 def reload get(transaction_params) if finding_by_transaction_id? self end |
#save ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/nmi_direct_post/transaction.rb', line 36 def save void! if ('void' == type && condition.blank?) return false if self.invalid? _safe_params = safe_params logger.info { "Sending Direct Post Transaction to NMI: #{_safe_params}" } post([_safe_params, transaction_params].join('&')) valid?.tap { |_| reload if _ } end |
#save! ⇒ Object
45 46 47 |
# File 'lib/nmi_direct_post/transaction.rb', line 45 def save! save || raise(TransactionNotSavedError) end |
#void! ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/nmi_direct_post/transaction.rb', line 75 def void! @type='void' if condition.blank? return false if invalid? reload @type = 'void' end save end |