afipws 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- afipws (0.1.0)
4
+ afipws (0.1.1)
5
5
  activesupport
6
6
  builder
7
7
  httpclient
@@ -1,3 +1,3 @@
1
1
  module Afipws
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/afipws/wsaa.rb CHANGED
@@ -4,17 +4,18 @@ module Afipws
4
4
 
5
5
  WSDL = {
6
6
  :development => "https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl",
7
- :production => 'https://wsaa.afip.gov.ar/ws/services/LoginCms?wsdl',
8
- :test => Root + '/spec/fixtures/wsaa.wsdl'
7
+ :production => "https://wsaa.afip.gov.ar/ws/services/LoginCms?wsdl",
8
+ :test => Root + "/spec/fixtures/wsaa.wsdl"
9
9
  }
10
10
 
11
11
  def initialize options = {}
12
+ @env = options[:env] || :test
12
13
  @key = options[:key]
13
14
  @cert = options[:cert]
14
15
  @service = options[:service] || 'wsfe'
15
16
  @ttl = options[:ttl] || 2400
16
17
  @cuit = options[:cuit]
17
- @client = Client.new WSDL[options[:env] || :test]
18
+ @client = Client.new WSDL[@env.to_sym]
18
19
  end
19
20
 
20
21
  def generar_tra service, ttl
data/lib/afipws/wsfe.rb CHANGED
@@ -2,18 +2,19 @@ module Afipws
2
2
  class WSFE
3
3
  extend Forwardable
4
4
  include TypeConversions
5
- attr_reader :wsaa, :client
5
+ attr_reader :wsaa, :client, :env
6
6
  def_delegators :wsaa, :ta, :auth, :cuit
7
7
 
8
8
  WSDL = {
9
9
  :development => "https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL",
10
10
  :production => "https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL",
11
- :test => Root + '/spec/fixtures/wsfe.wsdl'
11
+ :test => Root + "/spec/fixtures/wsfe.wsdl"
12
12
  }
13
13
 
14
14
  def initialize options = {}
15
+ @env = options[:env] || :test
15
16
  @wsaa = options[:wsaa] || WSAA.new(options.merge(:service => 'wsfe'))
16
- @client = Client.new WSDL[options[:env] || :test]
17
+ @client = Client.new WSDL[@env.to_sym]
17
18
  end
18
19
 
19
20
  def dummy
@@ -77,6 +78,12 @@ module Afipws
77
78
 
78
79
  def solicitar_caea
79
80
  convertir_rta_caea @client.fecaea_solicitar auth.merge(periodo_para_solicitud_caea)
81
+ rescue Afipws::WSError => e
82
+ if e.errors.any? { |e| e[:code] == '15008' }
83
+ consultar_caea fecha_inicio_quincena_siguiente
84
+ else
85
+ raise
86
+ end
80
87
  end
81
88
 
82
89
  def consultar_caea fecha
@@ -116,11 +123,7 @@ module Afipws
116
123
  end
117
124
 
118
125
  def periodo_para_solicitud_caea
119
- if Date.today.day <= 15
120
- { :orden => 2, :periodo => Date.today.strftime('%Y%m') }
121
- else
122
- { :orden => 1, :periodo => Date.today.next_month.strftime('%Y%m') }
123
- end
126
+ periodo_para_consulta_caea fecha_inicio_quincena_siguiente
124
127
  end
125
128
 
126
129
  def periodo_para_consulta_caea fecha
@@ -128,6 +131,11 @@ module Afipws
128
131
  { :orden => orden, :periodo => fecha.strftime('%Y%m') }
129
132
  end
130
133
 
134
+ def fecha_inicio_quincena_siguiente
135
+ hoy = Date.today
136
+ hoy.day <= 15 ? hoy.change(:day => 16) : hoy.next_month.change(:day => 1)
137
+ end
138
+
131
139
  private
132
140
  def get_array response, array_element
133
141
  Array.wrap response[:result_get][array_element]
@@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
4
  describe Afipws::WSFE do
5
5
  let :ws do
6
6
  wsaa = Afipws::WSAA.new
