Skip to content

Commit

Permalink
Interfaz COM:
Browse files Browse the repository at this point in the history
 * agrego soporte WSCTG (codigo de trazabilidad de granos / carta de porte)
 * agrego ejemplo WSCTG en visual basic
Ajustes soap ns en digdepfiel y wsctg
  • Loading branch information
reingart committed Jun 7, 2010
1 parent d05d34f commit 675c533
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;!@Install@!UTF-8!
Title="PyAfipWs 1.22"
Title="PyAfipWs 1.23b"
BeginPrompt="¿Desea instalar la Interface Para Servicios Web de AFIP?"
RunProgram="INSTALAR.BAT %%T"
Directory=".\\DIST\\"
Expand Down
104 changes: 104 additions & 0 deletions ejemplos/wsctg/wsctg.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Attribute VB_Name = "Module1"
' Ejemplo de Uso de Interface COM con Web Service Codigo de Trazabilidad de Granos
' 2010 (C) Mariano Reingart <reingart@gmail.com>

Sub Main()
Dim WSAA As Object, WSCTG As Object

On Error GoTo ManejoError

' Crear objeto interface Web Service Autenticación y Autorización
Set WSAA = CreateObject("WSAA")

' Generar un Ticket de Requerimiento de Acceso (TRA) para wsctg
tra = WSAA.CreateTRA("wsctg")
Debug.Print tra

' Especificar la ubicacion de los archivos certificado y clave privada
Path = CurDir() + "\"
' Certificado: certificado es el firmado por la AFIP
' ClavePrivada: la clave privada usada para crear el certificado
Certificado = "..\..\reingart.crt" ' certificado de prueba
ClavePrivada = "..\..\reingart.key" ' clave privada de prueba

' Generar el mensaje firmado (CMS)
cms = WSAA.SignTRA(tra, Path + Certificado, Path + ClavePrivada)
Debug.Print cms

' Llamar al web service para autenticar:
ta = WSAA.CallWSAA(cms, "https://wsaahomo.afip.gov.ar/ws/services/LoginCms") ' Homologación

' Imprimir el ticket de acceso, ToKen y Sign de autorización
Debug.Print ta
Debug.Print "Token:", WSAA.token
Debug.Print "Sign:", WSAA.sign

' Una vez obtenido, se puede usar el mismo token y sign por 24 horas
' (este período se puede cambiar)

' Crear objeto interface Web Service de Factura Electrónica de Exportación
Set WSCTG = CreateObject("WSCTG")
' Setear tocken y sing de autorización (pasos previos)
WSCTG.token = WSAA.token
WSCTG.sign = WSAA.sign

' CUIT (debe estar registrado en la AFIP)
WSCTG.cuit = "20267565393"

' Conectar al Servicio Web
ok = WSCTG.Conectar("https://fwshomo.afip.gov.ar/wsctg/services/CTGService") ' homologación

' Llamo a un servicio nulo, para obtener el estado del servidor (opcional)
WSCTG.Dummy
Debug.Print "appserver status", WSCTG.AppServerStatus
Debug.Print "dbserver status", WSCTG.DbServerStatus
Debug.Print "authserver status", WSCTG.AuthServerStatus

numero_carta_de_porte = "512345678"
codigo_especie = 23
cuit_remitente_comercial = "20267565393"
cuit_destino = "20267565393"
cuit_destinatario = "20267565393"
codigo_localidad_origen = 3058
codigo_localidad_destino = 3059
codigo_cosecha = "0910"
peso_neto_carga = 1000
cant_horas = 1
patente_vehiculo = "AAA000"
cuit_transportista = "2026756539"

numero_CTG = WSCTG.SolicitarCTG(numero_carta_de_porte, codigo_especie, _
cuit_remitente_comercial, cuit_destino, cuit_destinatario, codigo_localidad_origen, _
codigo_localidad_destino, codigo_cosecha, peso_neto_carga, cant_horas, _
patente_vehiculo, cuit_transportista)

Debug.Print WSCTG.XmlResponse

MsgBox numero_CTG, vbInformation, "SolicitarCTG: número CTG:"

numero_CTG = "43816783"

transaccion = WSCTG.ConfirmarCTG(numero_carta_de_porte, numero_CTG, cuit_transportista, peso_neto_carga)

