Skip to content

Commit

Permalink
handle 400 errors and XML returns, correct comments to match parms
Browse files Browse the repository at this point in the history
  • Loading branch information
neophiliac committed Jan 9, 2011
1 parent 11c76ef commit c28e2ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/simplepay.rb
Expand Up @@ -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 = ''
Expand Down
11 changes: 6 additions & 5 deletions lib/simplepay/helpers/notification_helper.rb
Expand Up @@ -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? ...
Expand All @@ -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
Expand Down

0 comments on commit c28e2ad

Please sign in to comment.