Class: Twoctwop::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
# File 'lib/twoctwop/response.rb', line 10

def initialize(body)
  raise "No private key defined" if Twoctwop::Config.private_key.nil?
  raise "No certificate defined" if Twoctwop::Config.certificate.nil?

  @certificate = OpenSSL::X509::Certificate.new(Twoctwop::Config.certificate)
  @private_key = OpenSSL::PKey::RSA.new(Twoctwop::Config.private_key, Twoctwop::Config.passphrase)

  @body = OpenSSL::PKCS7.new(Base64.strict_decode64(body))
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/twoctwop/response.rb', line 8

def body
  @body
end

#certificateObject

Returns the value of attribute certificate.



8
9
10
# File 'lib/twoctwop/response.rb', line 8

def certificate
  @certificate
end

#private_keyObject

Returns the value of attribute private_key.



8
9
10
# File 'lib/twoctwop/response.rb', line 8

def private_key
  @private_key
end

Instance Method Details

#decrypt_bodyObject



20
21
22
# File 'lib/twoctwop/response.rb', line 20

def decrypt_body
  Hashie::Mash.new(Hash.from_xml(body.decrypt(private_key, certificate))['PaymentResponse'])
end