Skip to main content

Contingency

Struct Contingency 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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-256 chars).

§activated_at: Option<String>

ISO-8601 timestamp when contingency was activated.

§timestamp: u64

Unix timestamp (seconds since epoch) of activation.

Implementations§

Source§

impl Contingency

Source

pub fn new() -> Self

Create a new contingency manager with no active contingency (normal mode).

Source

pub fn is_active(&self) -> bool

Returns true when a contingency mode is currently active.

Source

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 256 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 256 characters.

Source

pub fn deactivate(&mut self)

Deactivate contingency mode, resetting to normal emission.

Source

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.

Source

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}
Source

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).

Source

pub fn emission_type_enum(&self) -> EmissionType

Get the EmissionType enum for the current contingency state.

Source

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

Source§

fn clone(&self) -> Contingency

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Contingency

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Contingency

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Contingency

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.