Permalink
Browse files

Actualizando a savon 2.3

  • Loading branch information...
1 parent ce6be66 commit 28ca309b52a917c4da1aa2a92768ad26176706de @Shelvak Shelvak committed Jan 20, 2014
Showing with 137 additions and 115 deletions.
  1. +21 −15 Gemfile.lock
  2. +9 −8 bravo.gemspec
  3. +0 −6 lib/bravo.rb
  4. +107 −86 lib/bravo/bill.rb
View
36 Gemfile.lock
@@ -3,8 +3,9 @@ PATH
specs:
bravo (0.4.0)
activesupport (>= 3.2)
- savon (~> 0.9)
- tzinfo (> 0)
+ curb
+ savon (~> 2.3.0)
+ tzinfo
GEM
remote: https://rubygems.org/
@@ -20,18 +21,21 @@ GEM
nokogiri (>= 1.4.0)
atomic (1.1.14)
builder (3.2.2)
+ curb (0.8.4)
diff-lcs (1.1.3)
- gyoku (1.1.0)
+ gyoku (1.1.1)
builder (>= 2.1.2)
- httpi (1.1.1)
+ httpi (2.1.0)
rack
+ rubyntlm (~> 0.3.2)
i18n (0.6.9)
+ mime-types (1.25.1)
mini_portile (0.5.2)
minitest (4.7.5)
- multi_json (1.8.2)
- nokogiri (1.6.0)
+ multi_json (1.8.4)
+ nokogiri (1.6.1)
mini_portile (~> 0.5.0)
- nori (1.1.5)
+ nori (2.3.0)
rack (1.5.2)
rake (10.0.4)
rspec (2.12.0)
@@ -42,19 +46,21 @@ GEM
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
- savon (0.9.14)
- akami (~> 1.1)
+ rubyntlm (0.3.4)
+ savon (2.3.3)
+ akami (~> 1.2.0)
builder (>= 2.1.2)
- gyoku (>= 0.4.0)
- httpi (~> 1.0)
+ gyoku (~> 1.1.0)
+ httpi (~> 2.1.0)
nokogiri (>= 1.4.0)
- nori (~> 1.1)
- wasabi (~> 2.2)
+ nori (~> 2.3.0)
+ wasabi (~> 3.2.2)
thread_safe (0.1.3)
atomic
tzinfo (0.3.38)
- wasabi (2.5.1)
- httpi (~> 1.0)
+ wasabi (3.2.3)
+ httpi (~> 2.0)
+ mime-types (< 2.0.0)
nokogiri (>= 1.4.0)
PLATFORMS
View
17 bravo.gemspec
@@ -6,8 +6,8 @@ require 'bravo/version'
Gem::Specification.new do |gem|
gem.name = "bravo"
gem.version = Bravo::VERSION
- gem.authors = ["Leandro Marcucci"]
- gem.email = ["leanucci@gmail.com"]
+ gem.authors = [ 'Leandro Marcucci' ]
+ gem.email = 'leanucci@gmail.com'
gem.description = %q{Adaptador para el Web Service de Facturacion Electrónica de AFIP}
gem.summary = %q{Adaptador WSFE}
gem.homepage = "http://github.com/leanucci/bravo"
@@ -16,11 +16,12 @@ Gem::Specification.new do |gem|
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
- gem.require_paths = ["lib", "bin"]
+ gem.require_paths = ['lib', 'bin']
- gem.add_runtime_dependency(%q<savon>, ["~> 0.9"])
- gem.add_runtime_dependency(%q<activesupport>, [">= 3.2"])
- gem.add_runtime_dependency(%q<tzinfo>, ["> 0"])
- gem.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
- gem.add_development_dependency(%q<rake>, ["~> 10.0.3"])
+ gem.add_runtime_dependency('savon', [ '~> 2.3.0' ])
+ gem.add_runtime_dependency('activesupport', [ '>= 3.2' ])
+ gem.add_runtime_dependency('tzinfo')
+ gem.add_runtime_dependency('curb')
+ gem.add_development_dependency('rspec', [ '~> 2.12.0' ])
+ gem.add_development_dependency('rake', ['~> 10.0.3'])
end
View
6 lib/bravo.rb
@@ -27,10 +27,4 @@ def auth_hash
def log?
Bravo.verbose || ENV["VERBOSE"]
end
-
-end
-
-Savon.configure do |config|
- config.log = Bravo.log?
- config.log_level = :debug
end
View
193 lib/bravo/bill.rb
@@ -1,22 +1,32 @@
module Bravo
class Bill
+ require 'curb'
+
attr_reader :client, :base_imp, :total
attr_accessor :net, :doc_num, :iva_cond, :documento, :concepto, :moneda,
:due_date, :aliciva_id, :fch_serv_desde, :fch_serv_hasta,
:body, :response
def initialize(attrs = {})
Bravo::AuthData.fetch
- @client = Savon::Client.new do
- wsdl.document = Bravo.service_url
- http.auth.ssl.cert_key_file = Bravo.pkey
- http.auth.ssl.cert_file = Bravo.cert
- http.auth.ssl.verify_mode = :none
- http.read_timeout = 90
- http.open_timeout = 90
- http.headers = { "Accept-Encoding" => "gzip, deflate", "Connection" => "Keep-Alive" }
- end
- @body = {"Auth" => Bravo.auth_hash}
+
+ @client = Savon.client(
+ env_namespace: :soap,
+ wsdl: Bravo.service_url,
+ ssl_cert_key_file: Bravo.pkey,
+ ssl_cert_file: Bravo.cert,
+ ssl_verify_mode: :none,
+ read_timeout: 90,
+ open_timeout: 90,
+ headers: {
+ 'Accept-Encoding' => 'gzip, deflate', 'Connection' => 'Keep-Alive'
+ },
+ log: Bravo.log?,
+ log_level: :debug,
+ namespaces: {xmlns: 'http://ar.gov.afip.dif.FEV1/'}
+ )
+
+ @body = {'Auth' => Bravo.auth_hash}
@net = attrs[:net] || 0
self.documento = attrs[:documento] || Bravo.default_documento
self.moneda = attrs[:moneda] || Bravo.default_moneda
@@ -31,9 +41,8 @@ def cbte_type
def exchange_rate
return 1 if moneda == :peso
- response = client.request :fe_param_get_cotizacion do
- soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
- soap.body = body.merge!({"MonId" => Bravo::MONEDAS[moneda][:codigo]})
+ response = client.call :fe_param_get_cotizacion do
+ message body.merge!({"MonId" => Bravo::MONEDAS[moneda][:codigo]})
end
response.to_hash[:fe_param_get_cotizacion_response][:fe_param_get_cotizacion_result][:result_get][:mon_cotiz].to_f
end
@@ -49,9 +58,9 @@ def iva_sum
def authorize
return false unless setup_bill
- response = client.request :fecae_solicitar do |soap|
- soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
- soap.body = body
+
+ response = client.call(:fecae_solicitar) do |soap|
+ soap.message(body)
end
return false unless setup_response(response.to_hash)
@@ -61,52 +70,59 @@ def authorize
def setup_bill
today = Time.new.in_time_zone('Buenos Aires').strftime('%Y%m%d')
- fecaereq = {"FeCAEReq" => {
- "FeCabReq" => Bravo::Bill.header(cbte_type),
- "FeDetReq" => {
- "FECAEDetRequest" => {
- "Concepto" => Bravo::CONCEPTOS[concepto],
- "DocTipo" => Bravo::DOCUMENTOS[documento],
- "CbteFch" => today,
- "ImpTotConc" => 0.00,
- "MonId" => Bravo::MONEDAS[moneda][:codigo],
- "MonCotiz" => exchange_rate,
- "ImpOpEx" => 0.00,
- "ImpTrib" => 0.00,
- "Iva" => {
- "AlicIva" => {
- "Id" => "5",
- "BaseImp" => net,
- "Importe" => iva_sum}}}}}}
-
- detail = fecaereq["FeCAEReq"]["FeDetReq"]["FECAEDetRequest"]
-
- detail["DocNro"] = doc_num
- detail["ImpNeto"] = net.to_f
- detail["ImpIVA"] = iva_sum
- detail["ImpTotal"] = total
-
- if bill_number = next_bill_number
- detail["CbteDesde"] = detail["CbteHasta"] = bill_number
- else
- return false
- end
+ fecaereq = {
+ 'FeCAEReq' => {
+ 'FeCabReq' => Bravo::Bill.header(cbte_type),
+ 'FeDetReq' => {
+ 'FECAEDetRequest' => {
+ 'Concepto' => Bravo::CONCEPTOS[concepto],
+ 'DocTipo' => Bravo::DOCUMENTOS[documento],
+ 'CbteFch' => today,
+ 'ImpTotConc' => 0.00,
+ 'MonId' => Bravo::MONEDAS[moneda][:codigo],
+ 'MonCotiz' => exchange_rate,
+ 'ImpOpEx' => 0.00,
+ 'ImpTrib' => 0.00,
+ 'Iva' => {
+ 'AlicIva' => {
+ 'Id' => '5',
+ 'BaseImp' => net,
+ 'Importe' => iva_sum
+ }
+ }
+ }
+ }
+ }
+ }
- unless concepto == 0
- detail.merge!({"FchServDesde" => fch_serv_desde || today,
- "FchServHasta" => fch_serv_hasta || today,
- "FchVtoPago" => due_date || today})
- end
+ detail = fecaereq['FeCAEReq']['FeDetReq']['FECAEDetRequest']
- body.merge!(fecaereq)
- true
+ detail['DocNro'] = self.doc_num
+ detail['ImpNeto'] = self.net.to_f
+ detail['ImpIVA'] = self.iva_sum
+ detail['ImpTotal'] = self.total
+
+ if bill_number = next_bill_number
+ detail['CbteDesde'] = detail['CbteHasta'] = bill_number
+ else
+ return false
+ end
+
+ unless concepto == 0
+ detail.merge!({'FchServDesde' => fch_serv_desde || today,
+ 'FchServHasta' => fch_serv_hasta || today,
+ 'FchVtoPago' => due_date || today})
+ end
+
+
+ body.merge!(fecaereq)
+ true
end
def next_bill_number
begin
- resp = client.request :fe_comp_ultimo_autorizado do
- soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
- soap.body = {"Auth" => Bravo.auth_hash, "PtoVta" => Bravo.sale_point, "CbteTipo" => cbte_type}
+ resp = client.call :fe_comp_ultimo_autorizado do |soap|
+ soap.message(body.merge({"PtoVta" => Bravo.sale_point, "CbteTipo" => cbte_type}))
end
resp.to_hash[:fe_comp_ultimo_autorizado_response][:fe_comp_ultimo_autorizado_result][:cbte_nro].to_i + 1
@@ -119,29 +135,33 @@ def authorized?
!response.nil? && response.header_result == "A" && response.detail_result == "A"
end
- def query_bill(iva_cond, cbte_number)
- cbte_type = Bravo::BILL_TYPE[iva_cond] ||
- raise(NullOrInvalidAttribute.new, "Please choose a valid document type.")
-
- response = client.request :fe_comp_consultar do
- soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
- soap.body = {"Auth" => Bravo.auth_hash,
- "FeCompConsReq" => { "PtoVta" => Bravo.sale_point, "CbteTipo" => cbte_type, "CbteNro" => cbte_number}}
+ def query_bill(iva_condition, cbte_number)
+ cbte_type_selected = Bravo::BILL_TYPE[iva_condition] ||
+ raise(NullOrInvalidAttribute.new, 'Please choose a valid document type.')
+
+ response = client.call :fe_comp_consultar do |soap|
+ soap.message(body.merge({
+ 'FeCompConsReq' => {
+ 'PtoVta' => Bravo.sale_point,
+ 'CbteTipo' => cbte_type_selected,
+ 'CbteNro' => cbte_number
+ }
+ }))
end
result = response.to_hash[:fe_comp_consultar_response][:fe_comp_consultar_result][:result_get]
- response_hash = {:header_result => result[:resultado],
- :authorized_on => result[:fch_proceso],
- :detail_result => result[:resultado],
- :cae_due_date => result[:fch_vto],
- :cae => result[:cod_autorizacion],
- :iva_id => result[:iva][:alic_iva][:id],
- :iva_importe => result[:iva][:alic_iva][:importe],
- :moneda => result[:mon_id],
- :cotizacion => result[:mon_cotiz],
- :iva_base_imp => result[:iva][:alic_iva][:base_imp],
- :doc_num => result[:doc_nro]
+ response_hash = {header_result: result[:resultado],
+ authorized_on: result[:fch_proceso],
+ detail_result: result[:resultado],
+ cae_due_date: result[:fch_vto],
+ cae: result[:cod_autorizacion],
+ iva_id: result[:iva][:alic_iva][:id],
+ iva_importe: result[:iva][:alic_iva][:importe],
+ moneda: result[:mon_id],
+ cotizacion: result[:mon_cotiz],
+ iva_base_imp: result[:iva][:alic_iva][:base_imp],
+ doc_num: result[:doc_nro]
}
self.response = Response.new(response_hash)
@@ -177,17 +197,18 @@ def setup_response(response)
request_detail.merge!(iva)
- response_hash = {:header_result => response_header.delete(:resultado),
- :authorized_on => response_header.delete(:fch_proceso),
- :detail_result => response_detail.delete(:resultado),
- :cae_due_date => response_detail.delete(:cae_fch_vto),
- :cae => response_detail.delete(:cae),
- :iva_id => request_detail.delete(:id),
- :iva_importe => request_detail.delete(:importe),
- :moneda => request_detail.delete(:mon_id),
- :cotizacion => request_detail.delete(:mon_cotiz),
- :iva_base_imp => request_detail.delete(:base_imp),
- :doc_num => request_detail.delete(:doc_nro)
+ response_hash = {
+ header_result: response_header.delete(:resultado),
+ authorized_on: response_header.delete(:fch_proceso),
+ detail_result: response_detail.delete(:resultado),
+ cae_due_date: response_detail.delete(:cae_fch_vto),
+ cae: response_detail.delete(:cae),
+ iva_id: request_detail.delete(:id),
+ iva_importe: request_detail.delete(:importe),
+ moneda: request_detail.delete(:mon_id),
+ cotizacion: request_detail.delete(:mon_cotiz),
+ iva_base_imp: request_detail.delete(:base_imp),
+ doc_num: request_detail.delete(:doc_nro)
}.merge!(request_header).merge!(request_detail)
self.response = Response.new(response_hash)

0 comments on commit 28ca309

Please sign in to comment.