37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/webpaynormal.rb', line 37
def initTransaction(amount, buyOrder, sessionId, urlReturn, urlFinal)
initInput ={
"wsInitTransactionInput" => {
"wSTransactionType" => "TR_NORMAL_WS",
"buyOrder" => buyOrder,
"sessionId" => sessionId,
"returnURL" => urlReturn,
"finalURL" => urlFinal,
"transactionDetails" => {
"sharesAmount" => nil,
"sharesNumber" => nil,
"amount" => amount,
"commerceCode" => @commerce_code,
"buyOrder" => buyOrder
}
}
}
req = @client.build_request(:init_transaction, message: initInput)
document = sign_xml(req)
puts document
begin
response = @client.call(:init_transaction) do
xml document.to_xml(:save_with => 0)
end
rescue Exception, RuntimeError => e
puts "Ocurrio un error en la llamada a Webpay: "+e.message
response_array ={
"error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
}
return response_array
end
tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)
if !Verifier.verify(response, tbk_cert)
puts "El Certificado de respuesta es Invalido."
response_array ={
"error_desc" => 'El Certificado de respuesta es Invalido'
}
return response_array
else
puts "El Certificado de respuesta es Valido."
end
token=''
response_document = Nokogiri::HTML(response.to_s)
response_document.xpath("//token").each do |token_value|
token = token_value.text
end
url=''
response_document.xpath("//url").each do |url_value|
url = url_value.text
end
puts 'token: '+token
puts 'url: '+url
response_array ={
"token" => token.to_s,
"url" => url.to_s,
"error_desc" => "TRX_OK"
}
return_array ={
"request" => initInput['wsInitTransactionInput'],
"response" => response_array
}
return return_array
end
|