Skip to content

Commit d492565

Browse files
authored
Merge pull request #141 from ivannrnt/wsfev1-develop-update
WSFEv1: Agrego campos RG5616 a CaeSolicitarX() y a CAEARegInformativo()
2 parents fe78ecd + 096dbb7 commit d492565

File tree

4 files changed

+114
-87
lines changed

4 files changed

+114
-87
lines changed

ejemplos/wsfev1/wsfev1.bas

Lines changed: 71 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Attribute VB_Name = "Modulo1"
22
' Ejemplo de Uso de Interface COM con Web Service Factura Electrónica Mercado Interno AFIP
33
' Según RG2485 y RG2904 Artículo 4 Opción B (sin detalle, Version 1)
4-
' 2010 (C) Mariano Reingart <[email protected]>
4+
' 2025 (C) Mariano Reingart <[email protected]>
55
' Licencia: GPLv3
66

77
Sub Main()
@@ -11,110 +11,94 @@ Sub Main()
1111

1212
' Crear objeto interface Web Service Autenticación y Autorización
1313
Set WSAA = CreateObject("WSAA")
14-
Debug.Print WSAA.Version
15-
If WSAA.Version < "2.04" Then
16-
MsgBox "Debe instalar una versión más actualizada de PyAfipWs WSAA!"
17-
End
18-
End If
19-
20-
' deshabilito errores no manejados (version 2.04 o superior)
21-
WSAA.LanzarExcepciones = False
22-
23-
' Generar un Ticket de Requerimiento de Acceso (TRA) para WSFEv1
24-
ttl = 36000 ' tiempo de vida = 10hs hasta expiración
25-
tra = WSAA.CreateTRA("wsfe", ttl)
26-
ControlarExcepcion WSAA
27-
Debug.Print tra
2814

29-
' Especificar la ubicacion de los archivos certificado y clave privada
30-
Path = WSAA.InstallDir + "\" ' para ruta actual, usar CurDir()
31-
' Certificado: certificado es el firmado por la AFIP
32-
' ClavePrivada: la clave privada usada para crear el certificado
33-
Certificado = "reingart.crt" ' certificado de prueba
34-
ClavePrivada = "reingart.key" ' clave privada de prueba
15+
' inicializo las variables:
16+
token = ""
17+
sign = ""
3518

36-
' Generar el mensaje firmado (CMS)
37-
cms = WSAA.SignTRA(tra, Path + Certificado, Path + ClavePrivada)
38-
ControlarExcepcion WSAA
39-
Debug.Print cms
19+
' busco un ticket de acceso previamente almacenado:
20+
If Dir("ta.xml") <> "" Then
21+
' leo el xml almacenado del archivo
22+
Open "ta.xml" For Input As #1
23+
Line Input #1, ta_xml
24+
Close #1
25+
' analizo el ticket de acceso previo:
26+
ok = WSAA.AnalizarXml(ta_xml)
27+
If Not WSAA.Expirado() Then
28+
' puedo reusar el ticket de acceso:
29+
token = WSAA.ObtenerTagXml("token")
30+
sign = WSAA.ObtenerTagXml("sign")
31+
End If
32+
End If
4033

41-
' Conectarse con el webservice de autenticación:
42-
cache = ""
43-
proxy = "" '"usuario:clave@localhost:8000"
44-
wrapper = "" ' libreria http (httplib2, urllib2, pycurl)
45-
cacert = WSAA.InstallDir & "\conf\afip_ca_info.crt" ' certificado de la autoridad de certificante
46-
wsdl = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl"
47-
ok = WSAA.Conectar(cache, wsdl, proxy, wrapper, cacert) ' Homologación
48-
ControlarExcepcion WSAA
34+
' Si no reuso un ticket de acceso, solicito uno nuevo:
35+
If token = "" Or sign = "" Then
36+
' Generar un Ticket de Requerimiento de Acceso (TRA)
37+
tra = WSAA.CreateTRA("wsfe", 43200) ' 3600*12hs
38+
39+
Path = WSAA.InstallDir + "\"
40+
41+
' Especificar la ubicacion de los archivos certificado y clave privada
42+
cert = "reingart.crt" ' certificado de prueba
43+
clave = "reingart.key" ' clave privada de prueba
44+
' Generar el mensaje firmado (CMS)
45+
cms = WSAA.SignTRA(tra, Path + cert, Path + clave)
46+
If cms <> "" Then
47+
' Llamar al web service para autenticar (cambiar URL para produccion):
48+
wsdl = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl"
49+
ok = WSAA.Conectar("", wsdl)
50+
ta_xml = WSAA.LoginCMS(cms)
51+
If ta_xml <> "" Then
52+
' guardo el ticket de acceso en el archivo
53+
Open "ta.xml" For Output As #1
54+
Print #1, ta_xml
55+
Close #1
56+
End If
57+
token = WSAA.token
58+
sign = WSAA.sign
59+
End If
60+
' reviso que no haya errores:
61+
Debug.Print "Excepcion:", WSAA.Excepcion
62+
If WSAA.Excepcion <> "" Then
63+
Debug.Print WSAA.Traceback
64+
End If
4965

