Class: SpreedlyCore::Transaction
- Defined in:
- lib/spreedly-core-ruby/transactions.rb
Overview
Abstract class for all the different spreedly transactions
Direct Known Subclasses
AddPaymentMethodTransaction, AuthorizeTransaction, CaptureTransaction, CreditTransaction, PurchaseTransaction, RedactTransaction, RetainTransaction, VoidedTransaction
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#checkout_url ⇒ Object
readonly
Returns the value of attribute checkout_url.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#currency_code ⇒ Object
readonly
Returns the value of attribute currency_code.
-
#gateway_token ⇒ Object
readonly
Returns the value of attribute gateway_token.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#on_test_gateway ⇒ Object
readonly
Returns the value of attribute on_test_gateway.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#signed ⇒ Object
readonly
Returns the value of attribute signed.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#succeeded ⇒ Object
(also: #succeeded?)
readonly
Returns the value of attribute succeeded.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#transaction_type ⇒ Object
readonly
Returns the value of attribute transaction_type.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Class Method Summary collapse
-
.find(token) ⇒ Object
Lookup the transaction by its token.
-
.handles(transaction_type) ⇒ Object
Breaks enacapsulation a bit, but allow subclasses to register the ‘transaction_type’ they handle.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Transaction
constructor
A new instance of Transaction.
- #pending? ⇒ Boolean
- #valid_signature? ⇒ Boolean
- #verified! ⇒ Object
- #verified? ⇒ Boolean
Methods inherited from Base
configure, environment_key, gateway_token, gateway_token=, verify_get, verify_options, verify_post, verify_put, verify_request
Constructor Details
#initialize(attrs = {}) ⇒ Transaction
Returns a new instance of Transaction.
28 29 30 31 32 33 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 28 def initialize(attrs={}) super if(valid_signature?) verified! end end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def amount @amount end |
#checkout_url ⇒ Object (readonly)
Returns the value of attribute checkout_url.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def checkout_url @checkout_url end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def created_at @created_at end |
#currency_code ⇒ Object (readonly)
Returns the value of attribute currency_code.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def currency_code @currency_code end |
#gateway_token ⇒ Object (readonly)
Returns the value of attribute gateway_token.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def gateway_token @gateway_token end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def @message end |
#on_test_gateway ⇒ Object (readonly)
Returns the value of attribute on_test_gateway.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def on_test_gateway @on_test_gateway end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def response @response end |
#signed ⇒ Object (readonly)
Returns the value of attribute signed.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def signed @signed end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def state @state end |
#succeeded ⇒ Object (readonly) Also known as: succeeded?
Returns the value of attribute succeeded.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def succeeded @succeeded end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def token @token end |
#transaction_type ⇒ Object (readonly)
Returns the value of attribute transaction_type.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def transaction_type @transaction_type end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
4 5 6 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 4 def updated_at @updated_at end |
Class Method Details
.find(token) ⇒ Object
Lookup the transaction by its token. Returns the correct subclass
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 17 def self.find(token) return nil if token.nil? verify_get("/transactions/#{token}.xml", :has_key => "transaction") do |response| attrs = response.parsed_response["transaction"] klass = @@transaction_type_to_class[attrs["transaction_type"]] || self klass.new(attrs).tap do |transaction| transaction.verified! end end end |
.handles(transaction_type) ⇒ Object
Breaks enacapsulation a bit, but allow subclasses to register the ‘transaction_type’ they handle.
11 12 13 14 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 11 def self.handles(transaction_type) @@transaction_type_to_class ||= {} @@transaction_type_to_class[transaction_type] = self end |
Instance Method Details
#pending? ⇒ Boolean
43 44 45 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 43 def pending? state == "pending" end |
#valid_signature? ⇒ Boolean
47 48 49 50 51 52 53 54 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 47 def valid_signature? return false unless signed fields = signed["fields"] data = fields.collect do |field| self.instance_variable_get("@#{field}") end.join("|") (OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new(signed["algorithm"], SpreedlyCore::Base.secret, data)) == signed["signature"]) end |
#verified! ⇒ Object
35 36 37 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 35 def verified! @verified = true end |
#verified? ⇒ Boolean
39 40 41 |
# File 'lib/spreedly-core-ruby/transactions.rb', line 39 def verified? @verified end |