Class: Epics::Response
- Inherits:
-
Object
- Object
- Epics::Response
- Defined in:
- lib/epics/response.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#doc ⇒ Object
Returns the value of attribute doc.
Instance Method Summary collapse
- #business_code ⇒ Object
- #business_error? ⇒ Boolean
- #cipher ⇒ Object
- #digest_valid? ⇒ Boolean
- #digester ⇒ Object
-
#initialize(client, xml) ⇒ Response
constructor
A new instance of Response.
- #last_segment? ⇒ Boolean
- #mutable_return_code ⇒ Object
- #ok? ⇒ Boolean
- #order_data ⇒ Object
- #order_id ⇒ Object
- #public_digest_valid? ⇒ Boolean
- #report_text ⇒ Object
- #return_code ⇒ Object
- #segmented? ⇒ Boolean
- #signature_valid? ⇒ Boolean
- #system_return_code ⇒ Object
- #technical_code ⇒ Object
- #technical_error? ⇒ Boolean
- #transaction_id ⇒ Object
- #transaction_key ⇒ Object
Constructor Details
#initialize(client, xml) ⇒ Response
Returns a new instance of Response.
5 6 7 8 |
# File 'lib/epics/response.rb', line 5 def initialize(client, xml) self.doc = Nokogiri::XML.parse(xml) self.client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/epics/response.rb', line 3 def client @client end |
#doc ⇒ Object
Returns the value of attribute doc.
2 3 4 |
# File 'lib/epics/response.rb', line 2 def doc @doc end |
Instance Method Details
#business_code ⇒ Object
30 31 32 |
# File 'lib/epics/response.rb', line 30 def business_code doc.xpath("//xmlns:body/xmlns:ReturnCode", xmlns: "urn:org:ebics:H004").text end |
#business_error? ⇒ Boolean
26 27 28 |
# File 'lib/epics/response.rb', line 26 def business_error? !["", "000000"].include?(business_code) end |
#cipher ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/epics/response.rb', line 94 def cipher cipher = OpenSSL::Cipher.new("aes-128-cbc") cipher.decrypt cipher.padding = 0 cipher.key = transaction_key cipher end |
#digest_valid? ⇒ Boolean
64 65 66 67 68 69 70 71 |
# File 'lib/epics/response.rb', line 64 def digest_valid? authenticated = doc.xpath("//*[@authenticate='true']").map(&:canonicalize).join digest_value = doc.xpath("//ds:DigestValue", ds: "http://www.w3.org/2000/09/xmldsig#").first digest = Base64.encode64(digester.digest(authenticated)).strip digest == digest_value.content end |
#digester ⇒ Object
109 110 111 |
# File 'lib/epics/response.rb', line 109 def digester @digester ||= OpenSSL::Digest::SHA256.new end |
#last_segment? ⇒ Boolean
38 39 40 |
# File 'lib/epics/response.rb', line 38 def last_segment? !!doc.at_xpath("//xmlns:header/xmlns:mutable/*[@lastSegment='true']", xmlns: "urn:org:ebics:H004") end |
#mutable_return_code ⇒ Object
18 19 20 |
# File 'lib/epics/response.rb', line 18 def mutable_return_code doc.xpath("//xmlns:header/xmlns:mutable/xmlns:ReturnCode", xmlns: "urn:org:ebics:H004").text end |
#ok? ⇒ Boolean
34 35 36 |
# File 'lib/epics/response.rb', line 34 def ok? !technical_error? & !business_error? end |
#order_data ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/epics/response.rb', line 86 def order_data order_data_encrypted = Base64.decode64(doc.xpath("//xmlns:OrderData", xmlns: 'urn:org:ebics:H004').first.content) data = (cipher.update(order_data_encrypted) + cipher.final) Zlib::Inflate.new.inflate(data) end |
#order_id ⇒ Object
60 61 62 |
# File 'lib/epics/response.rb', line 60 def order_id doc.xpath("//xmlns:header/xmlns:mutable/xmlns:OrderID", xmlns: "urn:org:ebics:H004").text end |
#public_digest_valid? ⇒ Boolean
80 81 82 83 84 |
# File 'lib/epics/response.rb', line 80 def public_digest_valid? encryption_pub_key_digest = doc.xpath("//xmlns:EncryptionPubKeyDigest", xmlns: 'urn:org:ebics:H004').first client.e.public_digest == encryption_pub_key_digest.content end |
#report_text ⇒ Object
52 53 54 |
# File 'lib/epics/response.rb', line 52 def report_text doc.xpath("//xmlns:ReportText", xmlns: "urn:org:ebics:H004").first.content end |
#return_code ⇒ Object
46 47 48 49 50 |
# File 'lib/epics/response.rb', line 46 def return_code doc.xpath("//xmlns:ReturnCode", xmlns: "urn:org:ebics:H004").last.content rescue NoMethodError nil end |
#segmented? ⇒ Boolean
42 43 44 |
# File 'lib/epics/response.rb', line 42 def segmented? !!doc.at_xpath("//xmlns:header/xmlns:mutable/xmlns:SegmentNumber", xmlns: "urn:org:ebics:H004") end |
#signature_valid? ⇒ Boolean
73 74 75 76 77 78 |
# File 'lib/epics/response.rb', line 73 def signature_valid? signature = doc.xpath("//ds:SignedInfo", ds: "http://www.w3.org/2000/09/xmldsig#").first.canonicalize signature_value = doc.xpath("//ds:SignatureValue", ds: "http://www.w3.org/2000/09/xmldsig#").first client.bank_x.key.verify(digester, Base64.decode64(signature_value.content), signature) end |
#system_return_code ⇒ Object
22 23 24 |
# File 'lib/epics/response.rb', line 22 def system_return_code doc.xpath("//xmlns:SystemReturnCode/xmlns:ReturnCode", xmlns: 'http://www.ebics.org/H000').text end |
#technical_code ⇒ Object
14 15 16 |
# File 'lib/epics/response.rb', line 14 def technical_code mutable_return_code.empty? ? system_return_code : mutable_return_code end |
#technical_error? ⇒ Boolean
10 11 12 |
# File 'lib/epics/response.rb', line 10 def technical_error? !["011000", "000000"].include?(technical_code) end |
#transaction_id ⇒ Object
56 57 58 |
# File 'lib/epics/response.rb', line 56 def transaction_id doc.xpath("//xmlns:header/xmlns:static/xmlns:TransactionID", xmlns: 'urn:org:ebics:H004').text end |
#transaction_key ⇒ Object
103 104 105 106 107 |
# File 'lib/epics/response.rb', line 103 def transaction_key transaction_key_encrypted = Base64.decode64(doc.xpath("//xmlns:TransactionKey", xmlns: 'urn:org:ebics:H004').first.content) @transaction_key ||= client.e.key.private_decrypt(transaction_key_encrypted) end |