Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ed05a9d
Refactored style issues.
leanucci Sep 17, 2014
a84fc2c
Do not test 1.9.3. Test 2.1.2.
leanucci Sep 17, 2014
f7782d6
Minor fixes to README.
leanucci Oct 20, 2014
cb88c57
Updated specs.
Oct 21, 2014
cb08856
Rubocop.
Oct 21, 2014
7b58df2
Do the usual call.
Oct 21, 2014
ee5cf27
Added missing ?WSDL to production url.
leanucci Dec 5, 2014
95c4076
Updated Thor.
leanucci Apr 18, 2015
ae24a44
Updated savon.
leanucci Apr 18, 2015
f77298c
Restore travis openssl config.
leanucci Apr 29, 2015
e1c9b7f
Added inspect method.
leanucci May 18, 2015
47d3707
Removed class name for response since it varies.
leanucci May 18, 2015
200d5e7
Removed guard.
leanucci Feb 20, 2015
89b331d
Updated gems.
leanucci Feb 20, 2015
fd309ce
Bravo auth filename refactored.
leanucci Feb 20, 2015
2d52e91
Bill cleanup.
leanucci Feb 20, 2015
ffacb4f
Cleaned up bill generation.
leanucci Feb 20, 2015
1c0d7f8
Run with progress format in travis
leanucci May 18, 2015
21f00e8
Test all branches. Added ruby 2.2.0.
leanucci May 18, 2015
373a34f
Switched xit to pending in wsaa spec.
leanucci May 18, 2015
3c9da68
Rubocop fixes
leanucci May 18, 2015
4e89487
Refactored AuthData
leanucci May 19, 2015
ec804f7
Rubocop refactor.
leanucci May 19, 2015
38e069e
Bundle with test.
leanucci May 19, 2015
28f760a
Debugging travis and ruby 2.0.0
leanucci May 23, 2015
07a6e98
Fixedh scan compatibility issue with ruby 2.0.0
leanucci May 23, 2015
8699792
Using Bigdecimal instead of Float for calculations
leanucci May 23, 2015
4ace56a
Clean cassettes and auth data after ruby version
leanucci May 23, 2015
f7c4516
Logger is poro now
leanucci May 23, 2015
50082c6
Ignored vcr cassettes
leanucci May 23, 2015
9a43e36
removed class << self block
leanucci May 23, 2015
8979769
Added Authorization class.
leanucci May 23, 2015
a8409a3
deleted Auth data class
leanucci Jun 7, 2015
1066c12
added multiple authorized cuits support
leanucci Jun 7, 2015
98e5168
Progress
leanucci Aug 19, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tmtags
log/
log/*.log
./fixtures/
./fixtures/vcr_cassettes/
*/**/vcr_cassettes/
*.gem
tmp/
bin/bravo-certs/
Expand Down
157 changes: 157 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
---
AllCops:
Exclude:
- 'bin/*'

Metrics/CyclomaticComplexity:
Severity: refactor
Max: 8

Metrics/LineLength:
Max: 110
Severity: refactor

Metrics/ClassLength:
Max: 150
Severity: refactor

Metrics/MethodLength:
Max: 15
Severity: refactor

Metrics/ParameterLists:
Max: 5
Severity: refactor

Metrics/PerceivedComplexity:
Max: 10
Severity: refactor

Lint/EndAlignment:
AlignWith: variable

Lint/UselessAssignment:
Severity: error

Lint/ShadowingOuterLocalVariable:
Severity: convention

Style/CaseEquality:
Enabled: false

Style/Documentation:
Enabled: false
Severity: refactor

Style/IfUnlessModifier:
MaxLineLength: 80

Style/GuardClause:
MinBodyLength: 3

Style/Lambda:
Enabled: false

Style/EmptyLineBetweenDefs:
AllowAdjacentOneLineDefs: true

Style/ClassAndModuleChildren:
Enabled: false

Style/AndOr:
EnforcedStyle: conditionals

# This one is usefull for class attr_*
Style/TrivialAccessors:
AllowDSLWriters: true

Style/AlignParameters:
EnforcedStyle: with_fixed_indentation

Style/AlignHash:
EnforcedHashRocketStyle: key
EnforcedLastArgumentHashStyle: always_ignore

Style/ModuleFunction:
Enabled: false

Style/RegexpLiteral:
# The maximum number of (escaped) slashes that a slash-delimited regexp is
# allowed to have. If there are more slashes, a %r regexp shall be used.
MaxSlashes: 0

