#[non_exhaustive]pub struct Contingency {
pub contingency_type: Option<ContingencyType>,
pub reason: Option<String>,
pub activated_at: Option<String>,
pub timestamp: u64,
}Expand description
Contingency manager for NF-e emission.
Manages activation and deactivation of contingency mode, used when the primary SEFAZ authorizer is unavailable. Supports all contingency types defined in the NF-e specification: SVC-AN, SVC-RS, EPEC, FS-DA, FS-IA, and offline.
§JSON persistence
The state can be serialized to / deserialized from a compact JSON string
using to_json and load,
matching the PHP Contingency::__toString() format:
{"motive":"reason","timestamp":1480700623,"type":"SVCAN","tpEmis":6}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.contingency_type: Option<ContingencyType>The active contingency type, or None when in normal mode.
reason: Option<String>Justification reason for entering contingency (15-255 chars).
activated_at: Option<String>ISO-8601 timestamp when contingency was activated.
timestamp: u64Unix timestamp (seconds since epoch) of activation.
Implementations§
Source§impl Contingency
impl Contingency
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new contingency manager with no active contingency (normal mode).
Sourcepub fn activate(
&mut self,
contingency_type: ContingencyType,
reason: &str,
) -> Result<(), FiscalError>
pub fn activate( &mut self, contingency_type: ContingencyType, reason: &str, ) -> Result<(), FiscalError>
Activate contingency mode with the given type and justification reason.
The reason is trimmed and must be between 15 and 255 UTF-8 characters (inclusive). On success, the contingency is activated with the current UTC timestamp.
§Errors
Returns FiscalError::Contingency if the trimmed reason is shorter
than 15 characters or longer than 255 characters.
Sourcepub fn deactivate(&mut self)
pub fn deactivate(&mut self)
Deactivate contingency mode, resetting to normal emission.
Sourcepub fn load(json: &str) -> Result<Self, FiscalError>
pub fn load(json: &str) -> Result<Self, FiscalError>
Load contingency state from a JSON string.
Expected JSON format (matching PHP Contingency):
{"motive":"reason","timestamp":1480700623,"type":"SVCAN","tpEmis":6}Accepts all contingency type strings: SVCAN, SVC-AN, SVCRS,
SVC-RS, EPEC, FSDA, FS-DA, FSIA, FS-IA, OFFLINE,
and their lowercase equivalents.
§Errors
Returns FiscalError::Contingency if the JSON cannot be parsed or
contains an unrecognized contingency type.
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Serialize the contingency state to a JSON string.
Produces the same format as the PHP Contingency::__toString():
{"motive":"reason","timestamp":1480700623,"type":"SVCAN","tpEmis":6}When deactivated, produces:
{"motive":"","timestamp":0,"type":"","tpEmis":1}Sourcepub fn emission_type(&self) -> u8
pub fn emission_type(&self) -> u8
Get the emission type code for the current contingency state.
Returns 1 (normal) if no contingency is active, or the corresponding
tpEmis code: 2 (FS-IA), 4 (EPEC), 5 (FS-DA), 6 (SVC-AN),
7 (SVC-RS), 9 (offline).
Sourcepub fn emission_type_enum(&self) -> EmissionType
pub fn emission_type_enum(&self) -> EmissionType
Get the EmissionType enum for the current contingency state.
Sourcepub fn check_web_service_availability(
&self,
model: InvoiceModel,
) -> Result<(), FiscalError>
pub fn check_web_service_availability( &self, model: InvoiceModel, ) -> Result<(), FiscalError>
Check whether the current contingency mode has a dedicated web service.
Only SVC-AN and SVC-RS have their own SEFAZ web services. Other types
(EPEC, FS-DA, FS-IA, offline) do not have their own web services for
NF-e authorization and will return an error if used with sefazAutorizacao.
§Errors
Returns FiscalError::Contingency if:
- The document is model 65 (NFC-e) and an SVC contingency is active (NFC-e does not support SVC-AN/SVC-RS).
- The active contingency type does not have a dedicated web service (EPEC, FS-DA, FS-IA, offline).
Trait Implementations§
Source§impl Clone for Contingency
impl Clone for Contingency
Source§fn clone(&self) -> Contingency
fn clone(&self) -> Contingency
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more