Debug.Print WSCTG.XmlResponse

MsgBox WSCTG.Observaciones, vbInformation, "ConfirmarCTG: código transaccion:" & self.CodigoTransaccion

Debug.Assert transaccion = "10000001681"

Exit Sub
ManejoError:
' Si hubo error:
Debug.Print Err.Description ' descripción error afip
Debug.Print Err.Number - vbObjectError ' codigo error afip
Select Case MsgBox(Err.Description, vbCritical + vbRetryCancel, "Error:" & Err.Number - vbObjectError & " en " & Err.Source)
Case vbRetry
Debug.Assert False
Resume
Case vbCancel
Debug.Print Err.Description
End Select
Debug.Print WSCTG.XmlRequest
Debug.Assert False

End Sub
39 changes: 39 additions & 0 deletions ejemplos/wsctg/wsctg.vbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\system32\stdole2.tlb#OLE Automation
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; mscomctl.ocx
Module=Module1; wsctg.bas
Startup="Sub Main"
HelpFile=""
Title="wsctg"
Command32=""
Name="WSCTG"
HelpContextID="0"
Description="Ejemplo Web Service Depositario Fiel"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionComments="Requiere interfaz PyAfipWs"
VersionCompanyName="http://www.sistemasagiles.com.ar/"
VersionFileDescription="Ejemplo Web Service Depositario Fiel"
VersionLegalCopyright="2010 (C) Mariano Reingart reingart@gmail.com"
VersionProductName="PyAfipWs"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1
1 change: 1 addition & 0 deletions ejemplos/wsctg/wsctg.vbw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Module1 = 22, 22, 630, 257, Z
104 changes: 99 additions & 5 deletions pyafipws.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
__author__ = "Mariano Reingart (reingart@gmail.com)"
__copyright__ = "Copyright (C) 2008 Mariano Reingart"
__license__ = "GPL 3.0"
__version__ = "1.23a"
__version__ = "1.23b"

import sys
import wsaa, wsfe, wsbfe, wsfex, wdigdepfiel
import wsaa, wsfe, wsbfe, wsfex, wsctg, wdigdepfiel
from php import SimpleXMLElement, SoapFault, SoapClient, parse_proxy
import traceback
from win32com.server.exception import COMException
Expand Down Expand Up @@ -583,14 +583,107 @@ def GetLastID(self):


class WSCTG:
_public_methods_ = []
_public_methods_ = ['Conectar','Dummy','SolicitarCTG','ConfirmarCTG']
_public_attrs_ = ['Token', 'Sign', 'Cuit',
'AppServerStatus', 'DbServerStatus', 'AuthServerStatus',
'XmlRequest', 'XmlResponse', 'Version', ]
'XmlRequest', 'XmlResponse', 'Version', 'NumeroCTG',
'CodigoTransaccion', 'Observaciones']
_reg_progid_ = "WSCTG"
_reg_clsid_ = "{8F1CE1EA-6D7A-45E7-A5BB-B17E2EB1F965}"

def __init__(self):
self.Token = self.Sign = self.Cuit = None
self.AppServerStatus = self.DbServerStatus = self.AuthServerStatus = None
self.XmlRequest = ''
self.XmlResponse = ''
self.CodError = self.DescError = ''
self.client = None
self.Version = __version__
self.NumeroCTG = ''
self.CodigoTransaccion = self.Observaciones = ''


def Conectar(self, url="", proxy=""):
if HOMO or not url: url = wsctg.WSCTGURL
proxy_dict = parse_proxy(proxy)
try:
self.client = SoapClient(url,
action = wsctg.SOAP_ACTION,
namespace = wsctg.SOAP_NS,
trace = False, ns = 'ctg', soap_ns = 'soapenv',
exceptions = True, proxy = proxy_dict)
return True
except Exception, e:
##raise
raisePythonException(e)

def Dummy(self):
try:
results = wsctg.dummy(self.client)
self.AppServerStatus = str(results['appserver'])
self.DbServerStatus = str(results['dbserver'])
self.AuthServerStatus = str(results['authserver'])
except SoapFault,e:
raiseSoapError(e)
except COMException:
raise
except Exception, e:
raisePythonException(e)
finally:
# guardo datos de depuración
self.XmlRequest = self.client.xml_request
self.XmlResponse = self.client.xml_response