Style/FormatString:
Enabled: false

Style/SingleLineBlockParams:
Enabled: false

Style/CaseIndentation:
IndentWhenRelativeTo: end

Style/PredicateName:
Severity: refactor

Style/IndentHash:
EnforcedStyle: consistent

Style/MultilineBlockChain:
Severity: refactor

Lint/AssignmentInCondition:
Enabled: false

Style/Alias:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/SpaceInsideBlockBraces:
SpaceBeforeBlockParameters: true

Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%i': '[]'
'%w': '[]'
'%W': '[]'
'%': '{}'

Style/CollectionMethods:
PreferredMethods:
reduce: inject
collect: map
collect!: 'map!'
detect: find
detect!: 'find!'
find_all: select
find_all!: 'select!'

Style/DoubleNegation:
Severity: refactor

Style/SignalException:
EnforcedStyle: only_raise

Style/DotPosition:
EnforcedStyle: trailing

Style/SingleLineMethods:
AllowIfMethodIsEmpty: true

# It doesnt handle cases when we want to align multiple methods call into a table like
Style/SingleSpaceBeforeFirstArg:
Enabled: false

# replaces $1 x Regexp.last_match[1]
Style/PerlBackrefs:
Enabled: false

# There are valid cases (eg. Date.parse(date) rescue nil)
Style/RescueModifier:
Enabled: false

Style/Blocks:
Severity: refactor
Exclude:
- '**/spec/**/*_spec.rb'
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
bundler_args: --without test
branches:
only:
- master
- 2.1.2
- 2.2.0
script:
- rm -rf spec/fixtures/vcr_cassettes/
- if [ -e /tmp/bravo* ]; then rm /tmp/bravo*; fi
- bundle exec rspec spec --format=progress
- bundle exec rubocop
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*Bravo 1.0.0 (june 01, 2015)*
* Refactored auth data to expire after 12 hours

*Bravo 1.0.0.rc1 (November 25, 2013)*
* Added full support for Savon logging options

Expand Down
9 changes: 2 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
source 'http://rubygems.org'

group :test do
gem 'guard-rspec', '~> 2.4.0'
gem 'rb-fsevent', '~> 0.9.1'
gem 'debugger', '~> 1.3.0'
end

gemspec
gem 'byebug', group: :test
gemspec
5 changes: 0 additions & 5 deletions Guardfile

This file was deleted.

