Skip to main content

Client

Struct Client 

Source
pub struct Client<T: Read + Write, S: SequenceProvider> { /* private fields */ }
Expand description

Synchronous HDM client.

Generic over the transport (anything that’s Read + Write) and the sequence-number provider (anything implementing SequenceProvider). The split allows in-memory testing via std::io::Cursor-style mocks and pluggable persistence (InMemorySeq, FileSeq, custom).

Threading: the client is not internally synchronised. Wrap in a Mutex if you need to share it across threads. The HDM itself is single-session anyway, so concurrent calls don’t make sense at the protocol layer.

Timeouts: Client does not enforce timeouts on its transport. Configure set_read_timeout/set_write_timeout on a TcpStream before passing it to Self::new. The spec’s §4.2 step 7 mandates a 50-second cap on response wait time.

Implementations§

Source§

impl<T: Read + Write, S: SequenceProvider> Client<T, S>

Source

pub fn new(transport: T, password: impl Into<String>, seq: S) -> Self

Build a new client over transport, deriving the password key from password.

Source

pub const fn is_logged_in(&self) -> bool

Whether a session has been established via Self::login (and not invalidated).

Source

pub const fn forget_session(&mut self)

Drop the in-memory session key. Does not notify the HDM — call Self::logout for that.

Source

pub fn list_operators_and_departments( &mut self, ) -> Result<ListOpsAndDepsResponse, Error>

Op 1 (§4.5.1): list configured operators and departments. Does not require login.

§Errors

See Error.

Source

pub fn login( &mut self, cashier: u32, pin: impl Into<String>, ) -> Result<(), Error>

Op 2 (§4.5.2): operator login. On success the session key returned by the HDM is decoded and installed; subsequent operations use it transparently.

§Errors
  • Error::Server with kind = BadOperatorPassword / NoSuchOperator / InactiveOperator on login failure.
  • Error::Crypto (CryptoError::SessionKeyBase64 / InvalidKeyLength) if the HDM returns a key field that isn’t valid 24-byte Base64 (would indicate a device bug).
Source

pub fn logout(&mut self) -> Result<(), Error>

Op 3 (§4.5.3): operator logout. Drops the session both server-side and locally.

§Errors

See Error. Returns Error::NotLoggedIn if Self::login hasn’t been called.

Source

pub fn print_receipt( &mut self, request: PrintReceiptRequest, ) -> Result<ReceiptResponse, Error>

Op 4 (§4.5.4): print a fiscal receipt. The sequence number is assigned by the client.

§Errors

See Error. Common business errors: NoSuchDepartment, BadAtgCode, PaidLessThanTotal, BadEmarkFormat, PrinterOutOfPaper, HdmSyncRequired. Check ServerErrorKind::is_retryable and ServerErrorKind::requires_relogin on the returned error.

Source

pub fn print_last_receipt(&mut self) -> Result<EmptyResponse, Error>

Op 5 (§4.5.5): reprint a copy of the operator’s most recent receipt.

§Errors

See Error.

Source

pub fn get_returnable_receipt( &mut self, receipt_id: impl Into<String>, crn: impl Into<String>, ) -> Result<ReturnableReceiptResponse, Error>

Op 10 (§4.5.6): look up the contents of a receipt you intend to return.

Read-only — returns the receipt’s items, amounts and eMarks so you can build the actual return (Self::print_return_receipt, op 6). It registers nothing.

§Errors

See Error.

Op 7 (§4.6.3): configure the header/footer lines printed on every receipt.

§Errors

See Error.

Op 8 (§4.6.4): upload a header logo image (Base64-encoded BMP, colour depth ≤4 bits).

§Errors

See Error.

Source

pub fn fiscal_report( &mut self, request: FiscalReportRequest, ) -> Result<EmptyResponse, Error>

Op 9 (§4.6.2): print a fiscal report (X-report = interim, Z-report = end-of-day).

§Errors

See Error.

Source

pub fn print_return_receipt( &mut self, request: PrintReturnReceiptRequest, ) -> Result<ReturnReceiptResponse, Error>

Op 6 (§4.5.7): print a return/refund receipt — the operation that actually registers a return. Full, by-amount or per-item returns are driven via the request’s optional fields. The read-only lookup of the receipt being returned is op 10 (Self::get_returnable_receipt).

§Errors

See Error.

Source

pub fn cash_in_out( &mut self, request: CashInOutRequest, ) -> Result<EmptyResponse, Error>

Op 11 (§4.5.8): record a cash-drawer in/out adjustment.

§Errors

See Error.

Source

pub fn date_time(&mut self) -> Result<DateTimeResponse, Error>

Op 12 (§4.6): query the HDM’s current date and time.

§Errors

See Error.

Source

pub fn receipt_sample(&mut self) -> Result<EmptyResponse, Error>

Op 13 (§4.6.1): print a sample receipt for layout/operator verification.

§Errors

See Error.

Source

pub fn hdm_time_sync(&mut self) -> Result<EmptyResponse, Error>

Op 14 (§4.7): synchronise the HDM with the tax authority’s clock/state.

§Errors

See Error.

Source

pub fn payment_systems_list( &mut self, ) -> Result<PaymentSystemsListResponse, Error>

Op 15 (§4.8): list the payment systems configured on the HDM. Use this once at startup to discover the code-to-name mapping for PrintReceiptRequest::payment_system rather than hardcoding codes.

§Errors

See Error.

Source

pub fn single_emark( &mut self, e_mark: impl Into<String>, ) -> Result<EmptyResponse, Error>

Op 16 (§4.9): submit a single eMark traceability code.

§Errors

See Error. BadEmarkFormat for malformed codes (see §4.9 escaping rules).

Auto Trait Implementations§

§

impl<T, S> Freeze for Client<T, S>
where T: Freeze, S: Freeze,

§

impl<T, S> RefUnwindSafe for Client<T, S>

§

impl<T, S> Send for Client<T, S>
where T: Send,

§

impl<T, S> Sync for Client<T, S>
where T: Sync, S: Sync,

§

impl<T, S> Unpin for Client<T, S>
where T: Unpin, S: Unpin,

§

impl<T, S> UnsafeUnpin for Client<T, S>
where T: UnsafeUnpin, S: UnsafeUnpin,

§

impl<T, S> UnwindSafe for Client<T, S>
where T: UnwindSafe, S: UnwindSafe,

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