Class: PaypalAdaptive::IpnNotification

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

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ IpnNotification

Returns a new instance of IpnNotification.



9
10
11
12
13
14
15
# File 'lib/ipn_notification.rb', line 9

def initialize(env=nil)
  @env = env
  @@config ||= PaypalAdaptive::Config.new(@env)
  @@paypal_base_url ||= @@config.paypal_base_url
  @@ssl_ca_cert_path ||= @@config.ssl_ca_cert_path
  @@ssl_cert_file ||= @@config.ssl_cert_file
end

Instance Method Details

#send_back(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ipn_notification.rb', line 17

def send_back(data)
  data = "cmd=_notify-validate&#{data}"
  url = URI.parse @@paypal_base_url
  http = Net::HTTP.new(url.host, 443)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER

  if @@ssl_cert_file
    cert = File.read(@@ssl_cert_file)
    http.cert = OpenSSL::X509::Certificate.new(cert)
    http.key = OpenSSL::PKey::RSA.new(cert)
  end

  if @@ssl_ca_cert_path
    http.ca_path = @@ssl_ca_cert_path unless @@ssl_ca_cert_path.nil? #/etc/ssl/certs'
  end

  path = "#{@@paypal_base_url}/cgi-bin/webscr"
  resp, response_data = http.post(path, data)

  @verified = response_data == "VERIFIED"
end

#verified?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ipn_notification.rb', line 40

def verified?
  @verified
end