pub fn attach_protocol(
request_xml: &str,
response_xml: &str,
) -> Result<String, FiscalError>Expand description
Attach the SEFAZ authorization protocol to a signed NFe XML,
producing the <nfeProc> wrapper required for storage and DANFE.
The function extracts the <NFe> from request_xml and the matching
<protNFe> from response_xml, validates the protocol status, and
joins them into a single <nfeProc> document.
If the response contains multiple <protNFe> nodes (batch response),
the function attempts to match by digest value and access key. When no
exact match is found it falls back to the first available <protNFe>.
ยงErrors
Returns FiscalError::XmlParsing if:
- Either input is empty
- The
<NFe>tag is missing fromrequest_xml - No
<protNFe>can be found inresponse_xml
Returns FiscalError::SefazRejection if the protocol status code
is not in VALID_PROTOCOL_STATUSES.