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
54 55 56 57 58 59 60 61 62 |
# File 'lib/nmi_direct_post/transaction.rb', line 54 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
68 69 70 |
# File 'lib/nmi_direct_post/transaction.rb', line 68 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
76 77 78 |
# File 'lib/nmi_direct_post/transaction.rb', line 76 def declined? 2 == response end |
#failed? ⇒ Boolean
72 73 74 |
# File 'lib/nmi_direct_post/transaction.rb', line 72 def failed? "failed" == condition end |
#pending? ⇒ Boolean
64 65 66 |
# File 'lib/nmi_direct_post/transaction.rb', line 64 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 44 45 46 47 48 |
# File 'lib/nmi_direct_post/transaction.rb', line 36 def save return false if invalid? if condition.blank? if 'void' == type reload @type = 'void' end end _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
50 51 52 |
# File 'lib/nmi_direct_post/transaction.rb', line 50 def save! save || raise(TransactionNotSavedError) end |
#void! ⇒ Object
80 81 82 83 |
# File 'lib/nmi_direct_post/transaction.rb', line 80 def void! @type='void' save end |