50-
' Llamar al web service para autenticar:
51-
ta = WSAA.LoginCMS(cms)
52-
ControlarExcepcion WSAA
53-
66+
End If
5467
' Imprimir el ticket de acceso, ToKen y Sign de autorización
5568
Debug.Print ta
56-
Debug.Print "Token:", WSAA.Token
57-
Debug.Print "Sign:", WSAA.Sign
69+
Debug.Print "Token:", token
70+
Debug.Print "Sign:", sign
5871

59-
' Una vez obtenido, se puede usar el mismo token y sign por 10 horas
72+
' Una vez obtenido, se puede usar el mismo token y sign por 24 horas
6073
' (este período se puede cambiar)
61-
' revisar WSAA.Expirado() y en dicho caso tramitar nuevo TA
6274

63-
' Crear objeto interface Web Service de Factura Electrónica de Mercado Interno
75+
' Crear objeto interface Web Service de Factura Electrónica Mercado Interno
6476
Set WSFEv1 = CreateObject("WSFEv1")
65-
Debug.Print WSFEv1.Version
66-
If WSAA.Version < "1.12" Then
67-
MsgBox "Debe instalar una versión mas actualizada de PyAfipWs WSFEv1!"
68-
End
69-
End If
70-
'Debug.Print WSFEv1.InstallDir
71-
7277
' Setear tocken y sing de autorización (pasos previos)
73-
WSFEv1.Token = WSAA.Token
74-
WSFEv1.Sign = WSAA.Sign
78+
WSFEv1.token = token
79+
WSFEv1.sign = sign
7580

7681
' CUIT del emisor (debe estar registrado en la AFIP)
7782
WSFEv1.Cuit = "20267565393"
7883

79-
' deshabilito errores no manejados
80-
WSFEv1.LanzarExcepciones = False
81-
8284
' Conectar al Servicio Web de Facturación
83-
proxy = "" ' "usuario:clave@localhost:8000"
84-
wsdl = "https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL"
85-
cache = "" 'Path
86-
wrapper = "" ' libreria http (httplib2, urllib2, pycurl)
87-
cacert = WSAA.InstallDir & "\conf\afip_ca_info.crt" ' certificado de la autoridad de certificante (solo pycurl)
88-
89-
ok = WSFEv1.Conectar(cache, wsdl, proxy, wrapper, cacert) ' homologación
90-
Debug.Print WSFEv1.Version
91-
ControlarExcepcion WSFEv1
92-
93-
' mostrar bitácora de depuración:
94-
Debug.Print WSFEv1.DebugLog
95-
85+
wsdl = "" ' "file:///C:/pyafipws/wsfev1_wsdl.xml"
86+
ok = WSFEv1.Conectar("", wsdl) ' produccion
9687
' Llamo a un servicio nulo, para obtener el estado del servidor (opcional)
9788
WSFEv1.Dummy
9889
ControlarExcepcion WSFEv1
9990
Debug.Print "appserver status", WSFEv1.AppServerStatus
10091
Debug.Print "dbserver status", WSFEv1.DbServerStatus
10192
Debug.Print "authserver status", WSFEv1.AuthServerStatus
102-
103-
' Establezco los valores de la factura a autorizar:
104-
tipo_cbte = 6
105-
punto_vta = 4004
106-
cbte_nro = WSFEv1.CompUltimoAutorizado(tipo_cbte, punto_vta)
107-
ControlarExcepcion WSFEv1
108-
For Each v In WSFEv1.errores
109-
Debug.Print v
110-
Next
111-
Debug.Print WSFEv1.errmsg
112-
Debug.Print WSFEv1.errcode
113-
If cbte_nro = "" Then
114-
cbte_nro = 0 ' no hay comprobantes emitidos
115-
Else
116-
cbte_nro = CLng(cbte_nro) ' convertir a entero largo
117-
End If
93+
94+
95+
96+
TipoCamioAfip = WSFEv1.ParamGetCotizacion("DOL", "20250403")
97+
Debug.Print WSFEv1.XmlRequest
98+
Debug.Print WSFEv1.XmlResponse
99+
MsgBox TipoCambioAfip
100+
101+
cbte_nro = CInt(WSFEv1.CompUltimoAutorizado(tipo_cbte, punto_vta)) + 1
118102
fecha = Format(Date, "yyyymmdd")
119103
concepto = 1
120104
tipo_doc = 80: nro_doc = "33693450239"
@@ -187,6 +171,10 @@ Sub Main()
187171

