Skip to content

Commit 1ef53c6

Browse files
authored
Merge pull request #5 from pennylane-hq/vn/fix-hpb-request-for-h003
Use dynamic URN schema in requests based on client version
2 parents fc71f30 + 5eee11f commit 1ef53c6

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

lib/epics/client.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def HEV
144144
end
145145

146146
def HPB
147-
Nokogiri::XML(download(Epics::HPB)).xpath("//xmlns:PubKeyValue", xmlns: "urn:org:ebics:H004").each do |node|
147+
Nokogiri::XML(download(Epics::HPB)).xpath("//xmlns:PubKeyValue", xmlns: urn_schema).each do |node|
148148
type = node.parent.last_element_child.content
149149

150150
modulus = Base64.decode64(node.at_xpath(".//*[local-name() = 'Modulus']").content)
@@ -267,15 +267,15 @@ def Z54(from, to)
267267
end
268268

269269
def HAA
270-
Nokogiri::XML(download(Epics::HAA)).at_xpath("//xmlns:OrderTypes", xmlns: "urn:org:ebics:H004").content.split(/\s/)
270+
Nokogiri::XML(download(Epics::HAA)).at_xpath("//xmlns:OrderTypes", xmlns: urn_schema).content.split(/\s/)
271271
end
272272

273273
def HTD
274274
Nokogiri::XML(download(Epics::HTD)).tap do |htd|
275-
@iban ||= htd.at_xpath("//xmlns:AccountNumber[@international='true']", xmlns: "urn:org:ebics:H004").text rescue nil
276-
@bic ||= htd.at_xpath("//xmlns:BankCode[@international='true']", xmlns: "urn:org:ebics:H004").text rescue nil
277-
@name ||= htd.at_xpath("//xmlns:Name", xmlns: "urn:org:ebics:H004").text rescue nil
278-
@order_types ||= htd.search("//xmlns:OrderTypes", xmlns: "urn:org:ebics:H004").map{|o| o.content.split(/\s/) }.delete_if{|o| o == ""}.flatten
275+
@iban ||= htd.at_xpath("//xmlns:AccountNumber[@international='true']", xmlns: urn_schema).text rescue nil
276+
@bic ||= htd.at_xpath("//xmlns:BankCode[@international='true']", xmlns: urn_schema).text rescue nil
277+
@name ||= htd.at_xpath("//xmlns:Name", xmlns: urn_schema).text rescue nil
278+
@order_types ||= htd.search("//xmlns:OrderTypes", xmlns: urn_schema).map{|o| o.content.split(/\s/) }.delete_if{|o| o == ""}.flatten
279279
end.to_xml
280280
end
281281

lib/epics/generic_request.rb

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def timestamp
1919
def_delegators :client, :host_id, :user_id, :partner_id
2020

2121
def root
22-
"ebicsRequest"
22+
'ebicsRequest'
2323
end
2424

2525
def body
@@ -34,75 +34,78 @@ def header
3434

3535
def auth_signature
3636
Nokogiri::XML::Builder.new do |xml|
37-
xml.AuthSignature{
38-
xml.send('ds:SignedInfo') {
39-
xml.send('ds:CanonicalizationMethod', '', Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315")
40-
xml.send('ds:SignatureMethod', '', Algorithm: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
41-
xml.send('ds:Reference', '', URI: "#xpointer(//*[@authenticate='true'])") {
42-
xml.send('ds:Transforms') {
43-
xml.send('ds:Transform', '', Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315")
44-
}
45-
xml.send('ds:DigestMethod', '', Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256")
37+
xml.AuthSignature do
38+
xml.send('ds:SignedInfo') do
39+
xml.send('ds:CanonicalizationMethod', '', Algorithm: 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315')
40+
xml.send('ds:SignatureMethod', '', Algorithm: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256')
41+
xml.send('ds:Reference', '', URI: "#xpointer(//*[@authenticate='true'])") do
42+
xml.send('ds:Transforms') do
43+
xml.send('ds:Transform', '', Algorithm: 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315')
44+
end
45+
xml.send('ds:DigestMethod', '', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256')
4646
xml.send('ds:DigestValue', '')
47-
}
48-
}
47+
end
48+
end
4949
xml.send('ds:SignatureValue', '')
50-
}
50+
end
5151
end.doc.root
5252
end
5353

5454
def to_transfer_xml
5555
Nokogiri::XML::Builder.new do |xml|
56-
xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => 'urn:org:ebics:H004', 'Version' => 'H004', 'Revision' => '1') {
57-
xml.header(authenticate: true) {
58-
xml.static {
56+
xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => client.urn_schema,
57+
'Version' => client.version, 'Revision' => '1') do
58+
xml.header(authenticate: true) do
59+
xml.static do
5960
xml.HostID host_id
6061
xml.TransactionID transaction_id
61-
}
62-
xml.mutable {
62+
end
63+
xml.mutable do
6364
xml.TransactionPhase 'Transfer'
6465
xml.SegmentNumber(1, lastSegment: true)
65-
}
66-
}
66+
end
67+
end
6768
xml.parent.add_child(auth_signature)
68-
xml.body {
69-
xml.DataTransfer {
69+
xml.body do
70+
xml.DataTransfer do
7071
xml.OrderData encrypted_order_data
71-
}
72-
}
73-
}
72+
end
73+
end
74+
end
7475
end.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML, encoding: 'utf-8')
7576
end
7677

7778
def to_receipt_xml
7879
Nokogiri::XML::Builder.new do |xml|
79-
xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => 'urn:org:ebics:H004', 'Version' => 'H004', 'Revision' => '1') {
80-
xml.header(authenticate: true) {
81-
xml.static {
80+
xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => client.urn_schema,
81+
'Version' => client.version, 'Revision' => '1') do
82+
xml.header(authenticate: true) do
83+
xml.static do
8284
xml.HostID host_id
8385
xml.TransactionID(transaction_id)
84-
}
85-
xml.mutable {
86+
end
87+
xml.mutable do
8688
xml.TransactionPhase 'Receipt'
87-
}
88-
}
89+
end
90+
end
8991
xml.parent.add_child(auth_signature)
90-
xml.body {
91-
xml.TransferReceipt(authenticate: true) {
92+
xml.body do
93+
xml.TransferReceipt(authenticate: true) do
9294
xml.ReceiptCode 0
93-
}
94-
}
95-
}
95+
end
96+
end
97+
end
9698
end.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML, encoding: 'utf-8')
9799
end
98100

99101
def to_xml
100102
Nokogiri::XML::Builder.new do |xml|
101-
xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => 'urn:org:ebics:H004', 'Version' => 'H004', 'Revision'=> '1') {
103+
xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => client.urn_schema,
104+
'Version' => client.version, 'Revision' => '1') do
102105
xml.parent.add_child(header)
103106
xml.parent.add_child(auth_signature)
104107
xml.parent.add_child(body)
105-
}
108+
end
106109
end.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML, encoding: 'utf-8')
107110
end
108111
end

0 commit comments

Comments
 (0)