Skip to content

Commit 8f58664

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 57db3f9 + 17537e7 commit 8f58664

2 files changed

Lines changed: 73 additions & 9 deletions

File tree

satcfdi/pacs/finkok.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,57 @@ def pending(self, rfc: str) -> list[str]:
480480
root = self._perform_request(url, envelope)
481481

482482
return [uuid.text for uuid in root.find(".//apps:uuids", self.namespaces)]
483+
484+
def get_receipt(self, taxpayer_id: str, uuid: str, receipt_type: Literal["C", "R"] = "C") -> CancelationAcknowledgment:
485+
"""Operation to get the cancellation or reception receipt of an invoice.
486+
487+
Args:
488+
taxpayer_id (str): The RFC of the issuer.
489+
uuid (str): The UUID of the invoice.
490+
receipt_type (Literal["C", "R"], optional): The type of receipt to get ("C" for cancelation, "R" for reception). Defaults to "C".
491+
492+
Returns:
493+
CancelationAcknowledgment: The acknowledgment of the receipt.
494+
- acuse: The receipt XML.
495+
496+
Raises:
497+
ResponseError: If there is an error in the response.
498+
"""
499+
namespace = self.namespaces["cancel"]
500+
operation_element = etree.Element(etree.QName(namespace, "get_receipt"))
501+
502+
rtaxpayer_id = etree.SubElement(
503+
operation_element, etree.QName(namespace, "taxpayer_id")
504+
)
505+
rtaxpayer_id.text = taxpayer_id
506+
507+
ruuid_elem = etree.SubElement(
508+
operation_element, etree.QName(namespace, "uuid")
509+
)
510+
ruuid_elem.text = uuid
511+
512+
rtype = etree.SubElement(
513+
operation_element, etree.QName(namespace, "type")
514+
)
515+
rtype.text = receipt_type
516+
517+
operation_element = self._add_auth(operation_element, namespace)
518+
envelope = self._build_envelope(operation_element)
519+
520+
url = self.get_service_url("cancel")
521+
root = self._perform_request(url, envelope)
522+
523+
error = root.find(".//apps:error", self.namespaces)
524+
if error is not None and error.text:
525+
raise ResponseError(error.text)
526+
527+
success = root.find(".//apps:success", self.namespaces)
528+
if success is not None and success.text == "true":
529+
receipt = root.find(".//apps:receipt", self.namespaces)
530+
if receipt is not None and receipt.text:
531+
return CancelationAcknowledgment(
532+
code=None,
533+
acuse=unescape(receipt.text).encode()
534+
)
535+
536+
raise ResponseError("Unknown error getting receipt")

tests/test_pac_finkok.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,22 @@ def test_finkok_accept_reject():
231231
assert isinstance(res, AcceptRejectAcknowledgment)
232232

233233

234-
def test_finkok_pending():
235-
with mock.patch("requests.post") as mk:
236-
mk.return_value.ok = True
237-
mk.return_value.content = b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<senv:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:tns="http://facturacion.finkok.com/cancel" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s1="http://facturacion.finkok.com/cancellation" xmlns:s0="apps.services.soap.core.views" xmlns:s12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:s12enc="http://www.w3.org/2003/05/soap-encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><senv:Body><tns:get_pendingResponse><tns:get_pendingResult><s0:uuids><tns:string>2D0E7634-886F-4119-B58F-2DCA228D510F</tns:string></s0:uuids></tns:get_pendingResult></tns:get_pendingResponse></senv:Body></senv:Envelope>'
238-
239-
res = finkok.pending("MAG041126GT8")
240-
assert mk.called
241-
assert mk.call_args.kwargs["url"] == url_maping["cancel"]
242-
assert "2D0E7634-886F-4119-B58F-2DCA228D510F" in res
234+
def test_finkok_pending():
235+
with mock.patch("requests.post") as mk:
236+
mk.return_value.ok = True
237+
mk.return_value.content = b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<senv:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:tns="http://facturacion.finkok.com/cancel" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s1="http://facturacion.finkok.com/cancellation" xmlns:s0="apps.services.soap.core.views" xmlns:s12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:s12enc="http://www.w3.org/2003/05/soap-encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><senv:Body><tns:get_pendingResponse><tns:get_pendingResult><s0:uuids><tns:string>2D0E7634-886F-4119-B58F-2DCA228D510F</tns:string></s0:uuids></tns:get_pendingResult></tns:get_pendingResponse></senv:Body></senv:Envelope>'
238+
239+
res = finkok.pending("MAG041126GT8")
240+
assert mk.called
241+
assert mk.call_args.kwargs["url"] == url_maping["cancel"]
242+
assert "2D0E7634-886F-4119-B58F-2DCA228D510F" in res
243+
244+
def test_finkok_get_receipt():
245+
with mock.patch("requests.post") as mk:
246+
mk.return_value.ok = True
247+
mk.return_value.content = b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<senv:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:tns="http://facturacion.finkok.com/cancel" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s1="http://facturacion.finkok.com/cancellation" xmlns:s0="apps.services.soap.core.views" xmlns:s12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:s12enc="http://www.w3.org/2003/05/soap-encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><senv:Body><tns:get_receiptResponse><tns:get_receiptResult><s0:uuid>E174F807-BEFA-4CF6-9B11-2A013B12F398</s0:uuid><s0:success>true</s0:success><s0:receipt><![CDATA[<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><CancelaCFDResponse xmlns="http://cancelacfd.sat.gob.mx"><CancelaCFDResult Fecha="2019-04-05T15:23:01.5995341" RfcEmisor="LAN7008173R5"><Folios><UUID>E174F807-BEFA-4CF6-9B11-2A013B12F398</UUID><EstatusUUID>201</EstatusUUID></Folios></CancelaCFDResult></CancelaCFDResponse></s:Body></s:Envelope>]]></s0:receipt><s0:taxpayer_id>LAN7008173R5</s0:taxpayer_id><s0:date>2019-04-05T15:23:01</s0:date></tns:get_receiptResult></tns:get_receiptResponse></senv:Body></senv:Envelope>'
248+
249+
res = finkok.get_receipt("LAN7008173R5", "E174F807-BEFA-4CF6-9B11-2A013B12F398", "C")
250+
assert mk.called
251+
assert mk.call_args.kwargs["url"] == url_maping["cancel"]
252+
assert b"CancelaCFDResponse" in res.acuse

0 commit comments

Comments
 (0)