188172
' Habilito reprocesamiento automático (predeterminado):
189173
WSFEv1.Reprocesar = True
174+
175+
' Agrego RG 5616
176+
ok = WSFEv1.EstablecerCampoFactura("cancela_misma_moneda_ext", "N")
177+
ok = WSFEv1.EstablecerCampoFactura("condicion_iva_receptor_id", "5")
190178

191179
' Solicito CAE:
192180
CAE = WSFEv1.CAESolicitar()

ejemplos/wsfev1/wsfev1.prg

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ ta = WSAA.LoginCMS(cms)
3030

3131
ON ERROR DO errhand2;
3232

33-
*-- Crear objeto interface Web Service de Factura Electrónica
34-
WSFE = CREATEOBJECT("WSFEv1")
33+
*-- Crear objeto interface Web Service de Factura Electr�nica
34+
WSFE = CREATEOBJECT("WSFE")
3535

3636
? WSFE.Version
3737
? WSFE.InstallDir
@@ -108,6 +108,10 @@ base_im = "100.00"
108108
importe = "21.00"
109109
ok = WSFE.AgregarIva(id, base_imp, importe)
110110

111+
*-- Agrego RG 5616
112+
ok = WSFE.EstablecerCampoFactura("cancela_misma_moneda_ext", "N")
113+
ok = WSFE.EstablecerCampoFactura("condicion_iva_receptor_id", "5")
114+
111115
**-- Solicito CAE:
112116

113117
cae = WSFE.CAESolicitar()

ejemplos/wsfev1/wsfev1_rg5616.vbp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Type=Exe
2+
Module=Modulo1; wsfev1.bas
3+
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation
4+
Startup="Sub Main"
5+
Command32=""
6+
Name="Proyecto1"
7+
HelpContextID="0"
8+
CompatibleMode="0"
9+
MajorVer=1
10+
MinorVer=0
11+
RevisionVer=0
12+
AutoIncrementVer=0
13+
ServerSupportFiles=0
14+
VersionCompanyName="."
15+
CompilationType=0
16+
OptimizationType=0
17+
FavorPentiumPro(tm)=0
18+
CodeViewDebugInfo=0
19+
NoAliasing=0
20+
BoundsCheck=0
21+
OverflowCheck=0
22+
FlPointCheck=0
23+
FDIVCheck=0
24+
UnroundedFP=0
25+
StartMode=0
26+
Unattended=0
27+
ThreadPerObject=0
28+
MaxNumberOfThreads=1
29+
30+
[MS Transaction Server]
31+
AutoRefresh=1

wsfev1.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ def CAESolicitarX(self):
617617
'FchServHasta': f.get('fecha_serv_hasta'),
618618
'FchVtoPago': f.get('fecha_venc_pago'),
619619
'MonId': f['moneda_id'],
620-
'MonCotiz': f['moneda_ctz'],
620+
'MonCotiz': f['moneda_ctz'],
621+
'CanMisMonExt': f.get('cancela_misma_moneda_ext'),
622+
'CondicionIVAReceptorId': f.get('condicion_iva_receptor_id'),
621623
'PeriodoAsoc': {
622624
'FchDesde': f['periodo_cbtes_asoc'].get('fecha_desde'),
623625
'FchHasta': f['periodo_cbtes_asoc'].get('fecha_hasta'),
@@ -815,7 +817,9 @@ def CAEARegInformativo(self):
815817
'FchServHasta': f.get('fecha_serv_hasta'),
816818
'FchVtoPago': f.get('fecha_venc_pago'),
817819
'MonId': f['moneda_id'],
818-
'MonCotiz': f['moneda_ctz'],
820+
'MonCotiz': f['moneda_ctz'],
821+
'CanMisMonExt': f.get('cancela_misma_moneda_ext'),
822+
'CondicionIVAReceptorId': f.get('condicion_iva_receptor_id'),
819823
'PeriodoAsoc': {
820824
'FchDesde': f['periodo_cbtes_asoc'].get('fecha_desde'),
821825
'FchHasta': f['periodo_cbtes_asoc'].get('fecha_hasta'),

0 commit comments

Comments
 (0)