Class: SpreedlyCore::Transaction

Inherits:
Base
  • Object
show all
Defined in:
lib/spreedly_core/transactions.rb

Overview

Abstract class for all the different spreedly core transactions

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

configure, gateway_token, #initialize, login, verify_get, verify_options, verify_post, verify_put, verify_request

Constructor Details

This class inherits a constructor from SpreedlyCore::Base

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def amount
  @amount
end

#created_atObject (readonly)

Returns the value of attribute created_at.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def created_at
  @created_at
end

#currency_codeObject (readonly)

Returns the value of attribute currency_code.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def currency_code
  @currency_code
end

#gateway_tokenObject (readonly)

Returns the value of attribute gateway_token.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def gateway_token
  @gateway_token
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def message
  @message
end

#on_test_gatewayObject (readonly)

Returns the value of attribute on_test_gateway.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def on_test_gateway
  @on_test_gateway
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def response
  @response
end

#succeededObject (readonly) Also known as: succeeded?

Returns the value of attribute succeeded.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def succeeded
  @succeeded
end

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def token
  @token
end

#transaction_typeObject (readonly)

Returns the value of attribute transaction_type.



4
5
6
# File 'lib/spreedly_core/transactions.rb', line 4

def transaction_type
  @transaction_type
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



4
5
6
# File 'lib/spreedly_core/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
# File 'lib/spreedly_core/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)
  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/transactions.rb', line 11

def self.handles(transaction_type)
  @@transaction_type_to_class ||= {}
  @@transaction_type_to_class[transaction_type] = self
end