bravo 0.4.0 → 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +34 -0
- data/.travis.yml +9 -0
- data/.yardopts +13 -0
- data/CHANGELOG +7 -3
- data/Gemfile +6 -14
- data/Guardfile +5 -0
- data/LICENSE.txt +4 -2
- data/README.md +52 -0
- data/Rakefile +7 -47
- data/VERSION +1 -1
- data/bin/bravo +59 -0
- data/bravo.gemspec +22 -86
- data/lib/bravo/auth_data.rb +45 -10
- data/lib/bravo/bill.rb +74 -52
- data/lib/bravo/constants.rb +70 -10
- data/lib/bravo/core_ext/float.rb +6 -0
- data/lib/bravo/core_ext/hash.rb +12 -0
- data/lib/bravo/core_ext/string.rb +4 -1
- data/lib/bravo/reference.rb +37 -0
- data/lib/bravo/version.rb +3 -1
- data/lib/bravo/wsaa.rb +96 -0
- data/lib/bravo.rb +13 -8
- data/spec/bravo/auth_data_spec.rb +7 -6
- data/spec/bravo/bill_spec.rb +85 -67
- data/spec/bravo/reference_spec.rb +12 -0
- data/spec/bravo/wsaa_spec.rb +43 -0
- data/spec/spec_helper.rb +30 -15
- metadata +101 -156
- data/Gemfile.lock +0 -57
- data/README.textile +0 -53
- data/lib/bravo/authorizer.rb +0 -10
- data/spec/bravo/authorizer_spec.rb +0 -9
- data/wsaa-client.sh +0 -171
data/README.textile
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
h1. Bravo: la gema de facturación electrónica argentina
|
2
|
-
|
3
|
-
"-Bravo-":http://images.coveralia.com/audio/b/Bravo-Desierto_Sin_Amor-Frontal.jpg Bravo permite la obtención del "-C.A.E.-":http://www.muevamueva.com/masmusica/latina/cae/images/fotos.5.gif C.A.E. (Código de Autorización Electrónico) por medio del Web Service de Facturación Electrónica provisto por la AFIP.
|
4
|
-
|
5
|
-
h2. Instalación
|
6
|
-
|
7
|
-
<pre>
|
8
|
-
gem install bravo
|
9
|
-
</pre>
|
10
|
-
|
11
|
-
o
|
12
|
-
|
13
|
-
<pre>
|
14
|
-
gem 'bravo'
|
15
|
-
</pre>
|
16
|
-
|
17
|
-
en tu @Gemfile@
|
18
|
-
|
19
|
-
|
20
|
-
h2. Configuración
|
21
|
-
|
22
|
-
Los servicios de AFIP requieren la utilización del Web Service de Autorización y Autenticación ("wsaa readme":http://www.afip.gov.ar/ws/WSAA/README.txt)
|
23
|
-
|
24
|
-
Luego de cumplidos los pasos indicados en el readme, basta con configurar Bravo con la ruta a los archivos:
|
25
|
-
|
26
|
-
<pre>
|
27
|
-
Bravo.pkey = "spec/fixtures/pkey"
|
28
|
-
Bravo.cert = "spec/fixtures/cert.crt"
|
29
|
-
</pre>
|
30
|
-
|
31
|
-
y exportar la variable CUIT con el número de cuit usado para obtener los certificados:
|
32
|
-
|
33
|
-
@export CUIT=_numerodecuit_@
|
34
|
-
|
35
|
-
Bravo acepta más opciones, para más detalles ver el "spec_helper":https://github.com/vurbia/Bravo/blob/master/spec/spec_helper.rb
|
36
|
-
|
37
|
-
h2. Uso
|
38
|
-
|
39
|
-
El uso de la gema se centra en el metodo @authorize@. Este método invoca @FECAESolicitar@ y devuelve el resultado, que de ser exitoso incluye el CAE y su fecha de vencimento (ver "bill_spec":https://github.com/vurbia/Bravo/blob/master/spec/bravo/bill_spec.rb#L87)
|
40
|
-
|
41
|
-
|
42
|
-
h2. TODO list
|
43
|
-
|
44
|
-
* rdoc
|
45
|
-
* mensajes de error más completos
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
h2. Agradecimientos
|
50
|
-
|
51
|
-
* Emilio Tagua por sus consejos y contribuciones.
|
52
|
-
|
53
|
-
Copyright (c) 2010 Leandro Marcucci & Vurbia Technologies International Inc. See LICENSE.txt for further details.
|
data/lib/bravo/authorizer.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "Authorizer" do
|
4
|
-
it "should read credentials on initialize" do
|
5
|
-
authorizer = Bravo::Authorizer.new
|
6
|
-
authorizer.pkey.should == 'spec/fixtures/pkey'
|
7
|
-
authorizer.cert.should == 'spec/fixtures/cert.crt'
|
8
|
-
end
|
9
|
-
end
|
data/wsaa-client.sh
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
# FUNCTION: Bash script to get a TA from WSAA
|
3
|
-
# AUTHOR: Gerardo Fisanotti - AFIP/SDG-SI/DIITEC/DEARIN - 15-nov-2010
|
4
|
-
# Dependencies: curl, openssl >= 1.0, xmllint
|
5
|
-
#
|
6
|
-
# Modify following definitions according to your environment:
|
7
|
-
#
|
8
|
-
# URL=https://wsaahomo.afip.gov.ar/ws/services/LoginCms # WSAA URL
|
9
|
-
# KEY=spec/fixtures/pkey # file containing the private key in PEM format
|
10
|
-
# CRT=spec/fixtures/cert.crt # file containing the X.509 certificate in PEM format
|
11
|
-
TAFN="TA.xml" # file name of the output file
|
12
|
-
# modify next line if you need a proxy to get to the Internet or comment it out
|
13
|
-
# if you don't need a proxy
|
14
|
-
# export https_proxy="http://10.20.152.112:80"
|
15
|
-
#
|
16
|
-
# No further modifications should be needed below this line
|
17
|
-
#==============================================================================
|
18
|
-
function MakeTRA()
|
19
|
-
#
|
20
|
-
# Generate the XML containing the Access Ticket Request (TRA)
|
21
|
-
#
|
22
|
-
{
|
23
|
-
# FROM=$(date -j -f "%a %b %d %T %Z %Y" "`date -v0H -v0M -v0S`" "+%s")
|
24
|
-
# TO=$(date -j -f "%a %b %d %T %Z %Y" "`date -v23H -v59M -v59S`" "+%s")
|
25
|
-
FROM=$(date "+%Y-%m-%dT00:00:00-03:00")
|
26
|
-
TO=$(date "+%Y-%m-%dT23:59:59-03:00")
|
27
|
-
ID=$(date "+%s")
|
28
|
-
TRA=$(cat <<EOF
|
29
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
30
|
-
<loginTicketRequest version="1.0">
|
31
|
-
<header>
|
32
|
-
<uniqueId>$ID</uniqueId>
|
33
|
-
<generationTime>$FROM</generationTime>
|
34
|
-
<expirationTime>$TO</expirationTime>
|
35
|
-
</header>
|
36
|
-
<service>wsfe</service>
|
37
|
-
</loginTicketRequest>
|
38
|
-
EOF
|
39
|
-
)
|
40
|
-
}
|
41
|
-
#------------------------------------------------------------------------------
|
42
|
-
function MakeCMS()
|
43
|
-
#
|
44
|
-
# Generate de CMS container (TRA + sign + certificate)
|
45
|
-
#
|
46
|
-
{
|
47
|
-
CMS=$(
|
48
|
-
echo "$TRA" |
|
49
|
-
/usr/local/ssl/bin/openssl cms -sign -in /dev/stdin -signer $CRT -inkey $KEY -nodetach \
|
50
|
-
-outform der |
|
51
|
-
/usr/local/ssl/bin/openssl base64 -e
|
52
|
-
)
|
53
|
-
}
|
54
|
-
#------------------------------------------------------------------------------
|
55
|
-
function MakeSOAPrequest()
|
56
|
-
#
|
57
|
-
# Generate the SOAP request XML
|
58
|
-
#
|
59
|
-
{
|
60
|
-
REQUEST=$(cat <<EOF
|
61
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
62
|
-
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://wsaa.view.sua.dvadac.desein.afip.gov">
|
63
|
-
<SOAP-ENV:Body>
|
64
|
-
<ns1:loginCms>
|
65
|
-
<ns1:in0>
|
66
|
-
$CMS
|
67
|
-
</ns1:in0>
|
68
|
-
</ns1:loginCms>
|
69
|
-
</SOAP-ENV:Body>
|
70
|
-
</SOAP-ENV:Envelope>
|
71
|
-
EOF
|
72
|
-
)
|
73
|
-
}
|
74
|
-
#------------------------------------------------------------------------------
|
75
|
-
function CallWSAA()
|
76
|
-
#
|
77
|
-
# Invoke WSAA sending SOAP request XML to LoginCMS method
|
78
|
-
#
|
79
|
-
{
|
80
|
-
RESPONSE=$(
|
81
|
-
echo "$REQUEST" |
|
82
|
-
curl -k -H 'Content-Type: application/soap+xml; action=""' -d @- $URL
|
83
|
-
)
|
84
|
-
echo "$REQUEST"
|
85
|
-
}
|
86
|
-
#------------------------------------------------------------------------------
|
87
|
-
function ParseTA()
|
88
|
-
#
|
89
|
-
# Try to parse the results obtained from WSAA
|
90
|
-
#
|
91
|
-
{
|
92
|
-
TOKEN=$(
|
93
|
-
echo "$RESPONSE" |
|
94
|
-
grep token |
|
95
|
-
sed -e 's/<token>//' |
|
96
|
-
sed -e 's/<\/token>//' |
|
97
|
-
sed -e 's/ //g'
|
98
|
-
)
|
99
|
-
SIGN=$(
|
100
|
-
echo "$RESPONSE" |
|
101
|
-
grep sign |
|
102
|
-
sed -e 's/<sign>//' |
|
103
|
-
sed -e 's/<\/sign>//' |
|
104
|
-
sed -e 's/ //g'
|
105
|
-
)
|
106
|
-
# If we did not get TOKEN, then it was a SOAP Fault, show the error message
|
107
|
-
# and exit
|
108
|
-
#
|
109
|
-
if [ "$TOKEN" == "" ]
|
110
|
-
then
|
111
|
-
echo "ERROR: "
|
112
|
-
echo "$(echo "$RESPONSE" | xmllint --format - | grep faultstring)"
|
113
|
-
exit 1
|
114
|
-
fi
|
115
|
-
}
|
116
|
-
#------------------------------------------------------------------------------
|
117
|
-
function WriteTA()
|
118
|
-
#
|
119
|
-
# Write the token and sign to the output file
|
120
|
-
#
|
121
|
-
{
|
122
|
-
cat <<EOF > $TAFN
|
123
|
-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
124
|
-
<loginTicketResponse version="1">
|
125
|
-
<credentials>
|
126
|
-
<token>$TOKEN</token>
|
127
|
-
<sign>$SIGN</sign>
|
128
|
-
</credentials>
|
129
|
-
</loginTicketResponse>
|
130
|
-
EOF
|
131
|
-
}
|
132
|
-
|
133
|
-
function WriteYAML()
|
134
|
-
{
|
135
|
-
cat <<EOF > /tmp/bravo_$(date +"%d_%m_%Y").yml
|
136
|
-
token: '$TOKEN'
|
137
|
-
sign: '$SIGN'
|
138
|
-
EOF
|
139
|
-
}
|
140
|
-
#------------------------------------------------------------------------------
|
141
|
-
#
|
142
|
-
# MAIN program
|
143
|
-
#
|
144
|
-
# If we were invoked with a service name in arg #1, use it
|
145
|
-
#[ $# -eq 1 ] && SERVICE=$1
|
146
|
-
# otherwise, ask for it
|
147
|
-
#[ $# -eq 0 ] && read -p "Service name: " SERVICE
|
148
|
-
|
149
|
-
# Parse commandline arguments
|
150
|
-
while getopts 'k:u:c:' OPTION
|
151
|
-
do
|
152
|
-
case $OPTION in
|
153
|
-
c) CRT=$OPTARG
|
154
|
-
;;
|
155
|
-
k) KEY=$OPTARG
|
156
|
-
;;
|
157
|
-
u) URL=$OPTARG
|
158
|
-
;;
|
159
|
-
esac
|
160
|
-
done
|
161
|
-
shift $(($OPTIND - 1))
|
162
|
-
MakeTRA # Generate TRA
|
163
|
-
MakeCMS # Generate CMS (TRA + signature + certificate)
|
164
|
-
MakeSOAPrequest # Generate the SOAP request XML
|
165
|
-
CallWSAA # Invoke WSAA sending SOAP request
|
166
|
-
ParseTA # Parse the WSAA SOAP response, extract Token and Sign
|
167
|
-
# WriteTA # Write an abbreviated TA.xml with Token and Sign only
|
168
|
-
WriteYAML
|
169
|
-
echo "Access Ticket acquired, written to: $TAFN" # Inform success and exit
|
170
|
-
echo $REQUEST
|
171
|
-
echo $TRA
|