class SpreedlyCore::Transaction

Abstract class for all the different spreedly transactions

Attributes

amount[R]
checkout_url[R]
created_at[R]
currency_code[R]
gateway_token[R]
message[R]
on_test_gateway[R]
response[R]
signed[R]
state[R]
succeeded[R]
succeeded?[R]
token[R]
transaction_type[R]
updated_at[R]

Public Class Methods

find(token) click to toggle source

Lookup the transaction by its token. Returns the correct subclass

# 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) click to toggle source

Breaks enacapsulation a bit, but allow subclasses to register the 'transaction_type' they handle.

# 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
new(attrs={}) click to toggle source
Calls superclass method SpreedlyCore::Base::new
# File lib/spreedly-core-ruby/transactions.rb, line 28
def initialize(attrs={})
  super
  if(valid_signature?)
    verified!
  end
end

Public Instance Methods

pending?() click to toggle source
# File lib/spreedly-core-ruby/transactions.rb, line 43
def pending?
  state == "pending"
end
valid_signature?() click to toggle source
# 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!() click to toggle source
# File lib/spreedly-core-ruby/transactions.rb, line 35
def verified!
  @verified = true
end
verified?() click to toggle source
# File lib/spreedly-core-ruby/transactions.rb, line 39
def verified?
  @verified
end