Class: Afipws::WSFE
- Inherits:
-
Object
- Object
- Afipws::WSFE
- Includes:
- TypeConversions
- Defined in:
- lib/afipws/wsfe.rb
Constant Summary collapse
- PRODUCTION_SSL_CIPHERS =
ARCA's production WSFE endpoint currently uses DH parameters rejected by OpenSSL's default security level. Keep this exception local to WSFE's production client; do not weaken TLS settings for other services.
'DEFAULT@SECLEVEL=1'.freeze
- WSDL =
{ development: 'https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL', production: 'https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL', test: Root + '/spec/fixtures/wsfe/wsfe.wsdl' }.freeze
Instance Attribute Summary collapse
-
#cuit ⇒ Object
readonly
Returns the value of attribute cuit.
-
#wsaa ⇒ Object
readonly
Returns the value of attribute wsaa.
Instance Method Summary collapse
- #auth ⇒ Object
- #autorizar_comprobantes(opciones) ⇒ Object
- #cant_max_registros_x_lote ⇒ Object
- #comprobante_to_request(comprobante) ⇒ Object
- #consultar_caea(fecha) ⇒ Object
- #consultar_comprobante(opciones) ⇒ Object
- #cotizacion(moneda_id) ⇒ Object
- #dummy ⇒ Object
- #fecha_inicio_quincena_siguiente ⇒ Object
- #informar_caea_sin_movimientos(caea, pto_vta) ⇒ Object
- #informar_comprobantes_caea(opciones) ⇒ Object
-
#initialize(options = {}) ⇒ WSFE
constructor
A new instance of WSFE.
- #periodo_para_consulta_caea(fecha) ⇒ Object
- #periodo_para_solicitud_caea ⇒ Object
- #puntos_venta ⇒ Object
- #solicitar_caea ⇒ Object
- #tipos_comprobantes ⇒ Object
- #tipos_concepto ⇒ Object
- #tipos_documentos ⇒ Object
- #tipos_iva ⇒ Object
- #tipos_monedas ⇒ Object
- #tipos_opcional ⇒ Object
- #tipos_tributos ⇒ Object
- #ultimo_comprobante_autorizado(opciones) ⇒ Object
Methods included from TypeConversions
Constructor Details
#initialize(options = {}) ⇒ WSFE
Returns a new instance of WSFE.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/afipws/wsfe.rb', line 18 def initialize = {} @cuit = [:cuit] @wsaa = WSAA.new .merge(service: 'wsfe') = Hash([:savon]).reverse_merge( wsdl: WSDL[@wsaa.env], convert_request_keys_to: :camelcase ) if @wsaa.env == :production [:ssl_ciphers] ||= RawSSLCipherString.new(PRODUCTION_SSL_CIPHERS) end @client = Client.new end |
Instance Attribute Details
#cuit ⇒ Object (readonly)
Returns the value of attribute cuit.
16 17 18 |
# File 'lib/afipws/wsfe.rb', line 16 def cuit @cuit end |
#wsaa ⇒ Object (readonly)
Returns the value of attribute wsaa.
16 17 18 |
# File 'lib/afipws/wsfe.rb', line 16 def wsaa @wsaa end |
Instance Method Details
#auth ⇒ Object
169 170 171 |
# File 'lib/afipws/wsfe.rb', line 169 def auth {auth: wsaa.auth.merge(cuit: cuit)} end |
#autorizar_comprobantes(opciones) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/afipws/wsfe.rb', line 79 def autorizar_comprobantes opciones comprobantes = opciones[:comprobantes] mensaje = { 'FeCAEReq' => { 'FeCabReq' => opciones.select_keys(:cbte_tipo, :pto_vta).merge(cant_reg: comprobantes.size), 'FeDetReq' => { 'FECAEDetRequest' => comprobantes.map { |comprobante| comprobante_to_request comprobante } } } } mensaje = r2x(mensaje, cbte_fch: :date, fch_serv_desde: :date, fch_serv_hasta: :date, fch_vto_pago: :date) r = request :fecae_solicitar, auth.merge(mensaje) r = Array.wrap(r[:fe_det_resp][:fecae_det_response]).map do |h| obs = Array.wrap(h[:observaciones] ? h[:observaciones][:obs] : nil) h.select_keys(:cae, :cae_fch_vto, :resultado).merge(cbte_nro: h[:cbte_desde], observaciones: obs) end x2r r, cae_fch_vto: :date, fch_serv_desde: :date, fch_serv_hasta: :date, fch_vto_pago: :date, cbte_nro: :integer, code: :integer end |
#cant_max_registros_x_lote ⇒ Object
151 152 153 |
# File 'lib/afipws/wsfe.rb', line 151 def cant_max_registros_x_lote request(:fe_comp_tot_x_request, auth)[:reg_x_req].to_i end |
#comprobante_to_request(comprobante) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/afipws/wsfe.rb', line 98 def comprobante_to_request comprobante nro = comprobante.delete :cbte_nro iva = comprobante.delete :imp_iva comprobante.delete :tributos if comprobante[:imp_trib] == 0 comprobante.merge cbte_desde: nro, cbte_hasta: nro, 'ImpIVA' => iva end |
#consultar_caea(fecha) ⇒ Object
115 116 117 |
# File 'lib/afipws/wsfe.rb', line 115 def consultar_caea fecha convertir_rta_caea request(:fecaea_consultar, auth.merge(periodo_para_consulta_caea(fecha))) end |
#consultar_comprobante(opciones) ⇒ Object
147 148 149 |
# File 'lib/afipws/wsfe.rb', line 147 def consultar_comprobante opciones request(:fe_comp_consultar, auth.merge(fe_comp_cons_req: opciones))[:result_get] end |
#cotizacion(moneda_id) ⇒ Object
75 76 77 |
# File 'lib/afipws/wsfe.rb', line 75 def cotizacion moneda_id request(:fe_param_get_cotizacion, auth.merge(mon_id: moneda_id))[:result_get][:mon_cotiz].to_f end |
#dummy ⇒ Object
31 32 33 |
# File 'lib/afipws/wsfe.rb', line 31 def dummy request :fe_dummy end |
#fecha_inicio_quincena_siguiente ⇒ Object
164 165 166 167 |
# File 'lib/afipws/wsfe.rb', line 164 def fecha_inicio_quincena_siguiente hoy = Date.today hoy.day <= 15 ? hoy.change(day: 16) : hoy.next_month.change(day: 1) end |
#informar_caea_sin_movimientos(caea, pto_vta) ⇒ Object
139 140 141 |
# File 'lib/afipws/wsfe.rb', line 139 def informar_caea_sin_movimientos caea, pto_vta request :fecaea_sin_movimiento_informar, auth.merge('CAEA' => caea, 'PtoVta' => pto_vta) end |
#informar_comprobantes_caea(opciones) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/afipws/wsfe.rb', line 119 def informar_comprobantes_caea opciones comprobantes = opciones[:comprobantes] mensaje = { 'FeCAEARegInfReq' => { 'FeCabReq' => opciones.select_keys(:cbte_tipo, :pto_vta).merge(cant_reg: comprobantes.size), 'FeDetReq' => { 'FECAEADetRequest' => comprobantes.map do |comprobante| comprobante_to_request comprobante.merge('CAEA' => comprobante.delete(:caea)) end } } } r = request :fecaea_reg_informativo, auth.merge(r2x(mensaje, cbte_fch: :date)) r = Array.wrap(r[:fe_det_resp][:fecaea_det_response]).map do |h| obs = Array.wrap(h[:observaciones] ? h[:observaciones][:obs] : nil) h.select_keys(:caea, :resultado).merge(cbte_nro: h[:cbte_desde], observaciones: obs) end x2r r, cbte_nro: :integer, code: :integer end |
#periodo_para_consulta_caea(fecha) ⇒ Object
159 160 161 162 |
# File 'lib/afipws/wsfe.rb', line 159 def periodo_para_consulta_caea fecha orden = fecha.day <= 15 ? 1 : 2 { orden: orden, periodo: fecha.strftime('%Y%m') } end |
#periodo_para_solicitud_caea ⇒ Object
155 156 157 |
# File 'lib/afipws/wsfe.rb', line 155 def periodo_para_solicitud_caea periodo_para_consulta_caea fecha_inicio_quincena_siguiente end |
#puntos_venta ⇒ Object
70 71 72 73 |
# File 'lib/afipws/wsfe.rb', line 70 def puntos_venta r = request :fe_param_get_ptos_venta, auth x2r get_array(r, :pto_venta), nro: :integer, fch_baja: :date, bloqueado: :boolean end |
#solicitar_caea ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/afipws/wsfe.rb', line 105 def solicitar_caea convertir_rta_caea request(:fecaea_solicitar, auth.merge(periodo_para_solicitud_caea)) rescue Afipws::ResponseError => e if e.code? 15008 consultar_caea fecha_inicio_quincena_siguiente else raise end end |
#tipos_comprobantes ⇒ Object
35 36 37 38 |
# File 'lib/afipws/wsfe.rb', line 35 def tipos_comprobantes r = request :fe_param_get_tipos_cbte, auth x2r get_array(r, :cbte_tipo), id: :integer, fch_desde: :date, fch_hasta: :date end |
#tipos_concepto ⇒ Object
50 51 52 53 |
# File 'lib/afipws/wsfe.rb', line 50 def tipos_concepto r = request :fe_param_get_tipos_concepto, auth x2r get_array(r, :concepto_tipo), id: :integer, fch_desde: :date, fch_hasta: :date end |
#tipos_documentos ⇒ Object
45 46 47 48 |
# File 'lib/afipws/wsfe.rb', line 45 def tipos_documentos r = request :fe_param_get_tipos_doc, auth x2r get_array(r, :doc_tipo), id: :integer, fch_desde: :date, fch_hasta: :date end |
#tipos_iva ⇒ Object
60 61 62 63 |
# File 'lib/afipws/wsfe.rb', line 60 def tipos_iva r = request :fe_param_get_tipos_iva, auth x2r get_array(r, :iva_tipo), id: :integer, fch_desde: :date, fch_hasta: :date end |
#tipos_monedas ⇒ Object
55 56 57 58 |
# File 'lib/afipws/wsfe.rb', line 55 def tipos_monedas r = request :fe_param_get_tipos_monedas, auth x2r get_array(r, :moneda), fch_desde: :date, fch_hasta: :date end |
#tipos_opcional ⇒ Object
40 41 42 43 |
# File 'lib/afipws/wsfe.rb', line 40 def tipos_opcional r = request :fe_param_get_tipos_opcional, auth x2r get_array(r, :tipos_opcional), id: :integer, fch_desde: :date, fch_hasta: :date end |
#tipos_tributos ⇒ Object
65 66 67 68 |
# File 'lib/afipws/wsfe.rb', line 65 def tipos_tributos r = request :fe_param_get_tipos_tributos, auth x2r get_array(r, :tributo_tipo), id: :integer, fch_desde: :date, fch_hasta: :date end |
#ultimo_comprobante_autorizado(opciones) ⇒ Object
143 144 145 |
# File 'lib/afipws/wsfe.rb', line 143 def ultimo_comprobante_autorizado opciones request(:fe_comp_ultimo_autorizado, auth.merge(opciones))[:cbte_nro].to_i end |