Afip 1.4.7 → 1.4.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Afip
2
+ VERSION = "1.4.8"
3
+ end
data/lib/Afip/wsaa.rb ADDED
@@ -0,0 +1,94 @@
1
+ module Afip
2
+ # Authorization class. Handles interactions wiht the WSAA, to provide
3
+ # valid key and signature that will last for a day.
4
+ #
5
+ class Wsaa
6
+ # Main method for authentication and authorization.
7
+ # When successful, produces the yaml file with auth data.
8
+ #
9
+ def self.login(service = "wsfe")
10
+ tra = build_tra(service)
11
+ cms = build_cms(tra)
12
+ req = build_request(cms)
13
+ auth = call_wsaa(req)
14
+
15
+ write_yaml(auth)
16
+ end
17
+
18
+ protected
19
+ # Builds the xml for the 'Ticket de Requerimiento de Acceso'
20
+ # @return [String] containing the request body
21
+ #
22
+ def self.build_tra service
23
+ @now = (Time.now) - 120
24
+ @from = @now.strftime('%FT%T%:z')
25
+ @to = (@from.to_time.end_of_day).strftime('%FT%T%:z')
26
+ @id = @now.strftime('%s')
27
+ tra = <<-EOF
28
+ <?xml version="1.0" encoding="UTF-8"?>
29
+ <loginTicketRequest version="1.0">
30
+ <header>
31
+ <uniqueId>#{ @id }</uniqueId>
32
+ <generationTime>#{ @from }</generationTime>
33
+ <expirationTime>#{ @to }</expirationTime>
34
+ </header>
35
+ <service>#{service}</service>
36
+ </loginTicketRequest>
37
+ EOF
38
+ return tra
39
+ end
40
+
41
+ # Builds the CMS
42
+ # @return [String] cms
43
+ #
44
+ def self.build_cms(tra)
45
+ cms = `echo '#{ tra }' |
46
+ #{ Afip.openssl_bin } cms -sign -in /dev/stdin -signer #{ Afip.cert } -inkey #{ Afip.pkey } -nodetach \
47
+ -outform der |
48
+ #{ Afip.openssl_bin } base64 -e`
49
+ return cms
50
+ end
51
+
52
+ # Builds the CMS request to log in to the server
53
+ # @return [String] the cms body
54
+ #
55
+ def self.build_request(cms)
56
+ request = <<-XML
57
+ <?xml version="1.0" encoding="UTF-8"?>
58
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://wsaa.view.sua.dvadac.desein.afip.gov">
59
+ <SOAP-ENV:Body>
60
+ <ns1:loginCms>
61
+ <ns1:in0>
62
+ #{ cms }
63
+ </ns1:in0>
64
+ </ns1:loginCms>
65
+ </SOAP-ENV:Body>
66
+ </SOAP-ENV:Envelope>
67
+ XML
68
+ return request
69
+ end
70
+
71
+ # Calls the WSAA with the request built by build_request
72
+ # @return [Array] with the token and signature
73
+ #
74
+ def self.call_wsaa(req)
75
+ response = `echo '#{ req }' | curl -k -s -H 'Content-Type: application/soap+xml; action=""' -d @- #{ Afip::AuthData.wsaa_url }`
76
+ pp response
77
+ response = CGI::unescapeHTML(response)
78
+ token = response.scan(/\<token\>(.+)\<\/token\>/).first.first
79
+ sign = response.scan(/\<sign\>(.+)\<\/sign\>/).first.first
80
+ return [token, sign]
81
+ end
82
+
83
+ # Writes the token and signature to a YAML file in the /tmp directory
84
+ #
85
+ def self.write_yaml(certs)
86
+ yml = <<-YML
87
+ token: #{certs[0]}
88
+ sign: #{certs[1]}
89
+ YML
90
+ `echo '#{ yml }' > /tmp/#{Afip::AuthData.environment.to_s}_Afip_#{ Afip.cuit }_#{ Time.new.strftime('%Y_%m_%d') }.yml`
91
+ end
92
+
93
+ end
94
+ end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Afip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.7
4
+ version: 1.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Facundo A. Díaz Martínez
@@ -86,7 +86,30 @@ email:
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
- files: []
89
+ files:
90
+ - Afip-1.2.1.gem
91
+ - Afip-1.4.gem
92
+ - Afip.gemspec
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/Afip.rb
101
+ - lib/Afip/auth_data.rb
102
+ - lib/Afip/authorizer.rb
103
+ - lib/Afip/bill.rb
104
+ - lib/Afip/constants.rb
105
+ - lib/Afip/core_ext/float.rb
106
+ - lib/Afip/core_ext/hash.rb
107
+ - lib/Afip/core_ext/string.rb
108
+ - lib/Afip/ctg.rb
109
+ - lib/Afip/padron.rb
110
+ - lib/Afip/version.rb
111
+ - lib/Afip/wsaa.rb
112
+ - pkg/Afip-1.4.7.gem
90
113
  homepage: http://litecode.com.ar/
91
114
  licenses:
92
115
  - MIT