Class: PayplugRails::Payplug

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

Class Method Summary collapse

Class Method Details

.create_payment(amount, ipn_url, customer_hash = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/payplug_rails.rb', line 17

def self.create_payment(amount, ipn_url, customer_hash={})
  data = {
    currency: 'EUR',
    amount: amount,
    ipn_url: ipn_url,
    origin: "PayplugRails-"+PayplugRails::VERSION,
  }.merge(customer_hash).to_query

  key = OpenSSL::PKey::RSA.new PayplugRails.private_key
  raw_sign = key.sign(OpenSSL::Digest::SHA1.new, data)
  http_sign = CGI.escape(Base64.strict_encode64(raw_sign))
  http_data = CGI.escape(Base64.strict_encode64(data))

  return PayplugRails.url+"?data="+http_data+"&sign="+http_sign
end

.verify(request) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/payplug_rails.rb', line 33

def self.verify(request)
  # Verify the IPN contained in the http request
  if request.raw_post.blank?
    return false
  end
  signature = Base64.decode64(request.headers['HTTP_PAYPLUG_SIGNATURE'])
  body = request.raw_post
  key = OpenSSL::PKey::RSA.new PayplugRails.payplug_public_key
  status = key.verify(OpenSSL::Digest::SHA1.new, signature, body)
  return status
end