class Transbank::Webpay::Document
Constants
- NAMESPACES
- SOAPENV
- XML_HEADER
Attributes
unsigned_xml[R]
Public Class Methods
new(action, params = {})
click to toggle source
# File lib/transbank/webpay/document.rb, line 16 def initialize(action, params = {}) camelcase_action = camelcase(action).to_sym @unsigned_xml = build_xml camelcase_action, params end
Public Instance Methods
document()
click to toggle source
# File lib/transbank/webpay/document.rb, line 33 def document @document ||= Nokogiri::XML(signed_xml).tap do |signed_document| x509data = signed_document.at_xpath("//*[local-name()='X509Data']") new_data = x509data.clone new_data.set_attribute('xmlns:ds', 'http://www.w3.org/2000/09/xmldsig#') n = Nokogiri::XML::Node.new('wsse:SecurityTokenReference', signed_document) n.add_child(new_data) x509data.add_next_sibling(n) end end
envelope()
click to toggle source
# File lib/transbank/webpay/document.rb, line 25 def envelope @envelope ||= unsigned_document.at_xpath("//env:Envelope") end
signed_xml()
click to toggle source
# File lib/transbank/webpay/document.rb, line 44 def signed_xml envelope.prepend_child(XML_HEADER) unsigned_xml = unsigned_document.to_s signer = Signer.new(unsigned_xml) signer.cert = Transbank::Webpay::Vault.cert signer.private_key = Transbank::Webpay::Vault.private_key signer.document.xpath('//soapenv:Body', soapenv: SOAPENV).each do |node| signer.digest!(node) end signer.sign!(:issuer_serial => true) signer.to_xml end
to_xml()
click to toggle source
# File lib/transbank/webpay/document.rb, line 29 def to_xml document.to_xml(save_with: 0) end
unsigned_document()
click to toggle source
# File lib/transbank/webpay/document.rb, line 21 def unsigned_document @unsigned_document ||= Nokogiri::XML(unsigned_xml) end
Private Instance Methods
build_tag(xml, name, value)
click to toggle source
# File lib/transbank/webpay/document.rb, line 76 def build_tag(xml, name, value) return xml.tag!(name, value) unless value.is_a?(Hash) xml.tag!(name) do value.each { |k, v| build_tag(xml, k, v) } end end
build_xml(action, params = {})
click to toggle source
# File lib/transbank/webpay/document.rb, line 62 def build_xml(action, params = {}) xml = Builder::XmlMarkup.new indent: 0 xml.instruct! :xml, encoding: 'UTF-8' xml.env(:Envelope, NAMESPACES) do xml.env(:Body) do xml.tns(action) do params.each do |name, value| build_tag(xml, name, value) end end end end end