79 changes: 45 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bravo
# Bravo
![Travis status](https://travis-ci.org/leanucci/bravo.png)
[![Gem Version](https://badge.fury.io/rb/bravo.png)](http://badge.fury.io/rb/bravo)
[![Code Climate](https://codeclimate.com/repos/5292a01e89af7e473304513a/badges/4a29fbaff3d74a23e634/gpa.png)](https://codeclimate.com/repos/5292a01e89af7e473304513a/feed)
Expand All @@ -7,26 +7,18 @@

## Requisitos

Para poder autorizar comprobantes mediante el WSFE, AFIP requiere de ciertos pasos detallados a continuación:

* Generar una clave privada para la aplicación.
* Generar un CSR (Certificate Signing Request) utilizando el número de CUIT que emitirá los comprobantes y la clave privada del paso anterior. Se deberá enviar a AFIP el CSR para obtener el Certificado X.509 que se utilizará en el proceso de autorización de comprobantes.
* Para el entorno de Testing, se debe enviar el X.509 por email a [email protected]_.
* Para el entorno de Producción, el trámite se hace a través del portal [AFIP](http://www.afip.gov.ar)
* El certificado X.509 y la clave privada son utilizados por Bravo para obtener el token y signature a incluir en el header de autenticacion en cada request que hagamaos a los servicios de AFIP.


Guía para obtener certificados WSAA [aquí](http://www.afip.gov.ar/ws/WSAA/cert-req-howto.txt)
### OpenSSL

Para cumplir con los requisitos de encriptación del [Web Service de Autenticación y Autorización](http://www.afip.gov.ar/ws/WSAA/README.txt) (WSAA), Bravo requiere [OpenSSL](http://openssl.org) en cualquier versión posterior a la 1.0.0a.
Para cumplir con los requisitos de encriptación del [Web Service de Autenticación y Autorización](http://www.afip.gov.ar/ws/WSAA/README.txt) (WSAA), Bravo requiere [OpenSSL](http://openssl.org) en cualquier versión igual o posterior a la 1.0.0a.

Como regla general, basta correr desde la línea de comandos ```openssl cms```

Si el comando ```cms``` no está disponible, se debe actualizar OpenSSL.

### Certificados

AFIP exige para acceder a sus Web Services, la utilización del WSAA. Este servicio se encarga de la autorización y autenticación de cada request hecho al web service.
AFIP exige estar identificado para acceder a sus Web Services, mediante la utilización del WSAA. Este servicio se encarga de la autorización y autenticación de cada request hecho al web service. Para esto, hay que generar un mensaje encriptado, que se utiliza para el login en el WSAA. Si este login es exitoso, se obtienen credenciales válidas por 12 horas.

Una vez instalada la version correcta de OpenSSL, podemos generar la clave privada y el CSR.

Expand All @@ -38,9 +30,22 @@ Una vez instalada la version correcta de OpenSSL, podemos generar la clave priva

Luego de haber obtenido el certificado X.509, podemos comenzar a utilizar Bravo en el entorno para el cual sirve el certificado.

### Configuración
### Autorización

Cada mensajeLa clase Authorizations es la encargada de manejar las credenciales con las que se autentican los mensajes
enviados a afip.

El primer paso, es crear una nueva instancia de Bravo::Authorization con el número de cuit y la ruta a los
archivos de certificado y clave privada:

```ruby
authorization = Bravo::Authorization.new
authorization.cuit = '2028774002'
authorization.pkey_path = 'path/al/pkey'
authorization.cert_path = 'path/al/cert'
```


Bravo no asume valores por defecto, por lo cual hay que configurar de forma explícita todos los parámetros:

* ```pkey``` ruta a la clave privada
* ```cert``` ruta al certificado X.509
Expand All @@ -53,20 +58,23 @@ Bravo no asume valores por defecto, por lo cual hay que configurar de forma expl

Ejemplo de configuración tomado del spec_helper de Bravo:

```ruby

require 'bravo'
require 'bravo'

Bravo.pkey = 'spec/fixtures/certs/pkey'
Bravo.cert = 'spec/fixtures/certs/cert.crt'
Bravo.cuit = '20287740027'
Bravo.sale_point = '0002'
Bravo.default_concepto = 'Productos y Servicios'
Bravo.default_documento = 'CUIT'
Bravo.default_moneda = :peso
Bravo.own_iva_cond = :responsable_inscripto
Bravo.verbose = 'true'
Bravo.openssl_bin = '/usr/local/Cellar/openssl/1.0.1e/bin/openssl'
Bravo::AuthData.environment = :test
Bravo.pkey = 'spec/fixtures/certs/pkey'
Bravo.cert = 'spec/fixtures/certs/cert.crt'
Bravo.cuit = '20287740027'
Bravo.sale_point = '0002'
Bravo.default_concepto = 'Productos y Servicios'
Bravo.default_documento = 'CUIT'
Bravo.default_moneda = :peso
Bravo.own_iva_cond = :responsable_inscripto
Bravo.verbose = 'true'
Bravo.openssl_bin = '/usr/local/Cellar/openssl/1.0.1e/bin/openssl'
Bravo::AuthData.environment = :test

```

### Emisión de comprobantes

Expand All @@ -88,18 +96,21 @@ Luego de configurar Bravo, autorizamos una factura:

Código de ejemplo para la configuración anterior:

```ruby

bill = Bravo::Bill.new

factura = Bravo::Bill.new
bill.net = 100.00 # el neto de la factura, total para Consumidor final
bill.aliciva_id = 2010 # define la alicuota de iva a utilizar, ver archivo constants.
bill.iva_cond = :consumidor_final # la condición ante el iva del comprador
bill.concepto = 'Servicios' # concepto de la factura
bill.invoice_type = :invoice # el tipo de comprobante a emitir, en este caso factura.

factura.net = 100.00 # el neto de la factura, total para Consumidor final
factura.aliciva_id = 2 # define la alicuota de iva a utilizar, ver archivo constants.
factura.iva_cond = :consumidor_final # la condición ante el iva del comprador
factura.concepto = 'Servicios' # concepto de la factura
factura.invoice_type = :invoice # el tipo de comprobante a emitir, en este caso factura.
bill.authorize

bill.authorize
bill.response.cae # contiene el cae para este comprobante.

bill.response.cae # contiene el cae para este comprobante.
```

## TODO list

Expand Down
2 changes: 1 addition & 1 deletion autotest/discover.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Autotest.add_discovery { "rspec2" } #added according to rspec2 book
Autotest.add_discovery { "rspec2" } # added according to rspec2 book
Loading