transbank-webpay 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/transbank/webpay.rb +9 -8
- data/lib/transbank/webpay/document.rb +8 -8
- data/lib/transbank/webpay/reader.rb +2 -2
- data/lib/transbank/webpay/validations.rb +16 -12
- data/lib/transbank/webpay/vault.rb +27 -0
- data/lib/transbank/webpay/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e41cf49e63380f433816c8ffeab129a4439af783
|
4
|
+
data.tar.gz: 2b4a58573ff7140c13de428a2054a48606878220
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 159796edc3f3ee02ab7f39aaa0b8703e0571012205101edeb8762276f149961e7ed63c4a776ce45afad0ca14f5f3ce5a85fb17d7c0c4468f4ed3baf39ea78688
|
7
|
+
data.tar.gz: fb85fa5eb42c292da501c63211531b81d9c296817df4e046926d13aa4bf380695dd9a10256b3704db3d328f1ced29037ef52d1d1d0a7f1f996fc7512f68cb7e9
|
data/lib/transbank/webpay.rb
CHANGED
@@ -7,6 +7,7 @@ require 'builder'
|
|
7
7
|
|
8
8
|
require 'transbank/webpay/version'
|
9
9
|
require 'transbank/webpay/configuration'
|
10
|
+
require 'transbank/webpay/vault'
|
10
11
|
require 'transbank/webpay/validations'
|
11
12
|
require 'transbank/webpay/struct'
|
12
13
|
require 'transbank/webpay/reader'
|
@@ -23,19 +24,19 @@ require 'transbank/webpay/api'
|
|
23
24
|
module Transbank
|
24
25
|
module Webpay
|
25
26
|
class << self
|
26
|
-
|
27
|
+
attr_reader :configuration
|
27
28
|
|
28
29
|
# Delegate api
|
29
30
|
Api.instance_methods.each { |m| define_method(m) { |*args| api.send(m, *args) } }
|
30
|
-
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def configure
|
33
|
+
@configuration ||= Configuration.new
|
34
|
+
yield(@configuration)
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
def api
|
38
|
+
@api ||= Api.new
|
39
|
+
end
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -46,8 +46,8 @@ module Transbank
|
|
46
46
|
unsigned_xml = unsigned_document.to_s
|
47
47
|
|
48
48
|
signer = Signer.new(unsigned_xml)
|
49
|
-
signer.cert = cert
|
50
|
-
signer.private_key = private_key
|
49
|
+
signer.cert = Transbank::Webpay::Vault.cert
|
50
|
+
signer.private_key = Transbank::Webpay::Vault.private_key
|
51
51
|
|
52
52
|
signer.document.xpath('//soapenv:Body', soapenv: SOAPENV).each do |node|
|
53
53
|
signer.digest!(node)
|
@@ -81,13 +81,13 @@ module Transbank
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
def cert
|
85
|
-
|
86
|
-
end
|
84
|
+
# def cert
|
85
|
+
# @cert ||= OpenSSL::X509::Certificate.new open(Transbank::Webpay.configuration.cert_path)
|
86
|
+
# end
|
87
87
|
|
88
|
-
def private_key
|
89
|
-
|
90
|
-
end
|
88
|
+
# def private_key
|
89
|
+
# @private_key ||= OpenSSL::PKey::RSA.new open(Transbank::Webpay.configuration.key_path)
|
90
|
+
# end
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -27,7 +27,7 @@ module Transbank
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def response_code_display
|
30
|
-
RESPONSE_CODE.fetch(action, RESPONSE_CODE[:default]).fetch(
|
30
|
+
RESPONSE_CODE.fetch(action, RESPONSE_CODE[:default]).fetch(xml_response_code, xml_response_code)
|
31
31
|
end
|
32
32
|
|
33
33
|
def body
|
@@ -56,7 +56,7 @@ module Transbank
|
|
56
56
|
doc.xpath("//faultstring")
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def xml_response_code
|
60
60
|
doc.xpath("//responseCode").text
|
61
61
|
end
|
62
62
|
|
@@ -29,21 +29,21 @@ module Transbank
|
|
29
29
|
Base64.encode64(digest).strip
|
30
30
|
end
|
31
31
|
|
32
|
-
def server_cert
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
32
|
+
# def server_cert
|
33
|
+
# @server_cert ||= begin
|
34
|
+
# path = Transbank::Webpay.configuration.server_cert_path
|
35
|
+
# OpenSSL::X509::Certificate.new File.read(path)
|
36
|
+
# end
|
37
|
+
# end
|
38
38
|
|
39
|
-
def pub_key
|
40
|
-
|
41
|
-
end
|
39
|
+
# def pub_key
|
40
|
+
# server_cert.public_key
|
41
|
+
# end
|
42
42
|
|
43
43
|
# Validations
|
44
44
|
def validate_response_code!
|
45
|
-
return if
|
46
|
-
@errors << response_code_display if
|
45
|
+
return if xml_response_code.empty?
|
46
|
+
@errors << response_code_display if xml_response_code != '0'
|
47
47
|
end
|
48
48
|
|
49
49
|
def validate_http_response!
|
@@ -63,7 +63,11 @@ module Transbank
|
|
63
63
|
Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0, ["soap"], nil
|
64
64
|
)
|
65
65
|
|
66
|
-
pub_key.verify
|
66
|
+
Transbank::Webpay::Vault.pub_key.verify(
|
67
|
+
OpenSSL::Digest::SHA1.new,
|
68
|
+
signature_decode,
|
69
|
+
signed_node_canonicalize
|
70
|
+
)
|
67
71
|
end
|
68
72
|
|
69
73
|
def validate_digest
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
module Transbank
|
3
|
+
module Webpay
|
4
|
+
class Vault
|
5
|
+
class << self
|
6
|
+
def cert
|
7
|
+
@cert ||= OpenSSL::X509::Certificate.new open(Transbank::Webpay.configuration.cert_path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def private_key
|
11
|
+
@private_key ||= OpenSSL::PKey::RSA.new open(Transbank::Webpay.configuration.key_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def server_cert
|
15
|
+
@server_cert ||= begin
|
16
|
+
path = Transbank::Webpay.configuration.server_cert_path
|
17
|
+
OpenSSL::X509::Certificate.new File.read(path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def pub_key
|
22
|
+
server_cert.public_key
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transbank-webpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramón Soto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: signer
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/transbank/webpay/response.rb
|
143
143
|
- lib/transbank/webpay/struct.rb
|
144
144
|
- lib/transbank/webpay/validations.rb
|
145
|
+
- lib/transbank/webpay/vault.rb
|
145
146
|
- lib/transbank/webpay/version.rb
|
146
147
|
- transbank-webpay.gemspec
|
147
148
|
homepage: ''
|