diff --git a/source/finkok/conf.py.example b/source/finkok/conf.py.example index 8394472..af7b74c 100644 --- a/source/finkok/conf.py.example +++ b/source/finkok/conf.py.example @@ -28,6 +28,10 @@ DEBUG = True AUTH = { 'user': '', 'pass': '', + 'RESELLER': { + 'user': '', + 'pass': '' + } } @@ -35,4 +39,8 @@ if DEBUG: AUTH = { 'user': 'pruebas-finkok@correolibre.net', 'pass': '5c9a88da105bff9a8c430cb713f6d35269f51674bdc5963c1501b7316366', + 'RESELLER': { + 'user': '', + 'pass': '' + } } diff --git a/source/finkok/finkok.py b/source/finkok/finkok.py index f4641c2..534283a 100644 --- a/source/finkok/finkok.py +++ b/source/finkok/finkok.py @@ -228,7 +228,6 @@ class PACFinkok(object): } return data - def cancel_xml(self, xml, auth={}): if not auth: auth = AUTH @@ -237,7 +236,7 @@ class PACFinkok(object): client = Client(self.URL[method], transport=self._transport, plugins=self._plugins) client.set_ns_prefix('can', 'http://facturacion.finkok.com/cancel') - xml = f'\n{xml}' + # ~ xml = f'\n{xml}' args = { 'xml': base64.b64encode(xml.encode()), 'username': auth['user'], @@ -250,3 +249,42 @@ class PACFinkok(object): return '' return result + + def client_balance(self, auth, rfc=''): + """Regresa los timbres restantes del cliente + Se pueden usar las credenciales de relleser o las credenciales del emisor + + Args: + rfc (str): El RFC del emisor + + Kwargs: + auth (dict): Credenciales del emisor + + Returns: + int Cantidad de timbres restantes + """ + + if not auth: + auth = AUTH['RESELLER'] + + method = 'client' + client = Client( + self.URL[method], transport=self._transport, plugins=self._plugins) + args = { + 'reseller_username': auth['user'], + 'reseller_password': auth['pass'], + 'taxpayer_id': rfc, + } + + result = self._get_result(client, 'get', args) + if self.error: + log.error(self.error) + return '' + + success = bool(self.result.users) + if not success: + self.error = self.result.message or 'RFC no existe' + return 0 + + return self.result.users.ResellerUser[0].credit + diff --git a/source/finkok/finkok1.py b/source/finkok/finkok1.py index f317fbe..0bd85a2 100644 --- a/source/finkok/finkok1.py +++ b/source/finkok/finkok1.py @@ -326,51 +326,6 @@ class PACFinkok(object): } return client - def client_get_timbres(self, rfc, auth={}): - """Regresa los timbres restantes del cliente - Se pueden usar las credenciales de relleser o las credenciales del emisor - - Args: - rfc (str): El RFC del emisor - - Kwargs: - auth (dict): Credenciales del emisor - - Returns: - int Cantidad de timbres restantes - """ - - if not auth: - auth = FINKOK['RESELLER'] - - method = 'client' - client = Client( - self.URL[method], transport=self._transport, plugins=self._plugins) - args = { - 'reseller_username': auth['USER'], - 'reseller_password': auth['PASS'], - 'taxpayer_id': rfc, - } - - try: - self.result = client.service.get(**args) - except Fault as e: - self.error = str(e) - return 0 - except TransportError as e: - self.error = str(e) - return 0 - except ConnectionError: - self.error = 'Verifica la conexión a internet' - return 0 - - success = bool(self.result.users) - if not success: - self.error = self.result.message or 'RFC no existe' - return 0 - - return self.result.users.ResellerUser[0].credit - def get_server_datetime(self): """Regresa la fecha y hora del servidor de timbrado del PAC """ diff --git a/source/finkok/finkok2.py b/source/finkok/finkok2.py index bd2e4b0..2dbbe61 100644 --- a/source/finkok/finkok2.py +++ b/source/finkok/finkok2.py @@ -300,7 +300,7 @@ class Finkok(object): self.error = str(e) return '' except TransportError as e: - self.error = str(e) + self.errorcancel = str(e) return '' return result @@ -340,33 +340,3 @@ class Finkok(object): return '' return result - - def client_get_timbres(self, rfc): - method = 'client' - client = Client( - URL[method], transport=self._transport, plugins=self._plugins) - args = { - 'reseller_username': self._auth['USER'], - 'reseller_password': self._auth['PASS'], - 'taxpayer_id': rfc, - } - - try: - self.result = client.service.get(**args) - except Fault as e: - self.error = str(e) - return 0 - except TransportError as e: - self.error = str(e) - return 0 - except ConnectionError: - self.error = 'Verifica la conexión a internet' - return 0 - - success = bool(self.result.users) - if not success: - self.error = self.result.message or 'RFC no existe' - return 0 - - return self.result.users.ResellerUser[0].credit - diff --git a/source/tests/tests_finkok.py b/source/tests/tests_finkok.py index 202e5e2..e8fd036 100644 --- a/source/tests/tests_finkok.py +++ b/source/tests/tests_finkok.py @@ -165,8 +165,10 @@ class TestStamp(unittest.TestCase): tree = ET.fromstring(result['acuse'].encode()) NS = {'s': 'http://schemas.xmlsoap.org/soap/envelope/'} - cancel_uuid = tree.xpath('string(//s:Body/*/*/*[1]/*[1])', namespaces=NS) - status = tree.xpath('string(//s:Body/*/*/*[1]/*[2])', namespaces=NS) + path = 'string(//s:Body/*/*/*[1]/*[1])' + cancel_uuid = tree.xpath(path, namespaces=NS) + path = 'string(//s:Body/*/*/*[1]/*[2])' + status = tree.xpath(path, namespaces=NS) self.assertEqual(cfdi_uuid, cancel_uuid) self.assertEqual(status, expected)