Class: PaypalAdaptive::IpnNotification
- Inherits:
-
Object
- Object
- PaypalAdaptive::IpnNotification
- Defined in:
- lib/paypal_adaptive/ipn_notification.rb
Instance Method Summary collapse
-
#initialize(env = nil) ⇒ IpnNotification
constructor
A new instance of IpnNotification.
- #send_back(data) ⇒ Object
- #verified? ⇒ Boolean
Constructor Details
#initialize(env = nil) ⇒ IpnNotification
Returns a new instance of IpnNotification.
9 10 11 12 13 14 15 16 |
# File 'lib/paypal_adaptive/ipn_notification.rb', line 9 def initialize(env=nil) config = PaypalAdaptive.config(env) @paypal_base_url = config.paypal_base_url @ssl_cert_path = config.ssl_cert_path @ssl_cert_file = config.ssl_cert_file @api_cert_file = config.api_cert_file @verify_mode = config.verify_mode end |
Instance Method Details
#send_back(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/paypal_adaptive/ipn_notification.rb', line 18 def send_back(data) data = "cmd=_notify-validate&#{data}" 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 http.ca_path = @ssl_cert_path unless @ssl_cert_path.nil? if @api_cert_file cert = File.read(@api_cert_file) http.cert = OpenSSL::X509::Certificate.new(cert) http.key = OpenSSL::PKey::RSA.new(cert) end http.ca_path = @ssl_cert_path unless @ssl_cert_path.nil? || @ssl_cert_path.length == 0 http.ca_file = @ssl_cert_file unless @ssl_cert_file.nil? || @ssl_cert_file.length == 0 req = Net::HTTP::Post.new(url.request_uri) # we don't want #set_form_data to create a hash and get our # response out of order; Paypal IPN docs explicitly state that # the contents of #send_back must be in the same order as they # were recieved req.body = data req.content_type = 'application/x-www-form-urlencoded' req['Accept-Encoding'] = 'identity' response_data = http.request(req).body @verified = response_data == "VERIFIED" end |
#verified? ⇒ Boolean
48 49 50 |
# File 'lib/paypal_adaptive/ipn_notification.rb', line 48 def verified? @verified end |