libwebpayplus 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/configuration.rb +18 -0
- data/lib/libwebpay.rb +29 -0
- data/lib/utils.rb +42 -0
- data/lib/verifier.rb +60 -0
- data/lib/webpay.rb +69 -0
- data/lib/webpaycapture.rb +134 -0
- data/lib/webpaycomplete.rb +377 -0
- data/lib/webpaymallnormal.rb +312 -0
- data/lib/webpaynormal.rb +310 -0
- data/lib/webpaynullify.rb +137 -0
- data/lib/webpayoneclick.rb +440 -0
- metadata +90 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'signer'
|
2
|
+
require 'savon'
|
3
|
+
require_relative "verifier"
|
4
|
+
|
5
|
+
|
6
|
+
class WebpayNullify
|
7
|
+
|
8
|
+
def initialize(configuration)
|
9
|
+
|
10
|
+
@wsdl_path = ''
|
11
|
+
@ambient = configuration.environment
|
12
|
+
|
13
|
+
case @ambient
|
14
|
+
when 'INTEGRACION'
|
15
|
+
@wsdl_path='https://webpay3gint.transbank.cl/WSWebpayTransaction/cxf/WSCommerceIntegrationService?wsdl'
|
16
|
+
when 'CERTIFICACION'
|
17
|
+
@wsdl_path='https://webpay3gint.transbank.cl/WSWebpayTransaction/cxf/WSCommerceIntegrationService?wsdl'
|
18
|
+
when 'PRODUCCION'
|
19
|
+
@wsdl_path='https://webpay3g.transbank.cl/WSWebpayTransaction/cxf/WSCommerceIntegrationService?wsdl'
|
20
|
+
else
|
21
|
+
#Por defecto esta el ambiente de INTEGRACION
|
22
|
+
@wsdl_path='https://webpay3gint.transbank.cl/WSWebpayTransaction/cxf/WSCommerceIntegrationService?wsdl'
|
23
|
+
end
|
24
|
+
|
25
|
+
@commerce_code = configuration.commerce_code
|
26
|
+
@private_key = OpenSSL::PKey::RSA.new(configuration.private_key)
|
27
|
+
@public_cert = OpenSSL::X509::Certificate.new(configuration.public_cert)
|
28
|
+
@webpay_cert = OpenSSL::X509::Certificate.new(configuration.webpay_cert)
|
29
|
+
@client = Savon.client(wsdl: @wsdl_path)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
#######################################################
|
35
|
+
def nullify(authorizationCode, authorizedAmount, buyOrder, nullifyAmount, commercecode)
|
36
|
+
|
37
|
+
|
38
|
+
nullifyInput ={
|
39
|
+
"nullificationInput" => {
|
40
|
+
"authorizationCode" => authorizationCode,
|
41
|
+
"authorizedAmount" => authorizedAmount,
|
42
|
+
"buyOrder" => buyOrder,
|
43
|
+
"commerceId" => commercecode,
|
44
|
+
"nullifyAmount" => nullifyAmount
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
req = @client.build_request(:nullify, message: nullifyInput)
|
49
|
+
|
50
|
+
#Firmar documento
|
51
|
+
document = sign_xml(req)
|
52
|
+
puts document
|
53
|
+
|
54
|
+
begin
|
55
|
+
response = @client.call(:nullify) do
|
56
|
+
xml document.to_xml(:save_with => 0)
|
57
|
+
end
|
58
|
+
rescue Exception ,RuntimeError => e
|
59
|
+
puts "Ocurrio un error en la llamada a Webpay: "+e.message
|
60
|
+
response_array ={
|
61
|
+
"error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
|
62
|
+
}
|
63
|
+
|
64
|
+
return response_array
|
65
|
+
end
|
66
|
+
|
67
|
+
#Verificacion de certificado respuesta
|
68
|
+
tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)
|
69
|
+
|
70
|
+
if !Verifier.verify(response, tbk_cert)
|
71
|
+
puts "El Certificado de respuesta es Invalido."
|
72
|
+
response_array ={
|
73
|
+
"error_desc" => 'El Certificado de respuesta es Invalido'
|
74
|
+
}
|
75
|
+
return response_array
|
76
|
+
else
|
77
|
+
puts "El Certificado de respuesta es Valido."
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
response_document = Nokogiri::HTML(response.to_s)
|
82
|
+
|
83
|
+
authorizationCode = response_document.xpath("//authorizationcode").text
|
84
|
+
authorizationDate = response_document.xpath("//authorizationdate").text
|
85
|
+
balance = response_document.xpath("//balance").text
|
86
|
+
nullifiedAmount = response_document.xpath("//nullifiedamount").text
|
87
|
+
token = response_document.xpath("//token").text
|
88
|
+
|
89
|
+
response_array ={
|
90
|
+
"authorizationCode" => authorizationCode.to_s,
|
91
|
+
"authorizationDate" => authorizationDate.to_s,
|
92
|
+
"balance" => balance.to_s,
|
93
|
+
"nullifiedAmount" => nullifiedAmount.to_s,
|
94
|
+
"token" => token.to_s,
|
95
|
+
"error_desc" => 'TRX_OK'
|
96
|
+
}
|
97
|
+
|
98
|
+
puts 'respuesta: '
|
99
|
+
puts response_document
|
100
|
+
|
101
|
+
return response_array
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
#######################################################
|
106
|
+
def sign_xml (input_xml)
|
107
|
+
|
108
|
+
document = Nokogiri::XML(input_xml.body)
|
109
|
+
envelope = document.at_xpath("//env:Envelope")
|
110
|
+
envelope.prepend_child("<env:Header><wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' wsse:mustUnderstand='1'/></env:Header>")
|
111
|
+
xml = document.to_s
|
112
|
+
|
113
|
+
signer = Signer.new(xml)
|
114
|
+
|
115
|
+
signer.cert = OpenSSL::X509::Certificate.new(@public_cert)
|
116
|
+
signer.private_key = OpenSSL::PKey::RSA.new(@private_key)
|
117
|
+
|
118
|
+
signer.document.xpath("//soapenv:Body", { "soapenv" => "http://schemas.xmlsoap.org/soap/envelope/" }).each do |node|
|
119
|
+
signer.digest!(node)
|
120
|
+
end
|
121
|
+
|
122
|
+
signer.sign!(:issuer_serial => true)
|
123
|
+
signed_xml = signer.to_xml
|
124
|
+
|
125
|
+
document = Nokogiri::XML(signed_xml)
|
126
|
+
x509data = document.at_xpath("//*[local-name()='X509Data']")
|
127
|
+
new_data = x509data.clone()
|
128
|
+
new_data.set_attribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")
|
129
|
+
|
130
|
+
n = Nokogiri::XML::Node.new('wsse:SecurityTokenReference', document)
|
131
|
+
n.add_child(new_data)
|
132
|
+
x509data.add_next_sibling(n)
|
133
|
+
|
134
|
+
return document
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,440 @@
|
|
1
|
+
require 'signer'
|
2
|
+
require 'savon'
|
3
|
+
require_relative 'verifier'
|
4
|
+
require_relative 'utils'
|
5
|
+
|
6
|
+
|
7
|
+
class WebpayOneClick
|
8
|
+
|
9
|
+
def initialize(configuration)
|
10
|
+
|
11
|
+
|
12
|
+
@wsdl_path = ''
|
13
|
+
@ambient = configuration.environment
|
14
|
+
|
15
|
+
case @ambient
|
16
|
+
when 'INTEGRACION'
|
17
|
+
@wsdl_path='https://webpay3gint.transbank.cl/webpayserver/wswebpay/OneClickPaymentService?wsdl'
|
18
|
+
when 'CERTIFICACION'
|
19
|
+
@wsdl_path='https://webpay3gint.transbank.cl/webpayserver/wswebpay/OneClickPaymentService?wsdl'
|
20
|
+
when 'PRODUCCION'
|
21
|
+
@wsdl_path='https://webpay3g.transbank.cl/webpayserver/wswebpay/OneClickPaymentService?wsdl'
|
22
|
+
else
|
23
|
+
#Por defecto esta el ambiente de INTEGRACION
|
24
|
+
@wsdl_path='https://webpay3gint.transbank.cl/webpayserver/wswebpay/OneClickPaymentService?wsdl'
|
25
|
+
end
|
26
|
+
|
27
|
+
@commerce_code = configuration.commerce_code
|
28
|
+
@private_key = OpenSSL::PKey::RSA.new(configuration.private_key)
|
29
|
+
@public_cert = OpenSSL::X509::Certificate.new(configuration.public_cert)
|
30
|
+
@webpay_cert = OpenSSL::X509::Certificate.new(configuration.webpay_cert)
|
31
|
+
@client = Savon.client(wsdl: @wsdl_path)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
#######################################################
|
37
|
+
def initInscription(username, email, urlReturn)
|
38
|
+
|
39
|
+
initInput ={
|
40
|
+
"arg0" => {
|
41
|
+
"username" => username,
|
42
|
+
"email" => email,
|
43
|
+
"responseURL" => urlReturn
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
req = @client.build_request(:init_inscription, message: initInput)
|
49
|
+
|
50
|
+
#Firmar documento
|
51
|
+
document = sign_xml(req)
|
52
|
+
puts document
|
53
|
+
|
54
|
+
begin
|
55
|
+
response = @client.call(:init_inscription) do
|
56
|
+
xml document.to_xml(:save_with => 0)
|
57
|
+
end
|
58
|
+
rescue Exception, RuntimeError => e
|
59
|
+
puts "Ocurrio un error en la llamada a Webpay: "+e.message
|
60
|
+
response_array ={
|
61
|
+
"error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
|
62
|
+
}
|
63
|
+
return response_array
|
64
|
+
end
|
65
|
+
|
66
|
+
#Verificacion de certificado respuesta
|
67
|
+
tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)
|
68
|
+
|
69
|
+
if !Verifier.verify(response, tbk_cert)
|
70
|
+
puts "El Certificado de respuesta es Invalido."
|
71
|
+
response_array ={
|
72
|
+
"error_desc" => 'El Certificado de respuesta es Invalido'
|
73
|
+
}
|
74
|
+
return response_array
|
75
|
+
else
|
76
|
+
puts "El Certificado de respuesta es Valido."
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
token=''
|
81
|
+
response_document = Nokogiri::HTML(response.to_s)
|
82
|
+
response_document.xpath("//token").each do |token_value|
|
83
|
+
token = token_value.text
|
84
|
+
end
|
85
|
+
url=''
|
86
|
+
response_document.xpath("//urlwebpay").each do |url_value|
|
87
|
+
url = url_value.text
|
88
|
+
end
|
89
|
+
|
90
|
+
puts 'token: '+token
|
91
|
+
puts 'url: '+url
|
92
|
+
|
93
|
+
response_array ={
|
94
|
+
"token" => token.to_s,
|
95
|
+
"url" => url.to_s,
|
96
|
+
"error_desc" => 'TRX_OK'
|
97
|
+
}
|
98
|
+
|
99
|
+
return response_array
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
##############################################
|
105
|
+
def finishInscription(token)
|
106
|
+
|
107
|
+
finishInput ={
|
108
|
+
"arg0" => {
|
109
|
+
"token" => token
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
#Preparacion firma
|
114
|
+
req = @client.build_request(:finish_inscription, message: finishInput)
|
115
|
+
#firmar la peticion
|
116
|
+
document = sign_xml(req)
|
117
|
+
|
118
|
+
begin
|
119
|
+
puts "Iniciando finishInscription..."
|
120
|
+
response = @client.call(:finish_inscription) do
|
121
|
+
xml document.to_xml(:save_with => 0)
|
122
|
+
end
|
123
|
+
|
124
|
+
rescue Exception, RuntimeError => e
|
125
|
+
puts "Ocurrio un error en la llamada a Webpay: "+e.message
|
126
|
+
response_array ={
|
127
|
+
"error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
|
128
|
+
}
|
129
|
+
return response_array
|
130
|
+
end
|
131
|
+
|
132
|
+
#Se revisa que respuesta no sea nula.
|
133
|
+
if response
|
134
|
+
puts 'Respuesta finishInscription: '+ response.to_s
|
135
|
+
else
|
136
|
+
puts 'Webservice Webpay responde con null'
|
137
|
+
response_array ={
|
138
|
+
"error_desc" => 'Webservice Webpay responde con null'
|
139
|
+
}
|
140
|
+
return response_array
|
141
|
+
end
|
142
|
+
|
143
|
+
puts response
|
144
|
+
|
145
|
+
#Verificacion de certificado respuesta
|
146
|
+
tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)
|
147
|
+
|
148
|
+
if !Verifier.verify(response, tbk_cert)
|
149
|
+
puts "El Certificado de respuesta es Invalido."
|
150
|
+
response_array ={
|
151
|
+
"error_desc" => 'El Certificado de respuesta es Invalido'
|
152
|
+
}
|
153
|
+
return response_array
|
154
|
+
else
|
155
|
+
puts "El Certificado de respuesta es Valido."
|
156
|
+
end
|
157
|
+
|
158
|
+
response_document = Nokogiri::HTML(response.to_s)
|
159
|
+
puts response_document.to_s
|
160
|
+
|
161
|
+
responseCode = response_document.xpath("//responsecode").text
|
162
|
+
authCode = response_document.xpath("//authcode").text
|
163
|
+
tbkUser = response_document.xpath("//tbkuser").text
|
164
|
+
last4CardDigits = response_document.xpath("//last4carddigits").text
|
165
|
+
creditCardType = response_document.xpath("//creditcardtype").text
|
166
|
+
|
167
|
+
|
168
|
+
response_array ={
|
169
|
+
"responseCode" => responseCode.to_s,
|
170
|
+
"authCode" => authCode.to_s,
|
171
|
+
"tbkUser" => tbkUser.to_s,
|
172
|
+
"last4CardDigits" => last4CardDigits.to_s,
|
173
|
+
"creditCardType" => creditCardType.to_s,
|
174
|
+
"error_desc" => 'TRX_OK'
|
175
|
+
}
|
176
|
+
|
177
|
+
return response_array
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
##############################################
|
183
|
+
def authorize(buyOrder, tbkUser, username, amount)
|
184
|
+
|
185
|
+
authorizeInput ={
|
186
|
+
"arg0" => {
|
187
|
+
"buyOrder" => buyOrder,
|
188
|
+
"tbkUser" => tbkUser,
|
189
|
+
"username" => username,
|
190
|
+
"amount" => amount
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
#Preparacion firma
|
195
|
+
req = @client.build_request(:authorize, message: authorizeInput)
|
196
|
+
#firmar la peticion
|
197
|
+
document = sign_xml(req)
|
198
|
+
|
199
|
+
#Se realiza el getResult
|
200
|
+
begin
|
201
|
+
puts "Iniciando authorize..."
|
202
|
+
response = @client.call(:authorize) do
|
203
|
+
xml document.to_xml(:save_with => 0)
|
204
|
+
end
|
205
|
+
|
206
|
+
rescue Exception, RuntimeError => e
|
207
|
+
puts "Ocurrio un error en la llamada a Webpay: "+e.message
|
208
|
+
response_array ={
|
209
|
+
"error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
|
210
|
+
}
|
211
|
+
return response_array
|
212
|
+
end
|
213
|
+
|
214
|
+
#Se revisa que respuesta no sea nula.
|
215
|
+
if response
|
216
|
+
puts 'Respuesta authorize: '+ response.to_s
|
217
|
+
else
|
218
|
+
puts 'Webservice Webpay responde con null'
|
219
|
+
response_array ={
|
220
|
+
"error_desc" => 'Webservice Webpay responde con null'
|
221
|
+
}
|
222
|
+
return response_array
|
223
|
+
end
|
224
|
+
|
225
|
+
puts response
|
226
|
+
|
227
|
+
#Verificacion de certificado respuesta
|
228
|
+
tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)
|
229
|
+
|
230
|
+
if !Verifier.verify(response, tbk_cert)
|
231
|
+
puts "El Certificado de respuesta es Invalido."
|
232
|
+
response_array ={
|
233
|
+
"error_desc" => 'El Certificado de respuesta es Invalido'
|
234
|
+
}
|
235
|
+
return response_array
|
236
|
+
else
|
237
|
+
puts "El Certificado de respuesta es Valido."
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
response_document = Nokogiri::HTML(response.to_s)
|
242
|
+
puts response_document.to_s
|
243
|
+
|
244
|
+
responseCode = response_document.xpath("//responsecode").text
|
245
|
+
authCode = response_document.xpath("//authorizationcode").text
|
246
|
+
transactionId = response_document.xpath("//transactionid").text
|
247
|
+
last4CardDigits = response_document.xpath("//last4carddigits").text
|
248
|
+
creditCardType = response_document.xpath("//creditcardtype").text
|
249
|
+
|
250
|
+
|
251
|
+
response_array ={
|
252
|
+
"responseCode" => responseCode.to_s,
|
253
|
+
"authCode" => authCode.to_s,
|
254
|
+
"transactionId" => transactionId.to_s,
|
255
|
+
"last4CardDigits" => last4CardDigits.to_s,
|
256
|
+
"creditCardType" => creditCardType.to_s,
|
257
|
+
"error_desc" => 'TRX_OK'
|
258
|
+
}
|
259
|
+
|
260
|
+
return response_array
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
##############################################
|
266
|
+
def reverse(buyOrder)
|
267
|
+
|
268
|
+
reverseInput ={
|
269
|
+
"arg0" => {
|
270
|
+
"buyorder" => buyOrder
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
#Preparacion firma
|
275
|
+
req = @client.build_request(:reverse, message: reverseInput)
|
276
|
+
|
277
|
+
#firmar la peticion
|
278
|
+
document = sign_xml(req)
|
279
|
+
|
280
|
+
#Se realiza el getResult
|
281
|
+
begin
|
282
|
+
puts "Iniciando reverse..."
|
283
|
+
response = @client.call(:reverse) do
|
284
|
+
xml document.to_xml(:save_with => 0)
|
285
|
+
end
|
286
|
+
|
287
|
+
rescue Exception, RuntimeError => e
|
288
|
+
puts "Ocurrio un error en la llamada a Webpay: "+e.message
|
289
|
+
response_array ={
|
290
|
+
"error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
|
291
|
+
}
|
292
|
+
return response_array
|
293
|
+
end
|
294
|
+
|
295
|
+
#Se revisa que respuesta no sea nula.
|
296
|
+
if response
|
297
|
+
puts 'Respuesta reverse: '+ response.to_s
|
298
|
+
else
|
299
|
+
puts 'Webservice Webpay responde con null'
|
300
|
+
response_array ={
|
301
|
+
"error_desc" => 'Webservice Webpay responde con null'
|
302
|
+
}
|
303
|
+
return response_array
|
304
|
+
end
|
305
|
+
|
306
|
+
puts response
|
307
|
+
|
308
|
+
#Verificacion de certificado respuesta
|
309
|
+
tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)
|
310
|
+
|
311
|
+
if !Verifier.verify(response, tbk_cert)
|
312
|
+
puts "El Certificado de respuesta es Invalido."
|
313
|
+
response_array ={
|
314
|
+
"error_desc" => 'El Certificado de respuesta es Invalido'
|
315
|
+
}
|
316
|
+
return response_array
|
317
|
+
else
|
318
|
+
puts "El Certificado de respuesta es Valido."
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
response_document = Nokogiri::HTML(response.to_s)
|
323
|
+
puts response_document.to_s
|
324
|
+
|
325
|
+
response = response_document.xpath("//return").text
|
326
|
+
|
327
|
+
response_array ={
|
328
|
+
"response" => response.to_s,
|
329
|
+
"error_desc" => 'TRX_OK'
|
330
|
+
}
|
331
|
+
|
332
|
+
return response_array
|
333
|
+
end
|
334
|
+
|
335
|
+
|
336
|
+
##############################################
|
337
|
+
def removeUser(tbkUser, username)
|
338
|
+
|
339
|
+
removeInput ={
|
340
|
+
"arg0" => {
|
341
|
+
"tbkUser" => tbkUser,
|
342
|
+
"username" => username
|
343
|
+
}
|
344
|
+
}
|
345
|
+
|
346
|
+
#Preparacion firma
|
347
|
+
req = @client.build_request(:remove_user, message: removeInput)
|
348
|
+
#firmar la peticion
|
349
|
+
document = sign_xml(req)
|
350
|
+
#document = Util.signXml(req)
|
351
|
+
|
352
|
+
#Se realiza el getResult
|
353
|
+
begin
|
354
|
+
puts "Iniciando removeUser..."
|
355
|
+
response = @client.call(:remove_user) do
|
356
|
+
xml document.to_xml(:save_with => 0)
|
357
|
+
end
|
358
|
+
|
359
|
+
rescue Exception, RuntimeError => e
|
360
|
+
puts "Ocurrio un error en la llamada a Webpay: "+e.message
|
361
|
+
response_array ={
|
362
|
+
"error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
|
363
|
+
}
|
364
|
+
return response_array
|
365
|
+
end
|
366
|
+
|
367
|
+
#Se revisa que respuesta no sea nula.
|
368
|
+
if response
|
369
|
+
puts 'Respuesta remove: '+ response.to_s
|
370
|
+
else
|
371
|
+
puts 'Webservice Webpay responde con null'
|
372
|
+
response_array ={
|
373
|
+
"error_desc" => 'Webservice Webpay responde con null'
|
374
|
+
}
|
375
|
+
return response_array
|
376
|
+
end
|
377
|
+
|
378
|
+
puts response
|
379
|
+
|
380
|
+
#Verificacion de certificado respuesta
|
381
|
+
tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)
|
382
|
+
|
383
|
+
if !Verifier.verify(response, tbk_cert)
|
384
|
+
puts "El Certificado de respuesta es Invalido."
|
385
|
+
response_array ={
|
386
|
+
"error_desc" => 'El Certificado de respuesta es Invalido'
|
387
|
+
}
|
388
|
+
return response_array
|
389
|
+
else
|
390
|
+
puts "El Certificado de respuesta es Valido."
|
391
|
+
end
|
392
|
+
|
393
|
+
|
394
|
+
response_document = Nokogiri::HTML(response.to_s)
|
395
|
+
puts response_document.to_s
|
396
|
+
|
397
|
+
response = response_document.xpath("//return").text
|
398
|
+
|
399
|
+
response_array ={
|
400
|
+
"response" => response.to_s,
|
401
|
+
"error_desc" => 'TRX_OK'
|
402
|
+
}
|
403
|
+
|
404
|
+
return response_array
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
#######################################################
|
409
|
+
def sign_xml (input_xml)
|
410
|
+
|
411
|
+
document = Nokogiri::XML(input_xml.body)
|
412
|
+
envelope = document.at_xpath("//env:Envelope")
|
413
|
+
envelope.prepend_child("<env:Header><wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' wsse:mustUnderstand='1'/></env:Header>")
|
414
|
+
xml = document.to_s
|
415
|
+
|
416
|
+
signer = Signer.new(xml)
|
417
|
+
|
418
|
+
signer.cert = OpenSSL::X509::Certificate.new(@public_cert)
|
419
|
+
signer.private_key = OpenSSL::PKey::RSA.new(@private_key)
|
420
|
+
|
421
|
+
signer.document.xpath("//soapenv:Body", { "soapenv" => "http://schemas.xmlsoap.org/soap/envelope/" }).each do |node|
|
422
|
+
signer.digest!(node)
|
423
|
+
end
|
424
|
+
|
425
|
+
signer.sign!(:issuer_serial => true)
|
426
|
+
signed_xml = signer.to_xml
|
427
|
+
|
428
|
+
document = Nokogiri::XML(signed_xml)
|
429
|
+
x509data = document.at_xpath("//*[local-name()='X509Data']")
|
430
|
+
new_data = x509data.clone()
|
431
|
+
new_data.set_attribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")
|
432
|
+
|
433
|
+
n = Nokogiri::XML::Node.new('wsse:SecurityTokenReference', document)
|
434
|
+
n.add_child(new_data)
|
435
|
+
x509data.add_next_sibling(n)
|
436
|
+
|
437
|
+
return document
|
438
|
+
end
|
439
|
+
|
440
|
+
end
|