Get credit client
This commit is contained in:
parent
f56a44dc0a
commit
148101eb2c
|
@ -28,6 +28,10 @@ DEBUG = True
|
||||||
AUTH = {
|
AUTH = {
|
||||||
'user': '',
|
'user': '',
|
||||||
'pass': '',
|
'pass': '',
|
||||||
|
'RESELLER': {
|
||||||
|
'user': '',
|
||||||
|
'pass': ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,4 +39,8 @@ if DEBUG:
|
||||||
AUTH = {
|
AUTH = {
|
||||||
'user': 'pruebas-finkok@correolibre.net',
|
'user': 'pruebas-finkok@correolibre.net',
|
||||||
'pass': '5c9a88da105bff9a8c430cb713f6d35269f51674bdc5963c1501b7316366',
|
'pass': '5c9a88da105bff9a8c430cb713f6d35269f51674bdc5963c1501b7316366',
|
||||||
|
'RESELLER': {
|
||||||
|
'user': '',
|
||||||
|
'pass': ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,6 @@ class PACFinkok(object):
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def cancel_xml(self, xml, auth={}):
|
def cancel_xml(self, xml, auth={}):
|
||||||
if not auth:
|
if not auth:
|
||||||
auth = AUTH
|
auth = AUTH
|
||||||
|
@ -237,7 +236,7 @@ class PACFinkok(object):
|
||||||
client = Client(self.URL[method],
|
client = Client(self.URL[method],
|
||||||
transport=self._transport, plugins=self._plugins)
|
transport=self._transport, plugins=self._plugins)
|
||||||
client.set_ns_prefix('can', 'http://facturacion.finkok.com/cancel')
|
client.set_ns_prefix('can', 'http://facturacion.finkok.com/cancel')
|
||||||
xml = f'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n{xml}'
|
# ~ xml = f'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n{xml}'
|
||||||
args = {
|
args = {
|
||||||
'xml': base64.b64encode(xml.encode()),
|
'xml': base64.b64encode(xml.encode()),
|
||||||
'username': auth['user'],
|
'username': auth['user'],
|
||||||
|
@ -250,3 +249,42 @@ class PACFinkok(object):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return result
|
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
|
||||||
|
|
||||||
|
|
|
@ -326,51 +326,6 @@ class PACFinkok(object):
|
||||||
}
|
}
|
||||||
return client
|
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):
|
def get_server_datetime(self):
|
||||||
"""Regresa la fecha y hora del servidor de timbrado del PAC
|
"""Regresa la fecha y hora del servidor de timbrado del PAC
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -300,7 +300,7 @@ class Finkok(object):
|
||||||
self.error = str(e)
|
self.error = str(e)
|
||||||
return ''
|
return ''
|
||||||
except TransportError as e:
|
except TransportError as e:
|
||||||
self.error = str(e)
|
self.errorcancel = str(e)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -340,33 +340,3 @@ class Finkok(object):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return result
|
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
|
|
||||||
|
|
||||||
|
|
|
@ -165,8 +165,10 @@ class TestStamp(unittest.TestCase):
|
||||||
|
|
||||||
tree = ET.fromstring(result['acuse'].encode())
|
tree = ET.fromstring(result['acuse'].encode())
|
||||||
NS = {'s': 'http://schemas.xmlsoap.org/soap/envelope/'}
|
NS = {'s': 'http://schemas.xmlsoap.org/soap/envelope/'}
|
||||||
cancel_uuid = tree.xpath('string(//s:Body/*/*/*[1]/*[1])', namespaces=NS)
|
path = 'string(//s:Body/*/*/*[1]/*[1])'
|
||||||
status = tree.xpath('string(//s:Body/*/*/*[1]/*[2])', namespaces=NS)
|
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(cfdi_uuid, cancel_uuid)
|
||||||
self.assertEqual(status, expected)
|
self.assertEqual(status, expected)
|
||||||
|
|
Loading…
Reference in New Issue