7
- wsaa.stubs :login => { :token => 't', :sign => 's' }
7
+ wsaa.stubs :login => { :token => 't', :sign => 's', :expiration_time => 12.hours.from_now }
8
8
  Afipws::WSFE.new :cuit => '1', :wsaa => wsaa
9
9
  end
10
10
 
@@ -157,6 +157,18 @@ describe Afipws::WSFE do
157
157
  ws.periodo_para_solicitud_caea.should == { :periodo => '201102', :orden => 1 }
158
158
  end
159
159
  end
160
+
161
+ it "cuando el caea ya fue otorgado debería consultarlo y devolverlo" do
162
+ Date.stubs :today => Date.new(2011,1,27)
163
+ savon.expects('FECAEASolicitar').with(has_path '/Periodo' => '201102', '/Orden' => 1).returns(:caea_ya_otorgado)
164
+ savon.expects('FECAEAConsultar').with(has_path '/Periodo' => '201102', '/Orden' => 1).returns(:success)
165
+ ws.solicitar_caea.should have_entries :caea => '21043476341977', :fch_vig_desde => Date.new(2011,02,01)
166
+ end
167
+
168
+ it "cuando hay otro error debería burbujearlo" do
169
+ savon.expects('FECAEASolicitar').returns(:error_distinto)
170
+ expect { ws.solicitar_caea }.to raise_error Afipws::WSError, /15007/
171
+ end
160
172
  end
161
173
 
162
174
  it "informar_comprobantes_caea" do
@@ -183,14 +195,6 @@ describe Afipws::WSFE do
183
195
  savon.expects('FECAEAConsultar').with(has_path '/Periodo' => '201101', '/Orden' => 1).returns(:success)
184
196
  ws.consultar_caea(Date.new(2011,1,1)).should have_entries :caea => '21043476341977', :fch_tope_inf => Date.new(2011,03,17)
185
197
  end
186
-
187
- it "periodo_para_consulta_caea" do
188
- ws.periodo_para_consulta_caea(Date.new(2011,1,1)).should == { :periodo => '201101', :orden => 1 }
189
- ws.periodo_para_consulta_caea(Date.new(2011,1,15)).should == { :periodo => '201101', :orden => 1 }
190
- ws.periodo_para_consulta_caea(Date.new(2011,1,16)).should == { :periodo => '201101', :orden => 2 }
191
- ws.periodo_para_consulta_caea(Date.new(2011,1,31)).should == { :periodo => '201101', :orden => 2 }
192
- ws.periodo_para_consulta_caea(Date.new(2011,2,2)).should == { :periodo => '201102', :orden => 1 }
193
- end
194
198
  end
195
199
 
196
200
  it "ultimo_comprobante_autorizado" do
@@ -218,6 +222,22 @@ describe Afipws::WSFE do
218
222
  end
219
223
  end
220
224
 
225
+ context "entorno" do
226
+ it "debería usar las url para development cuando el env es development" do
227
+ Afipws::Client.expects(:new).with("https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl")
228
+ Afipws::Client.expects(:new).with("https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL")
229
+ wsfe = Afipws::WSFE.new :env => :development
230
+ wsfe.env.should == :development
231
+ end
232
+
233
+ it "debería usar las url para production cuando el env es production" do
234
+ Afipws::Client.expects(:new).with("https://wsaa.afip.gov.ar/ws/services/LoginCms?wsdl")
235
+ Afipws::Client.expects(:new).with("https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL")
236
+ wsfe = Afipws::WSFE.new :env => 'production'
237
+ wsfe.env.should == :production
238
+ end
239
+ end
240
+
221
241
  context "manejo de errores" do
222
242
  it "cuando hay un error" do
223
243
  savon.expects('FEParamGetTiposCbte').returns(:failure_1_error)
@@ -237,4 +257,30 @@ describe Afipws::WSFE do
237
257
  }
238
258
  end
239
259
  end
