Class: Transbank::Oneclick::Document
- Inherits:
-
Object
- Object
- Transbank::Oneclick::Document
- Defined in:
- lib/transbank/oneclick/document.rb
Constant Summary collapse
- SOAP_ENV =
'http://schemas.xmlsoap.org/soap/envelope/'- NS1 =
'http://webservices.webpayserver.transbank.com/'- WSSE =
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'- WSU =
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#cert ⇒ Object
Returns the value of attribute cert.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#params ⇒ Object
Returns the value of attribute params.
-
#private_key ⇒ Object
Returns the value of attribute private_key.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #body_canonicalize ⇒ Object
- #body_id ⇒ Object
- #body_node ⇒ Object
- #canonicalize ⇒ Object
- #digest_value ⇒ Object
- #digest_value_node ⇒ Object
-
#initialize(action, params = {}) ⇒ Document
constructor
A new instance of Document.
- #sign! ⇒ Object
- #signature_value ⇒ Object
- #signature_value_node ⇒ Object
- #signed_node ⇒ Object
- #signed_node_canonicalize ⇒ Object
Constructor Details
#initialize(action, params = {}) ⇒ Document
Returns a new instance of Document.
10 11 12 13 14 15 16 17 |
# File 'lib/transbank/oneclick/document.rb', line 10 def initialize(action, params = {}) self.cert = OpenSSL::X509::Certificate.new File.read(Transbank::Oneclick.configuration.cert_path) self.private_key = OpenSSL::PKey::RSA.new File.read(Transbank::Oneclick.configuration.key_path) self.action = action self.params = params self.doc = template.clone.doc sign! end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/transbank/oneclick/document.rb', line 4 def action @action end |
#cert ⇒ Object
Returns the value of attribute cert.
4 5 6 |
# File 'lib/transbank/oneclick/document.rb', line 4 def cert @cert end |
#doc ⇒ Object
Returns the value of attribute doc.
4 5 6 |
# File 'lib/transbank/oneclick/document.rb', line 4 def doc @doc end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/transbank/oneclick/document.rb', line 4 def params @params end |
#private_key ⇒ Object
Returns the value of attribute private_key.
4 5 6 |
# File 'lib/transbank/oneclick/document.rb', line 4 def private_key @private_key end |
#template ⇒ Object
Returns the value of attribute template.
4 5 6 |
# File 'lib/transbank/oneclick/document.rb', line 4 def template @template end |
Instance Method Details
#body_canonicalize ⇒ Object
39 40 41 |
# File 'lib/transbank/oneclick/document.rb', line 39 def body_canonicalize body_node.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0, nil, nil) end |
#body_id ⇒ Object
19 20 21 |
# File 'lib/transbank/oneclick/document.rb', line 19 def body_id OpenSSL::Digest::MD5.hexdigest(action.to_s + params.to_s + DateTime::now.to_s) end |
#body_node ⇒ Object
23 24 25 |
# File 'lib/transbank/oneclick/document.rb', line 23 def body_node doc.at_xpath('//SOAP-ENV:Body') end |
#canonicalize ⇒ Object
47 48 49 |
# File 'lib/transbank/oneclick/document.rb', line 47 def canonicalize doc.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0, nil, nil) end |
#digest_value ⇒ Object
51 52 53 |
# File 'lib/transbank/oneclick/document.rb', line 51 def digest_value Base64.encode64(OpenSSL::Digest::SHA1.digest(body_canonicalize)).gsub("\n", '') end |
#digest_value_node ⇒ Object
31 32 33 |
# File 'lib/transbank/oneclick/document.rb', line 31 def digest_value_node doc.at_xpath '//ds:DigestValue', {'ds' => 'http://www.w3.org/2000/09/xmldsig#'} end |
#sign! ⇒ Object
59 60 61 62 |
# File 'lib/transbank/oneclick/document.rb', line 59 def sign! digest_value_node.content = digest_value signature_value_node.content = signature_value end |
#signature_value ⇒ Object
55 56 57 |
# File 'lib/transbank/oneclick/document.rb', line 55 def signature_value Base64.encode64(private_key.sign(OpenSSL::Digest::SHA1.new, signed_node_canonicalize)).gsub("\n", '') end |
#signature_value_node ⇒ Object
35 36 37 |
# File 'lib/transbank/oneclick/document.rb', line 35 def signature_value_node doc.at_xpath '//ds:SignatureValue', {'ds' => 'http://www.w3.org/2000/09/xmldsig#'} end |
#signed_node ⇒ Object
27 28 29 |
# File 'lib/transbank/oneclick/document.rb', line 27 def signed_node doc.at_xpath '//ds:SignedInfo', {'ds' => 'http://www.w3.org/2000/09/xmldsig#'} end |
#signed_node_canonicalize ⇒ Object
43 44 45 |
# File 'lib/transbank/oneclick/document.rb', line 43 def signed_node_canonicalize signed_node.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0, nil, nil) end |