diff --git a/lib/simplepay.rb b/lib/simplepay.rb index 4e99dc4..76e9c45 100644 --- a/lib/simplepay.rb +++ b/lib/simplepay.rb @@ -17,7 +17,7 @@ module Simplepay - VERSION = '0.2.2.1' unless const_defined?(:VERSION) + VERSION = '0.2.2.2' unless const_defined?(:VERSION) mattr_accessor :aws_access_key_id @@aws_access_key_id = '' diff --git a/lib/simplepay/helpers/notification_helper.rb b/lib/simplepay/helpers/notification_helper.rb index 512a7b7..5181427 100644 --- a/lib/simplepay/helpers/notification_helper.rb +++ b/lib/simplepay/helpers/notification_helper.rb @@ -8,13 +8,13 @@ module Helpers ## # Adds a +valid_simplepay_request?+ method to your ActionControllers. # - # In order to use this, you should just directly hand your +params+ into - # the method: + # In order to use this, you should just directly hand your ipn endpoint and + # +params+ into the method: # # class FooController < ApplicationController # # def receive_ipn - # if valid_simplepay_request?(params) + # if valid_simplepay_request?(endpoint, request.query_params) # ... record something useful ... # else # ... maybe log a bad request? ... @@ -41,14 +41,15 @@ module NotificationHelper # def valid_simplepay_request?(endpoint, query) url = Simplepay.use_sandbox ? 'https://fps.sandbox.amazonaws.com' : 'https://fps.amazonaws.com' + endpoint = CGI.escape(endpoint) query = CGI.escape(query) url_and_query = url + "/?Action=VerifySignature&Version=2008-09-17&UrlEndPoint=#{endpoint}&HttpParameters=#{query}" + result = Nokogiri::XML(open(url_and_query)) rescue false - result.css("VerificationStatus").children.to_s == "Success" + return (result ? (result.css("VerificationStatus").children.to_s == "Success") : false) end - end end