def SolicitarCTG(self, numero_carta_de_porte, codigo_especie,
cuit_remitente_comercial, cuit_destino, cuit_destinatario, codigo_localidad_origen,
codigo_localidad_destino, codigo_cosecha, peso_neto_carga, cant_horas,
patente_vehiculo, cuit_transportista):
try:
ret = wsctg.solicitar_ctg(self.client, self.Token, self.Sign, self.Cuit,
numeroCartaDePorte=numero_carta_de_porte, codigoEspecie=codigo_especie,
cuitRemitenteComercial=cuit_remitente_comercial,
cuitDestino=cuit_destino,
cuitDestinatario=cuit_destinatario,
codigoLocalidadOrigen=codigo_localidad_origen,
codigoLocalidadDestino=codigo_localidad_destino,
codigoCosecha=codigo_cosecha,
pesoNetoCarga=peso_neto_carga, cantHoras=cant_horas,
patenteVehiculo=patente_vehiculo, cuitTransportista=cuit_transportista)
self.NumeroCTG = ret
return self.NumeroCTG

except SoapFault,e:
raiseSoapError(e)
except COMException:
raise
except Exception, e:
raisePythonException(e)
finally:
# guardo datos de depuración
self.XmlRequest = self.client.xml_request
self.XmlResponse = self.client.xml_response

def ConfirmarCTG(self, numero_carta_de_porte, numero_CTG, cuit_transportista, peso_neto_carga):
try:
ret = wsctg.confirmar_ctg(self.client, self.Token, self.Sign, self.Cuit,
numeroCartaDePorte=numero_carta_de_porte,
numeroCTG=numero_CTG,
cuitTransportista=cuit_transportista,
pesoNetoCarga=peso_neto_carga)
self.CodigoTransaccion, self.Observaciones = ret
return self.CodigoTransaccion
except SoapFault,e:
raiseSoapError(e)
except COMException:
raise
except Exception, e:
raisePythonException(e)
finally:
# guardo datos de depuración
self.XmlRequest = self.client.xml_request
self.XmlResponse = self.client.xml_response


class wDigDepFiel:
_public_methods_ = ['Conectar', 'Dummy', 'AvisoDigit', 'AvisoRecepAcept', 'IniciarAviso', 'AgregarFamilia']
_public_attrs_ = ['Token', 'Sign', 'Cuit',
Expand All @@ -616,7 +709,7 @@ def Conectar(self, url="", proxy=""):
self.client = SoapClient(url,
action = wdigdepfiel.SOAP_ACTION,
namespace = wdigdepfiel.SOAP_NS,
trace = False, ns = 'ar',
trace = False, ns = 'ar', soap_ns='soap',
exceptions = True, proxy = proxy_dict)
return True
except Exception, e:
Expand Down Expand Up @@ -691,4 +784,5 @@ def AvisoDigit(self, tipo_agente, rol,
win32com.server.register.UseCommandLine(WSFE)
win32com.server.register.UseCommandLine(WSBFE)
win32com.server.register.UseCommandLine(WSFEX)
win32com.server.register.UseCommandLine(WSCTG)
win32com.server.register.UseCommandLine(wDigDepFiel)
2 changes: 1 addition & 1 deletion wdigdepfiel.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def aviso_digit(client, token, sign, cuit, tipo_agente, rol,
client = SoapClient(WSDDFURL,
action = SOAP_ACTION,
namespace = SOAP_NS, exceptions = True,
trace = True, ns = 'ar')
trace = True, ns = 'ar', soap_ns='soap')

if '--dummy' in sys.argv:
ret = dummy(client)
Expand Down
1 change: 1 addition & 0 deletions wsctg.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def confirmar_ctg(client, token, sign, cuit, **kwargs):
client = SoapClient(wsctg_url,
action = SOAP_ACTION,
namespace = SOAP_NS, exceptions = True,
soap_ns = 'soapenv',
trace = XML, ns = "ctg")

if '--dummy' in sys.argv:
Expand Down

0 comments on commit 675c533

Please sign in to comment.