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
- #ok? ⇒ Boolean
- #order_data ⇒ Object
- #order_id ⇒ Object
- #public_digest_valid? ⇒ Boolean
- #report_text ⇒ Object
- #return_code ⇒ Object
- #segmented? ⇒ Boolean
- #signature_valid? ⇒ Boolean
- #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
22 23 24 |
# File 'lib/epics/response.rb', line 22 def business_code doc.xpath("//xmlns:body/xmlns:ReturnCode", xmlns: "urn:org:ebics:H004").text end |
#business_error? ⇒ Boolean
18 19 20 |
# File 'lib/epics/response.rb', line 18 def business_error? !["", "000000"].include?(business_code) end |
#cipher ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/epics/response.rb', line 86 def cipher cipher = OpenSSL::Cipher.new("aes-128-cbc") cipher.decrypt cipher.padding = 0 cipher.key = transaction_key cipher end |
#digest_valid? ⇒ Boolean
56 57 58 59 60 61 62 63 |
# File 'lib/epics/response.rb', line 56 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
101 102 103 |
# File 'lib/epics/response.rb', line 101 def digester @digester ||= OpenSSL::Digest::SHA256.new end |
#last_segment? ⇒ Boolean
30 31 32 |
# File 'lib/epics/response.rb', line 30 def last_segment? !!doc.at_xpath("//xmlns:header/xmlns:mutable/*[@lastSegment='true']", xmlns: "urn:org:ebics:H004") end |
#ok? ⇒ Boolean
26 27 28 |
# File 'lib/epics/response.rb', line 26 def ok? !technical_error? & !business_error? end |
#order_data ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/epics/response.rb', line 78 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
52 53 54 |
# File 'lib/epics/response.rb', line 52 def order_id doc.xpath("//xmlns:header/xmlns:mutable/xmlns:OrderID", xmlns: "urn:org:ebics:H004").text end |
#public_digest_valid? ⇒ Boolean
72 73 74 75 76 |
# File 'lib/epics/response.rb', line 72 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
44 45 46 |
# File 'lib/epics/response.rb', line 44 def report_text doc.xpath("//xmlns:ReportText", xmlns: "urn:org:ebics:H004").first.content end |
#return_code ⇒ Object
38 39 40 41 42 |
# File 'lib/epics/response.rb', line 38 def return_code doc.xpath("//xmlns:ReturnCode", xmlns: "urn:org:ebics:H004").last.content rescue NoMethodError nil end |
#segmented? ⇒ Boolean
34 35 36 |
# File 'lib/epics/response.rb', line 34 def segmented? !!doc.at_xpath("//xmlns:header/xmlns:mutable/xmlns:SegmentNumber", xmlns: "urn:org:ebics:H004") end |
#signature_valid? ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/epics/response.rb', line 65 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 |
#technical_code ⇒ Object
14 15 16 |
# File 'lib/epics/response.rb', line 14 def technical_code doc.xpath("//xmlns:header/xmlns:mutable/xmlns:ReturnCode", xmlns: "urn:org:ebics:H004").text 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
48 49 50 |
# File 'lib/epics/response.rb', line 48 def transaction_id doc.xpath("//xmlns:header/xmlns:static/xmlns:TransactionID", xmlns: 'urn:org:ebics:H004').text end |
#transaction_key ⇒ Object
95 96 97 98 99 |
# File 'lib/epics/response.rb', line 95 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 |