From b1989dde29bfb0182bf352afcab3e5c96db7873b Mon Sep 17 00:00:00 2001 From: Rob Chekaluk Date: Tue, 7 Jan 2014 18:06:16 -0500 Subject: [PATCH] Ensure IPN can be verified under Ruby 2.0 by setting header 'Accept-Encoding: identity' --- lib/paypal_adaptive/ipn_notification.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/paypal_adaptive/ipn_notification.rb b/lib/paypal_adaptive/ipn_notification.rb index 0bf9851..05a41c4 100644 --- a/lib/paypal_adaptive/ipn_notification.rb +++ b/lib/paypal_adaptive/ipn_notification.rb @@ -1,6 +1,7 @@ require 'net/http' require 'net/https' require 'json' +require 'rack/utils' module PaypalAdaptive class IpnNotification @@ -16,7 +17,8 @@ def initialize(env=nil) def send_back(data) data = "cmd=_notify-validate&#{data}" - url = URI.parse @paypal_base_url + path = "#{@paypal_base_url}/cgi-bin/webscr" + url = URI.parse path http = Net::HTTP.new(url.host, 443) http.use_ssl = true http.verify_mode = @verify_mode @@ -30,8 +32,10 @@ def send_back(data) http.ca_path = @ssl_cert_path unless @ssl_cert_path.blank? http.ca_file = @ssl_cert_file unless @ssl_cert_file.blank? - path = "#{@paypal_base_url}/cgi-bin/webscr" - response_data = http.post(path, data).body + req = Net::HTTP::Post.new(url.request_uri) + req.set_form_data(Rack::Utils.parse_nested_query(data)) + req['Accept-Encoding'] = 'identity' + response_data = http.request(req).body @verified = response_data == "VERIFIED" end