@@ -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" )
0 commit comments