error en codigo de autenticacion
Publicado por atilio (1 intervención) el 23/07/2016 11:18:02
Hola ,tengo problemas con este codigo, me da este error : 'Crear el objeto WSAA (Web Service de Autenticaci n y Autorizaci n) AFIP
Set WSAA = CreateObject("WSAA")
El codigo completo es:
Gracias
Set WSAA = CreateObject("WSAA")
El codigo completo es:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
Sub cae
' Ejemplo de Uso de Interfaz PyAfipWs para Windows Script Host
' con Web Service Autenticaci n / Factura Electr nica AFIP
' 20134(C) Mariano Reingart <reingart@gmail.com>
' Licencia: GPLv3
' Requerimientos: scripts wsaa.py y wsfev1.py registrados
' Documentacion:
' http://www.sistemasagiles.com.ar/trac/wiki/PyAfipWs
' http://www.sistemasagiles.com.ar/trac/wiki/ManualPyAfipWs
'Msgbox "CUIT: " & CurrentView.Body.CUIT.Text
'Msgbox "E_Punt_Vent: " & CurrentView.Body.E_Punt_Vent.Text
'Msgbox "E_Concepto: " & CurrentView.Body.E_Concepto.Text
Msgbox "E_NRODOC_AB: " & CurrentView.Body.E_NRODOC_AB.Text
'Msgbox "E_cbt_hasta: " & CurrentView.Body.E_cbt_hasta.Text
'Msgbox "E_cbt_desde_: " & CurrentView.Body.E_cbt_desde_.Text
Msgbox "E_TOTAL_DOC: " & CurrentView.Body.E_TOTAL_DOC.Text
'Msgbox "E_ENETO: " & CurrentView.Body.E_ENETO.Text
'Msgbox "E_imp_tot_conc: " & CurrentView.Body.E_imp_tot_conc.Text
'Msgbox "E_ImpIva: " & CurrentView.Body.E_ImpIva.Text
'Msgbox "E_imp_trib: " & CurrentView.Body.E_imp_trib.Text
'Msgbox "E_imp_op_ex: " & CurrentView.Body.E_imp_op_ex.Text
'Msgbox "FECHA: " & CurrentView.Body.FECHA.Text
Msgbox "E_Venc: " & CurrentView.Body.E_Venc.Text
' Crear el objeto WSAA (Web Service de Autenticaci n y Autorizaci n) AFIP
Set WSAA = CreateObject("WSAA")
' Solicitar Ticket de Acceso
wsdl = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms" ' Homologaci n!
'wsdl = "https://wsaa.afip.gov.ar/ws/services/LoginCms" ' produccion!
scriptdir =WSAA.InstallDir
ok = WSAA.Autenticar("wsfe", scriptdir & "\reingart.crt", scriptdir & "\reingart.key", wsdl) 'en homo cambiar Key
'ok = WSAA.Autenticar("wsfe", "\rutacompleta al certif..crt", "\ruta de clave priv.key", wsdl) 'en produccion cambiar Key
Msgbox wsaa.XmlRequest
Msgbox wsaa.XmlResponse
' Crear el objeto WSFEv1 (Web Service de Factura Electr nica version 1) AFIP
Set WSFEv1 = CreateObject("WSFEv1")
' Establecer parametros de uso:
WSFEv1.Cuit = "20267565393" 'homologacion
'WSFEv1.Cuit = "20130871616" 'produccion
WSFEv1.Token = WSAA.Token
WSFEv1.Sign = WSAA.Sign
' Conectar al websrvice
wsdl = "https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL" 'homologacion
'wsdl = "https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL" 'produccion
WSFEv1.Conectar "", wsdl
' Consultar ltimo comprobante autorizado en AFIP
tipo_cbte = 1 'aqui puede ir el campo tipo de comprobante,fact.A1,ndA2,ncA3
',fact.B6 ,ndB7 ,ncB8 ,recA4 ,recB9
punto_vta = 4003
ult = WSFEv1.CompUltimoAutorizado(tipo_cbte, punto_vta)
Msgbox WSFEv1.CompUltimoAutorizado(tipo_cbte, punto_vta)
Msgbox wsfev1.XmlRequest
Msgbox wsfev1.XmlResponse
' Calculo el pr ximo n mero de comprobante:
If ult = "" Then
cbte_nro = 0 ' no hay comprobantes emitidos
Else
cbte_nro = Clng(ult) ' convertir a entero largo
cbte_nro = cbte_nro + 1
End If
If cbte_nro <> Val(CurrentView.Body.E_cbt_desde_.Text) Then
Msgbox "Proximo Nº factura " & cbte_nro & ", no coincide con el form: " & CurrentView.Body.E_cbt_desde_.Text
End If
' Formateo fecha actual en formato yyymmdd:
d = Date ' fecha actual
fecha = Year(d) & Right("0" & Month(d), 2) & Right("0" & Day(d),2)
' Establezco los valores de la factura a autorizar:
concepto = 1 '' E_Concepto 'ventas.-1 productos 2 servicios 3 ambos
tipo_doc = 80 'TIPO 'ventas.80 cambiar por 96 si es DNI o 99 si es Consumidor Final
nro_doc = CurrentView.Body.CUIT.Text 'ventas."33693450239" para reemplazar con el varlor del formualiro: CurrentView.Body.CUIT.Text
cbt_desde = CurrentView.Body.E_cbt_desde_.Text '-ventas.-cbte_nro
cbt_hasta = CurrentView.Body.E_cbt_hasta.Text 'ventas.-cbte_nro
imp_tot_conc = E_imp_tot_conc 'ventas."2.00"
imp_neto = Round( Ccur(CurrentView.Body.E_ENETO.Text),2) '"100.00"
imp_trib = 0 ' E_imp_trib'ventas."1.00"
imp_op_ex = E_imp_op_ex'ventas."0.00"
fecha_cbte = FECHA'ventas.fecha
fecha_venc_pago = E_Venc 'ventas."
imp_iva = Round(Ccur(CurrentView.Body.E_ImpIva.Text) ,2)'"21.00"
imp_total = Round(Ccur(CurrentView.Body.E_TOTAL_DOC.Text),2) '"124.00"
' Fechas del per odo del servicio facturado (solo si concepto > 1)
fecha_serv_desde = ""
fecha_serv_hasta = ""
moneda_id = "PES"
moneda_ctz = "1.000"
ok = WSFEv1.CrearFactura(concepto, tipo_doc, nro_doc, tipo_cbte, punto_vta, _
cbt_desde, cbt_hasta, imp_total, imp_tot_conc, imp_neto, _
imp_iva, imp_trib, imp_op_ex, fecha_cbte, fecha_venc_pago, _
fecha_serv_desde, fecha_serv_hasta, _
moneda_id, moneda_ctz)
' Agrego los comprobantes asociados:
If False Then ' solo nc/nd
tipo = 19
pto_vta = 2
nro = 1234
ok = WSFEv1.AgregarCmpAsoc(tipo, pto_vta, nro)
End If
' Agrego impuestos varios
''id = 99
''desc = "Impuesto Municipal Matanza'"
''base_imp = "100.00"
''alic = "1.00"
''importe = "1.00"
''ok = WSFEv1.AgregarTributo(id, desc, base_imp, alic, importe)
' Agrego tasas de IVA
'iva_id = 5 ' 21%
'base_imp = Round(Ccur(CurrentView.Body.E_ENETO.Text), 2) '"100.00"
'importe = Round( Ccur(CurrentView.Body.E_ImpIva.Text),2) '"21.00"
'ok = WSFEv1.AgregarIva(iva_id, base_imp, importe)
' Agrego tasas de IVA (solo si hay impuesto liquidado al 21%)
importe = Round( Ccur(CurrentView.Body.E_SUMA21.Text),2)
If importe > 0 Then
iva_id = 5 ' 21%
base_imp = Round(importe*100/21.00, 2)
ok = WSFEv1.AgregarIva(iva_id, base_imp, importe)
End If
' Agrego tasas de IVA (solo si hay impuesto liquidado al 10.5%)
importe = Round( Ccur(CurrentView.Body.E_SUMA105.Text),2)
If importe > 0 Then
iva_id = 4 ' 10,5%
base_imp = Round(importe*100/10.50, 2)
ok = WSFEv1.AgregarIva(iva_id, base_imp, importe)
End If
'Agrego tasas de IVA
'iva_id = 5 ' 21%
'base_imp = Round(Ccur(CurrentView.Body.E_ENETO.Text), 2)'"100.00"
'importe = Round( Ccur(CurrentView.Body.E_SUMA21.Text),2)'"21.00"
'ok = WSFEv1.AgregarIva(id, base_imp, importe)
' Agrego tasas de IVA
'iva_id = 4 ' 10,5%
'base_imp = Round(Ccur(CurrentView.Body.E_ENETO.Text), 2)'"100.00"
'importe = Round( Ccur(CurrentView.Body.E_SUMA105.Text),2)'"21.00"
'ok = WSFEv1.AgregarIva(id, base_imp, importe)
' Habilito reprocesamiento autom tico (predeterminado):
WSFEv1.Reprocesar = True
' Solicito CA
WSFEv1.LanzarExcepciones = False
WSFEv1.CAESolicitar
If WSFEv1.Excepcion <> "" Then
Msgbox WSFEv1.Traceback, vbInformation + vbOKOnly, WSFEv1.Excepcion
End If
If WSFEv1.ErrMsg <> "" Then
Msgbox WSFEv1.ErrMsg, vbInformation + vbOKOnly, "Errores AFIP"
End If
' Imprimo pedido y respuesta XML para depuraci n (errores de formato)
Msgbox wsfev1.XmlRequest
Msgbox wsfev1.XmlResponse
CurrentView.Body.CAE_N_.Text = wsfev1.CAE
CurrentView.Body.CAEFECHADV.Text = wsfev1.Vencimiento
'CurrentView.Body.COMODIN.Text = WSFEv1.Code
Msgbox "Resultado:" & WSFEv1.Resultado & " CAE: " & wsfev1.CAE & " Venc: " & WSFEv1.Vencimiento & " Obs: " & WSFEv1.obs & " Reproceso: " & WSFEv1.Reproceso, vbInformation + vbOKOnly
End Sub
Gracias
Valora esta pregunta


0