def check(r): try: if r['Codigo'] != 0: raise AdapterError(r['Descripcion']) return r['Xml'] except KeyError: raise AdapterError('unexpected format of PAC reply')
def stamp(self, xml, xid): """ Timbrado usando XML firmado por el cliente Args: xml (str): xml de cfdi firmado por cliente xid (str): mi identificador alternativo de cfdi """ def check(r): try: if r['Codigo'] != 0: raise AdapterError(r['Descripcion']) return r['Xml'] except KeyError: raise AdapterError('unexpected format of PAC reply') try: req, conn = self.__setup_req('ns0:TimbradoCFDIRequest') req.TipoPeticion = '1' # SIGNED BY CUSTOMER req.IdComprobante = xid req.Xml = xml self.logger.debug( "The following request for stamp will be sent\n{0}".format(req) ) return check(conn.service.timbrarCFDI(req)) except AdapterError: raise except (suds.WebFault, Exception) as e: raise AdapterError("Stamp experimenting problems: {}".format(e))
def __setup_req(self): try: connection = Client(self.config['EP']) self.logger.debug( "{0} adapter is up and ready to kick buttocks\n{1}".format( self.pac_name, connection)) return connection except (Exception) as e: raise AdapterError('can not connect with end point {}: {}'.format( self.config['EP'], e))
def cancel(self, xml, emisor): """ Cancelacion de XML firmado por el cliente Args: xml (str): xml de cfdi firmado por cliente """ try: conn = self.__setup_req() return self.__check( conn.service.cancelarCFDI({ 'User': self.config['LOGIN'], 'Pass': self.config['PASSWD'], 'TipoPeticion': '2', 'Emisor': emisor, # RFC 'Xml': xml }), 'Cancel') except AdapterError: raise except (Exception) as e: raise AdapterError("Cancel experimenting problems".format(e))
def stamp(self, xml, xid): """ Timbrado usando XML firmado por el cliente Args: xml (str): xml de cfdi firmado por cliente xid (str): mi identificador alternativo de cfdi """ try: conn = self.__setup_req() return self.__check( conn.service.timbrarCFDI({ 'User': self.config['LOGIN'], 'Pass': self.config['PASSWD'], 'TipoPeticion': '1', # SIGNED BY CUSTOMER 'IdComprobante': xid, 'Xml': xml }), 'Stamp') except AdapterError: raise except (Exception) as e: raise AdapterError("Stamp experimenting problems: {}".format(e))