260
+
261
+ context "cálculo de fechas y períodos" do
262
+ it "periodo_para_consulta_caea" do
263
+ ws.periodo_para_consulta_caea(Date.new(2011,1,1)).should == { :periodo => '201101', :orden => 1 }
264
+ ws.periodo_para_consulta_caea(Date.new(2011,1,15)).should == { :periodo => '201101', :orden => 1 }
265
+ ws.periodo_para_consulta_caea(Date.new(2011,1,16)).should == { :periodo => '201101', :orden => 2 }
266
+ ws.periodo_para_consulta_caea(Date.new(2011,1,31)).should == { :periodo => '201101', :orden => 2 }
267
+ ws.periodo_para_consulta_caea(Date.new(2011,2,2)).should == { :periodo => '201102', :orden => 1 }
268
+ end
269
+
270
+ it "fecha_inicio_quincena_siguiente" do
271
+ fecha_inicio_quincena_siguiente(Date.new(2010,1,1)).should == Date.new(2010,1,16)
272
+ fecha_inicio_quincena_siguiente(Date.new(2010,1,10)).should == Date.new(2010,1,16)
273
+ fecha_inicio_quincena_siguiente(Date.new(2010,1,15)).should == Date.new(2010,1,16)
274
+
275
+ fecha_inicio_quincena_siguiente(Date.new(2010,1,16)).should == Date.new(2010,2,1)
276
+ fecha_inicio_quincena_siguiente(Date.new(2010,1,20)).should == Date.new(2010,2,1)
277
+ fecha_inicio_quincena_siguiente(Date.new(2010,1,31)).should == Date.new(2010,2,1)
278
+ fecha_inicio_quincena_siguiente(Date.new(2010,12,31)).should == Date.new(2011,1,1)
279
+ end
280
+
281
+ def fecha_inicio_quincena_siguiente fecha
282
+ Date.stubs(:today => fecha)
283
+ subject.fecha_inicio_quincena_siguiente
284
+ end
285
+ end
240
286
  end
@@ -0,0 +1,18 @@
1
+ <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <FECAEASolicitarResponse xmlns="http://ar.gov.afip.dif.FEV1/">
4
+ <FECAEASolicitarResult>
5
+ <ResultGet>
6
+ <Periodo>0</Periodo>
7
+ <Orden>0</Orden>
8
+ </ResultGet>
9
+ <Errors>
10
+ <Err>
11
+ <Code>15007</Code>
12
+ <Msg>Orden incorrecto.</Msg>
13
+ </Err>
14
+ </Errors>
15
+ </FECAEASolicitarResult>
16
+ </FECAEASolicitarResponse>
17
+ </soap:Body>
18
+ </soap:Envelope>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Emmanuel Nicolau
@@ -189,6 +189,7 @@ files:
189
189
  - spec/fixtures/fecaea_consultar/success.xml
190
190
  - spec/fixtures/fecaea_reg_informativo/informe_rtdo_parcial.xml
191
191
  - spec/fixtures/fecaea_solicitar/caea_ya_otorgado.xml
192
+ - spec/fixtures/fecaea_solicitar/error_distinto.xml
192
193
  - spec/fixtures/fecaea_solicitar/success.xml
193
194
  - spec/fixtures/login_cms/fault.xml
194
195
  - spec/fixtures/login_cms/success.xml
@@ -213,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
214
  requirements:
214
215
  - - ">="
215
216
  - !ruby/object:Gem::Version
216
- hash: -619404093067996403
217
+ hash: -4544236781708141124
217
218
  segments:
218
219
  - 0
219
220
  version: "0"
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  requirements:
223
224
  - - ">="
224
225
  - !ruby/object:Gem::Version
225
- hash: -619404093067996403
226
+ hash: -4544236781708141124
226
227
  segments:
227
228
  - 0
228
229
  version: "0"
@@ -261,6 +262,7 @@ test_files:
261
262
  - spec/fixtures/fecaea_consultar/success.xml
262
263
  - spec/fixtures/fecaea_reg_informativo/informe_rtdo_parcial.xml
263
264
  - spec/fixtures/fecaea_solicitar/caea_ya_otorgado.xml
265
+ - spec/fixtures/fecaea_solicitar/error_distinto.xml
264
266
  - spec/fixtures/fecaea_solicitar/success.xml
265
267
  - spec/fixtures/login_cms/fault.xml
266
268
  - spec/fixtures/login_cms/success.xml