Class: Twocheckout::ValidateResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/twocheckout/validate_response.rb

Class Method Summary collapse

Class Method Details

.notification(options) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/twocheckout/validate_response.rb', line 20

def self.notification(options)
  if valid?(options[:sale_id], options[:vendor_id], options[:invoice_id], options[:secret], options[:md5_hash])
    {:code => "PASS", :message => "Hash Matched"}
  else
    {:code => "FAIL", :message => "Hash Mismatch"}
  end
end

.purchase(options) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/twocheckout/validate_response.rb', line 11

def self.purchase(options)
  oid = options[:demo] == 'Y' ? 1 : options[:order_number]
  if valid?(options[:secret], options[:sid], oid, options[:total], options[:key])
    {:code => "PASS", :message => "Hash Matched"}
  else
    {:code => "FAIL", :message => "Hash Mismatch"}
  end
end

.valid?(arg1, arg2, arg3, arg4, key) ⇒ Boolean

Checks against MD5 Hash

Returns:

  • (Boolean)


7
8
9
# File 'lib/twocheckout/validate_response.rb', line 7

def self.valid?(arg1, arg2, arg3, arg4, key)
  Digest::MD5.hexdigest("#{arg1}#{arg2}#{arg3}#{arg4}").upcase == key
end